Audacity  3.0.3
Mix.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Mix.h
6 
7  Dominic Mazzoni
8  Markus Meyer
9 
10 ********************************************************************//********************************************************************/
19 
20 #ifndef __AUDACITY_MIX__
21 #define __AUDACITY_MIX__
22 
23 #include "audacity/Types.h"
24 #include "SampleFormat.h"
25 #include <vector>
26 
27 class sampleCount;
28 class Resample;
29 class BoundedEnvelope;
30 class WaveTrackFactory;
31 class TrackList;
32 class WaveTrack;
33 using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
34 class WaveTrackCache;
35 
48 void AUDACITY_DLL_API MixAndRender(TrackList * tracks, WaveTrackFactory *factory,
49  double rate, sampleFormat format,
50  double startTime, double endTime,
51  std::shared_ptr<WaveTrack> &uLeft,
52  std::shared_ptr<WaveTrack> &uRight);
53 
54 class AUDACITY_DLL_API MixerSpec
55 {
56  unsigned mNumTracks, mNumChannels, mMaxNumChannels;
57 
58  void Alloc();
59 
60 public:
62 
63  MixerSpec( unsigned numTracks, unsigned maxNumChannels );
64  MixerSpec( const MixerSpec &mixerSpec );
65  virtual ~MixerSpec();
66 
67  bool SetNumChannels( unsigned numChannels );
68  unsigned GetNumChannels() { return mNumChannels; }
69 
70  unsigned GetMaxNumChannels() { return mMaxNumChannels; }
71  unsigned GetNumTracks() { return mNumTracks; }
72 
73  MixerSpec& operator=( const MixerSpec &mixerSpec );
74 };
75 
76 class AUDACITY_DLL_API Mixer {
77  public:
78 
79  // An argument to Mixer's constructor
80  class AUDACITY_DLL_API WarpOptions
81  {
82  public:
84  explicit WarpOptions(const TrackList &list);
85 
87  explicit WarpOptions(const BoundedEnvelope *e);
88 
90  WarpOptions(double min, double max);
91 
92  private:
93  friend class Mixer;
94  const BoundedEnvelope *envelope = nullptr;
95  double minSpeed, maxSpeed;
96  };
97 
98  //
99  // Constructor / Destructor
100  //
101 
102  Mixer(const WaveTrackConstArray &inputTracks, bool mayThrow,
103  const WarpOptions &warpOptions,
104  double startTime, double stopTime,
105  unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
106  double outRate, sampleFormat outFormat,
107  bool highQuality = true, MixerSpec *mixerSpec = nullptr,
108  bool applytTrackGains = true);
109 
110  virtual ~ Mixer();
111 
112  //
113  // Processing
114  //
115 
120  size_t Process(size_t maxSamples);
121 
124  void Restart();
125 
128  void Reposition(double t, bool bSkipping = false);
129 
130  // Used in scrubbing.
131  void SetTimesAndSpeed(double t0, double t1, double speed);
132  void SetSpeedForPlayAtSpeed(double speed);
133  void SetSpeedForKeyboardScrubbing(double speed, double startTime);
134 
137  double MixGetCurrentTime();
138 
141 
143  constSamplePtr GetBuffer(int channel);
144 
145  private:
146 
147  void Clear();
148  size_t MixSameRate(int *channelFlags, WaveTrackCache &cache,
149  sampleCount *pos);
150 
151  size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache,
152  sampleCount *pos, float *queue,
153  int *queueStart, int *queueLen,
154  Resample * pResample);
155 
156  void MakeResamplers();
157 
158  private:
159 
160  // Input
161  const size_t mNumInputTracks;
166  const bool mApplyTrackGains;
168  double mT0; // Start time
169  double mT1; // Stop time (none if mT0==mT1)
170  double mTime; // Current time (renamed from mT to mTime for consistency with AudioIO - mT represented warped time there)
172  const size_t mQueueMaxLen;
176  size_t mProcessLen;
178 
179  // Output
180  size_t mMaxOut;
181  const unsigned mNumChannels;
183  unsigned mNumBuffers;
184  size_t mBufferSize;
191  const double mRate;
192  double mSpeed;
194  std::vector<double> mMinFactor, mMaxFactor;
195 
196  const bool mMayThrow;
197 };
198 
199 #endif
200 
WaveTrackCache
A short-lived object, during whose lifetime, the contents of the WaveTrack are assumed not to change.
Definition: WaveTrack.h:633
Mixer::MixSameRate
size_t MixSameRate(int *channelFlags, WaveTrackCache &cache, sampleCount *pos)
Definition: Mix.cpp:565
Mixer::mSampleQueue
FloatBuffers mSampleQueue
Definition: Mix.h:173
WaveTrackConstArray
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:49
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
Mixer::mInterleaved
bool mInterleaved
Definition: Mix.h:187
Mixer::mInputTrack
ArrayOf< WaveTrackCache > mInputTrack
Definition: Mix.h:162
Mixer::mMixerSpec
MixerSpec * mMixerSpec
Definition: Mix.h:177
Mixer::mFormat
const sampleFormat mFormat
Definition: Mix.h:186
Mixer::mBuffer
ArrayOf< SampleBuffer > mBuffer
Definition: Mix.h:188
Mixer::mMaxOut
size_t mMaxOut
Definition: Mix.h:180
Mixer::mEnvelope
const BoundedEnvelope * mEnvelope
Definition: Mix.h:164
Mixer::mRate
const double mRate
Definition: Mix.h:191
Mixer::WarpOptions
Definition: Mix.h:81
Mixer::mGains
Floats mGains
Definition: Mix.h:182
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
Mixer::Reposition
void Reposition(double t, bool bSkipping=false)
Definition: Mix.cpp:746
Mixer::mBufferSize
size_t mBufferSize
Definition: Mix.h:184
Mixer::MakeResamplers
void MakeResamplers()
Definition: Mix.cpp:350
Mixer::SetSpeedForKeyboardScrubbing
void SetSpeedForKeyboardScrubbing(double speed, double startTime)
Definition: Mix.cpp:784
Mixer::mEnvValues
Doubles mEnvValues
Definition: Mix.h:167
Mixer::SetTimesAndSpeed
void SetTimesAndSpeed(double t0, double t1, double speed)
Definition: Mix.cpp:769
Mixer::WarpOptions::minSpeed
double minSpeed
Definition: Mix.h:95
MixAndRender
void AUDACITY_DLL_API MixAndRender(TrackList *tracks, WaveTrackFactory *factory, double rate, sampleFormat format, double startTime, double endTime, std::shared_ptr< WaveTrack > &uLeft, std::shared_ptr< WaveTrack > &uRight)
Mixes together all input tracks, applying any envelopes, amplitude gain, panning, and real-time effec...
Definition: Mix.cpp:43
BoundedEnvelope
Definition: Envelope.h:284
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:806
ArraysOf< bool >
MixerSpec::mMap
ArraysOf< bool > mMap
Definition: Mix.h:61
Mixer::mFloatBuffer
Floats mFloatBuffer
Definition: Mix.h:190
constSamplePtr
const char * constSamplePtr
Definition: SampleFormat.h:50
Mixer::MixVariableRates
size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache, sampleCount *pos, float *queue, int *queueStart, int *queueLen, Resample *pResample)
Definition: Mix.cpp:410
Mixer::mTime
double mTime
Definition: Mix.h:170
Mixer::mTemp
ArrayOf< Floats > mTemp
Definition: Mix.h:189
MixerSpec::GetNumTracks
unsigned GetNumTracks()
Definition: Mix.h:71
Mixer::mNumInputTracks
const size_t mNumInputTracks
Definition: Mix.h:161
format
int format
Definition: ExportPCM.cpp:56
Mixer::mSamplePos
ArrayOf< sampleCount > mSamplePos
Definition: Mix.h:165
Mixer::mT0
double mT0
Definition: Mix.h:168
Mixer::mMaxFactor
std::vector< double > mMaxFactor
Definition: Mix.h:194
Resample
Interface to libsoxr.
Definition: Resample.h:27
Mixer::mT1
double mT1
Definition: Mix.h:169
WaveTrackFactory
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:710
Mixer::Clear
void Clear()
Definition: Mix.cpp:356
sampleFormat
sampleFormat
Definition: SampleFormat.h:29
Types.h
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
Mixer::mQueueLen
ArrayOf< int > mQueueLen
Definition: Mix.h:175
Mixer::MixGetCurrentTime
double MixGetCurrentTime()
Definition: Mix.cpp:723
Mixer::mHighQuality
bool mHighQuality
Definition: Mix.h:193
Mixer::SetSpeedForPlayAtSpeed
void SetSpeedForPlayAtSpeed(double speed)
Definition: Mix.cpp:778
Mixer::Restart
void Restart()
Definition: Mix.cpp:728
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
Mixer::mQueueMaxLen
const size_t mQueueMaxLen
Definition: Mix.h:172
Mixer::mResample
ArrayOf< std::unique_ptr< Resample > > mResample
Definition: Mix.h:171
Mixer::mSpeed
double mSpeed
Definition: Mix.h:192
Mixer::mNumBuffers
unsigned mNumBuffers
Definition: Mix.h:183
Mixer::~ Mixer
virtual ~ Mixer()
Mixer::mNumChannels
const unsigned mNumChannels
Definition: Mix.h:181
Mixer::GetBuffer
constSamplePtr GetBuffer()
Retrieve the main buffer or the interleaved buffer.
Definition: Mix.cpp:713
Mixer::mMinFactor
std::vector< double > mMinFactor
Definition: Mix.h:194
Mixer::mMayThrow
const bool mMayThrow
Definition: Mix.h:196
Mixer::mApplyTrackGains
const bool mApplyTrackGains
Definition: Mix.h:166
MixerSpec
Class used with Mixer.
Definition: Mix.h:55
MixerSpec::GetNumChannels
unsigned GetNumChannels()
Definition: Mix.h:68
MixerSpec::mNumTracks
unsigned mNumTracks
Definition: Mix.h:56
MixerSpec::GetMaxNumChannels
unsigned GetMaxNumChannels()
Definition: Mix.h:70
Mixer::mInterleavedBufferSize
size_t mInterleavedBufferSize
Definition: Mix.h:185
Mixer
Functions for doing the mixdown of the tracks.
Definition: Mix.h:76
Mixer::mQueueStart
ArrayOf< int > mQueueStart
Definition: Mix.h:174
SampleFormat.h
ArrayOf< WaveTrackCache >
Mixer::mProcessLen
size_t mProcessLen
Definition: Mix.h:176
Mixer::Process
size_t Process(size_t maxSamples)
Definition: Mix.cpp:627
Mixer::mbVariableRates
bool mbVariableRates
Definition: Mix.h:163
Mixer::Mixer
Mixer(const WaveTrackConstArray &inputTracks, bool mayThrow, const WarpOptions &warpOptions, double startTime, double stopTime, unsigned numOutChannels, size_t outBufferSize, bool outInterleaved, double outRate, sampleFormat outFormat, bool highQuality=true, MixerSpec *mixerSpec=nullptr, bool applytTrackGains=true)
Definition: Mix.cpp:237