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 "SampleFormat.h"
24 #include <vector>
25 
26 class Resample;
27 class BoundedEnvelope;
28 class WaveTrackFactory;
29 class TrackList;
30 class WaveTrack;
31 using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
32 class WaveTrackCache;
33 
46 void AUDACITY_DLL_API MixAndRender(TrackList * tracks, WaveTrackFactory *factory,
47  double rate, sampleFormat format,
48  double startTime, double endTime,
49  std::shared_ptr<WaveTrack> &uLeft,
50  std::shared_ptr<WaveTrack> &uRight);
51 
52 void MixBuffers(unsigned numChannels, int *channelFlags, float *gains,
53  samplePtr src,
54  samplePtr *dests, int len, bool interleaved);
55 
56 class AUDACITY_DLL_API MixerSpec
57 {
58  unsigned mNumTracks, mNumChannels, mMaxNumChannels;
59 
60  void Alloc();
61 
62 public:
64 
65  MixerSpec( unsigned numTracks, unsigned maxNumChannels );
66  MixerSpec( const MixerSpec &mixerSpec );
67  virtual ~MixerSpec();
68 
69  bool SetNumChannels( unsigned numChannels );
70  unsigned GetNumChannels() { return mNumChannels; }
71 
72  unsigned GetMaxNumChannels() { return mMaxNumChannels; }
73  unsigned GetNumTracks() { return mNumTracks; }
74 
75  MixerSpec& operator=( const MixerSpec &mixerSpec );
76 };
77 
78 class AUDACITY_DLL_API Mixer {
79  public:
80 
81  // An argument to Mixer's constructor
82  class AUDACITY_DLL_API WarpOptions
83  {
84  public:
86  explicit WarpOptions(const TrackList &list);
87 
89  explicit WarpOptions(const BoundedEnvelope *e);
90 
92  WarpOptions(double min, double max);
93 
94  private:
95  friend class Mixer;
96  const BoundedEnvelope *envelope = nullptr;
97  double minSpeed, maxSpeed;
98  };
99 
100  //
101  // Constructor / Destructor
102  //
103 
104  Mixer(const WaveTrackConstArray &inputTracks, bool mayThrow,
105  const WarpOptions &warpOptions,
106  double startTime, double stopTime,
107  unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
108  double outRate, sampleFormat outFormat,
109  bool highQuality = true, MixerSpec *mixerSpec = nullptr,
110  bool applytTrackGains = true);
111 
112  virtual ~ Mixer();
113 
114  //
115  // Processing
116  //
117 
122  size_t Process(size_t maxSamples);
123 
126  void Restart();
127 
130  void Reposition(double t, bool bSkipping = false);
131 
132  // Used in scrubbing.
133  void SetTimesAndSpeed(double t0, double t1, double speed);
134  void SetSpeedForPlayAtSpeed(double speed);
135  void SetSpeedForKeyboardScrubbing(double speed, double startTime);
136 
139  double MixGetCurrentTime();
140 
143 
145  samplePtr GetBuffer(int channel);
146 
147  private:
148 
149  void Clear();
150  size_t MixSameRate(int *channelFlags, WaveTrackCache &cache,
151  sampleCount *pos);
152 
153  size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache,
154  sampleCount *pos, float *queue,
155  int *queueStart, int *queueLen,
156  Resample * pResample);
157 
158  void MakeResamplers();
159 
160  private:
161 
162  // Input
163  const size_t mNumInputTracks;
168  const bool mApplyTrackGains;
170  double mT0; // Start time
171  double mT1; // Stop time (none if mT0==mT1)
172  double mTime; // Current time (renamed from mT to mTime for consistency with AudioIO - mT represented warped time there)
174  const size_t mQueueMaxLen;
178  size_t mProcessLen;
180 
181  // Output
182  size_t mMaxOut;
183  const unsigned mNumChannels;
185  unsigned mNumBuffers;
186  size_t mBufferSize;
192  const double mRate;
193  double mSpeed;
195  std::vector<double> mMinFactor, mMaxFactor;
196 
197  const bool mMayThrow;
198 };
199 
200 #endif
201 
WaveTrackCache
A short-lived object, during whose lifetime, the contents of the WaveTrack are assumed not to change.
Definition: WaveTrack.h:624
Mixer::MixSameRate
size_t MixSameRate(int *channelFlags, WaveTrackCache &cache, sampleCount *pos)
Definition: Mix.cpp:568
Mixer::mSampleQueue
FloatBuffers mSampleQueue
Definition: Mix.h:175
WaveTrackConstArray
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:58
Mixer::GetBuffer
samplePtr GetBuffer()
Retrieve the main buffer or the interleaved buffer.
Definition: Mix.cpp:716
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:68
Mixer::mInterleaved
bool mInterleaved
Definition: Mix.h:189
Mixer::mInputTrack
ArrayOf< WaveTrackCache > mInputTrack
Definition: Mix.h:164
Mixer::mMixerSpec
MixerSpec * mMixerSpec
Definition: Mix.h:179
Mixer::mFormat
const sampleFormat mFormat
Definition: Mix.h:188
Mixer::mBuffer
ArrayOf< SampleBuffer > mBuffer
Definition: Mix.h:190
Mixer::mTemp
ArrayOf< SampleBuffer > mTemp
Definition: Mix.h:190
Mixer::mMaxOut
size_t mMaxOut
Definition: Mix.h:182
Mixer::mEnvelope
const BoundedEnvelope * mEnvelope
Definition: Mix.h:166
Mixer::mRate
const double mRate
Definition: Mix.h:192
Mixer::WarpOptions
Definition: Mix.h:83
Mixer::mGains
Floats mGains
Definition: Mix.h:184
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1263
Mixer::Reposition
void Reposition(double t, bool bSkipping=false)
Definition: Mix.cpp:749
Mixer::mBufferSize
size_t mBufferSize
Definition: Mix.h:186
Mixer::MakeResamplers
void MakeResamplers()
Definition: Mix.cpp:351
Mixer::SetSpeedForKeyboardScrubbing
void SetSpeedForKeyboardScrubbing(double speed, double startTime)
Definition: Mix.cpp:787
Mixer::mEnvValues
Doubles mEnvValues
Definition: Mix.h:169
Mixer::SetTimesAndSpeed
void SetTimesAndSpeed(double t0, double t1, double speed)
Definition: Mix.cpp:772
Mixer::WarpOptions::minSpeed
double minSpeed
Definition: Mix.h:97
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
samplePtr
char * samplePtr
Definition: Types.h:214
sampleFormat
sampleFormat
Definition: Types.h:194
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:807
ArraysOf< bool >
MixerSpec::mMap
ArraysOf< bool > mMap
Definition: Mix.h:63
Mixer::mFloatBuffer
Floats mFloatBuffer
Definition: Mix.h:191
Mixer::MixVariableRates
size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache, sampleCount *pos, float *queue, int *queueStart, int *queueLen, Resample *pResample)
Definition: Mix.cpp:413
Mixer::mTime
double mTime
Definition: Mix.h:172
MixerSpec::GetNumTracks
unsigned GetNumTracks()
Definition: Mix.h:73
Mixer::mNumInputTracks
const size_t mNumInputTracks
Definition: Mix.h:163
format
int format
Definition: ExportPCM.cpp:54
Mixer::mSamplePos
ArrayOf< sampleCount > mSamplePos
Definition: Mix.h:167
Mixer::mT0
double mT0
Definition: Mix.h:170
Mixer::mMaxFactor
std::vector< double > mMaxFactor
Definition: Mix.h:195
Resample
Interface to libsoxr.
Definition: Resample.h:29
Mixer::mT1
double mT1
Definition: Mix.h:171
WaveTrackFactory
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:699
Mixer::Clear
void Clear()
Definition: Mix.cpp:357
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
Mixer::mQueueLen
ArrayOf< int > mQueueLen
Definition: Mix.h:177
Mixer::MixGetCurrentTime
double MixGetCurrentTime()
Definition: Mix.cpp:726
Mixer::mHighQuality
bool mHighQuality
Definition: Mix.h:194
Mixer::SetSpeedForPlayAtSpeed
void SetSpeedForPlayAtSpeed(double speed)
Definition: Mix.cpp:781
Mixer::Restart
void Restart()
Definition: Mix.cpp:731
MixBuffers
void MixBuffers(unsigned numChannels, int *channelFlags, float *gains, samplePtr src, samplePtr *dests, int len, bool interleaved)
sampleCount
Definition: Types.h:66
Mixer::mQueueMaxLen
const size_t mQueueMaxLen
Definition: Mix.h:174
Mixer::mResample
ArrayOf< std::unique_ptr< Resample > > mResample
Definition: Mix.h:173
Mixer::mSpeed
double mSpeed
Definition: Mix.h:193
Mixer::mNumBuffers
unsigned mNumBuffers
Definition: Mix.h:185
Mixer::~ Mixer
virtual ~ Mixer()
Mixer::mNumChannels
const unsigned mNumChannels
Definition: Mix.h:183
Mixer::mMinFactor
std::vector< double > mMinFactor
Definition: Mix.h:195
Mixer::mMayThrow
const bool mMayThrow
Definition: Mix.h:197
Mixer::mApplyTrackGains
const bool mApplyTrackGains
Definition: Mix.h:168
MixerSpec
Class used with Mixer.
Definition: Mix.h:57
MixerSpec::GetNumChannels
unsigned GetNumChannels()
Definition: Mix.h:70
MixerSpec::mNumTracks
unsigned mNumTracks
Definition: Mix.h:58
MixerSpec::GetMaxNumChannels
unsigned GetMaxNumChannels()
Definition: Mix.h:72
Mixer::mInterleavedBufferSize
size_t mInterleavedBufferSize
Definition: Mix.h:187
Mixer
Functions for doing the mixdown of the tracks.
Definition: Mix.h:78
Mixer::mQueueStart
ArrayOf< int > mQueueStart
Definition: Mix.h:176
SampleFormat.h
ArrayOf< WaveTrackCache >
Mixer::mProcessLen
size_t mProcessLen
Definition: Mix.h:178
Mixer::Process
size_t Process(size_t maxSamples)
Definition: Mix.cpp:630
Mixer::mbVariableRates
bool mbVariableRates
Definition: Mix.h:165
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:238