Audacity  2.2.2
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 "MemoryX.h"
24 #include <wx/string.h>
25 #include "SampleFormat.h"
26 #include <vector>
27 
28 class Resample;
29 class DirManager;
30 class TimeTrack;
31 class TrackFactory;
32 class TrackList;
33 class WaveTrack;
34 using WaveTrackConstArray = std::vector < std::shared_ptr < const WaveTrack > >;
35 class WaveTrackCache;
36 
49 void MixAndRender(TrackList * tracks, TrackFactory *factory,
50  double rate, sampleFormat format,
51  double startTime, double endTime,
52  std::unique_ptr<WaveTrack> &uLeft, std::unique_ptr<WaveTrack> &uRight);
53 
54 void MixBuffers(unsigned numChannels, int *channelFlags, float *gains,
55  samplePtr src,
56  samplePtr *dests, int len, bool interleaved);
57 
58 class AUDACITY_DLL_API MixerSpec
59 {
60  unsigned mNumTracks, mNumChannels, mMaxNumChannels;
61 
62  void Alloc();
63 
64 public:
66 
67  MixerSpec( unsigned numTracks, unsigned maxNumChannels );
68  MixerSpec( const MixerSpec &mixerSpec );
69  virtual ~MixerSpec();
70 
71  bool SetNumChannels( unsigned numChannels );
72  unsigned GetNumChannels() { return mNumChannels; }
73 
74  unsigned GetMaxNumChannels() { return mMaxNumChannels; }
75  unsigned GetNumTracks() { return mNumTracks; }
76 
77  MixerSpec& operator=( const MixerSpec &mixerSpec );
78 };
79 
80 class AUDACITY_DLL_API Mixer {
81  public:
82 
83  // An argument to Mixer's constructor
85  {
86  public:
87  explicit WarpOptions(const TimeTrack *t)
88  : timeTrack(t), minSpeed(0.0), maxSpeed(0.0)
89  {}
90 
91  WarpOptions(double min, double max);
92 
93  private:
94  friend class Mixer;
96  double minSpeed, maxSpeed;
97  };
98 
99  //
100  // Constructor / Destructor
101  //
102 
103  Mixer(const WaveTrackConstArray &inputTracks, bool mayThrow,
104  const WarpOptions &warpOptions,
105  double startTime, double stopTime,
106  unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
107  double outRate, sampleFormat outFormat,
108  bool highQuality = true, MixerSpec *mixerSpec = NULL);
109 
110  virtual ~ Mixer();
111 
112  //
113  // Setup
114  //
115 
116  void ApplyTrackGains(bool apply = true); // True by default
117 
118  //
119  // Processing
120  //
121 
126  size_t Process(size_t maxSamples);
127 
130  void Restart();
131 
134  void Reposition(double t);
135 
136  // Used in scrubbing.
137  void SetTimesAndSpeed(double t0, double t1, double speed);
138 
141  double MixGetCurrentTime();
142 
144  samplePtr GetBuffer();
145 
147  samplePtr GetBuffer(int channel);
148 
149  private:
150 
151  void Clear();
152  size_t MixSameRate(int *channelFlags, WaveTrackCache &cache,
153  sampleCount *pos);
154 
155  size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache,
156  sampleCount *pos, float *queue,
157  int *queueStart, int *queueLen,
158  Resample * pResample);
159 
160  private:
161 
162  // Input
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  size_t mQueueMaxLen;
178  size_t mProcessLen;
180 
181  // Output
182  size_t mMaxOut;
183  unsigned mNumChannels;
185  unsigned mNumBuffers;
186  size_t mBufferSize;
188  sampleFormat mFormat;
192  double mRate;
193  double mSpeed;
195 
196  bool mMayThrow;
197 };
198 
199 #endif
200 
size_t Process(size_t maxSamples)
Definition: Mix.cpp:600
ArrayOf< WaveTrackCache > mInputTrack
Definition: Mix.h:164
size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache, sampleCount *pos, float *queue, int *queueStart, int *queueLen, Resample *pResample)
Definition: Mix.cpp:391
A list of TrackListNode items.
Definition: Track.h:612
Creates and manages BlockFile objects.
Definition: DirManager.h:54
void Restart()
Definition: Mix.cpp:701
double mT0
Definition: Mix.h:170
double mSpeed
Definition: Mix.h:193
double MixGetCurrentTime()
Definition: Mix.cpp:696
unsigned mNumBuffers
Definition: Mix.h:185
ArrayOf< std::unique_ptr< Resample > > mResample
Definition: Mix.h:173
ArrayOf< sampleCount > mSamplePos
Definition: Mix.h:167
Floats mGains
Definition: Mix.h:184
double mTime
Definition: Mix.h:172
bool mApplyTrackGains
Definition: Mix.h:168
void MixAndRender(TrackList *tracks, TrackFactory *factory, double rate, sampleFormat format, double startTime, double endTime, std::unique_ptr< WaveTrack > &uLeft, std::unique_ptr< WaveTrack > &uRight)
Mixes together all input tracks, applying any envelopes, amplitude gain, panning, and real-time effec...
Definition: Mix.cpp:44
double minSpeed
Definition: Mix.h:96
Used to create a WaveTrack, or a LabelTrack.. Implementation of the functions of this class are dispe...
Definition: Track.h:856
size_t mInterleavedBufferSize
Definition: Mix.h:187
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:29
size_t MixSameRate(int *channelFlags, WaveTrackCache &cache, sampleCount *pos)
Definition: Mix.cpp:538
int format
Definition: ExportPCM.cpp:56
sampleFormat mFormat
Definition: Mix.h:188
unsigned GetNumTracks()
Definition: Mix.h:75
const TimeTrack * timeTrack
Definition: Mix.h:95
const TimeTrack * mTimeTrack
Definition: Mix.h:166
void Reposition(double t)
Definition: Mix.cpp:714
size_t mNumInputTracks
Definition: Mix.h:163
size_t mMaxOut
Definition: Mix.h:182
void ApplyTrackGains(bool apply=true)
Definition: Mix.cpp:350
size_t mProcessLen
Definition: Mix.h:178
ArraysOf< bool > mMap
Definition: Mix.h:65
std::vector< std::shared_ptr< const WaveTrack > > WaveTrackConstArray
Definition: AudioIO.h:66
void MixBuffers(unsigned numChannels, int *channelFlags, float *gains, samplePtr src, samplePtr *dests, int len, bool interleaved)
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
ArrayOf< int > mQueueStart
Definition: Mix.h:176
unsigned mNumChannels
Definition: Mix.h:183
size_t mQueueMaxLen
Definition: Mix.h:174
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=NULL)
Definition: Mix.cpp:242
double mT1
Definition: Mix.h:171
int min(int a, int b)
samplePtr GetBuffer()
Retrieve the main buffer or the interleaved buffer.
Definition: Mix.cpp:686
ArrayOf< int > mQueueLen
Definition: Mix.h:177
double mRate
Definition: Mix.h:192
unsigned GetNumChannels()
Definition: Mix.h:72
Interface to libsoxr.
Definition: Resample.h:30
void SetTimesAndSpeed(double t0, double t1, double speed)
Definition: Mix.cpp:730
unsigned GetMaxNumChannels()
Definition: Mix.h:74
bool mMayThrow
Definition: Mix.h:196
WarpOptions(const TimeTrack *t)
Definition: Mix.h:87
Doubles mEnvValues
Definition: Mix.h:169
FloatBuffers mSampleQueue
Definition: Mix.h:175
unsigned mNumTracks
Definition: Mix.h:60
ArrayOf< SampleBuffer > mBuffer
Definition: Mix.h:190
virtual ~Mixer()
Definition: Mix.cpp:346
Functions for doing the mixdown of the tracks.
Definition: Mix.h:80
size_t mBufferSize
Definition: Mix.h:186
ArrayOf< SampleBuffer > mTemp
Definition: Mix.h:190
bool mbVariableRates
Definition: Mix.h:165
MixerSpec * mMixerSpec
Definition: Mix.h:179
void Clear()
Definition: Mix.cpp:355
bool mInterleaved
Definition: Mix.h:189
bool mHighQuality
Definition: Mix.h:194
Floats mFloatBuffer
Definition: Mix.h:191
Class used with Mixer.
Definition: Mix.h:58