Audacity  2.2.0
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 
27 class Resample;
28 class DirManager;
29 class TimeTrack;
30 class TrackFactory;
31 class TrackList;
32 class WaveTrack;
34 class WaveTrackCache;
35 
48 void MixAndRender(TrackList * tracks, TrackFactory *factory,
49  double rate, sampleFormat format,
50  double startTime, double endTime,
51  std::unique_ptr<WaveTrack> &uLeft, std::unique_ptr<WaveTrack> &uRight);
52 
53 void MixBuffers(unsigned numChannels, int *channelFlags, float *gains,
54  samplePtr src,
55  samplePtr *dests, int len, bool interleaved);
56 
57 class AUDACITY_DLL_API MixerSpec
58 {
59  unsigned mNumTracks, mNumChannels, mMaxNumChannels;
60 
61  void Alloc();
62 
63 public:
65 
66  MixerSpec( unsigned numTracks, unsigned maxNumChannels );
67  MixerSpec( const MixerSpec &mixerSpec );
68  virtual ~MixerSpec();
69 
70  bool SetNumChannels( unsigned numChannels );
71  unsigned GetNumChannels() { return mNumChannels; }
72 
73  unsigned GetMaxNumChannels() { return mMaxNumChannels; }
74  unsigned GetNumTracks() { return mNumTracks; }
75 
76  MixerSpec& operator=( const MixerSpec &mixerSpec );
77 };
78 
79 class AUDACITY_DLL_API Mixer {
80  public:
81 
82  // An argument to Mixer's constructor
84  {
85  public:
86  explicit WarpOptions(const TimeTrack *t)
87  : timeTrack(t), minSpeed(0.0), maxSpeed(0.0)
88  {}
89 
90  WarpOptions(double min, double max);
91 
92  private:
93  friend class Mixer;
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 = NULL);
108 
109  virtual ~ Mixer();
110 
111  //
112  // Setup
113  //
114 
115  void ApplyTrackGains(bool apply = true); // True by default
116 
117  //
118  // Processing
119  //
120 
125  size_t Process(size_t maxSamples);
126 
129  void Restart();
130 
133  void Reposition(double t);
134 
135  // Used in scrubbing.
136  void SetTimesAndSpeed(double t0, double t1, double speed);
137 
140  double MixGetCurrentTime();
141 
143  samplePtr GetBuffer();
144 
146  samplePtr GetBuffer(int channel);
147 
148  private:
149 
150  void Clear();
151  size_t MixSameRate(int *channelFlags, WaveTrackCache &cache,
152  sampleCount *pos);
153 
154  size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache,
155  sampleCount *pos, float *queue,
156  int *queueStart, int *queueLen,
157  Resample * pResample);
158 
159  private:
160 
161  // Input
169  double mT0; // Start time
170  double mT1; // Stop time (none if mT0==mT1)
171  double mTime; // Current time (renamed from mT to mTime for consistency with AudioIO - mT represented warped time there)
173  size_t mQueueMaxLen;
177  size_t mProcessLen;
179 
180  // Output
181  size_t mMaxOut;
182  unsigned mNumChannels;
184  unsigned mNumBuffers;
185  size_t mBufferSize;
187  sampleFormat mFormat;
191  double mRate;
192  double mSpeed;
194 
195  bool mMayThrow;
196 };
197 
198 #endif
199 
size_t Process(size_t maxSamples)
Definition: Mix.cpp:601
ArrayOf< WaveTrackCache > mInputTrack
Definition: Mix.h:163
size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache, sampleCount *pos, float *queue, int *queueStart, int *queueLen, Resample *pResample)
Definition: Mix.cpp:392
A list of TrackListNode items.
Definition: Track.h:550
Creates and manages BlockFile objects.
Definition: DirManager.h:52
void Restart()
Definition: Mix.cpp:702
double mT0
Definition: Mix.h:169
double mSpeed
Definition: Mix.h:192
double MixGetCurrentTime()
Definition: Mix.cpp:697
unsigned mNumBuffers
Definition: Mix.h:184
ArrayOf< std::unique_ptr< Resample > > mResample
Definition: Mix.h:172
ArrayOf< sampleCount > mSamplePos
Definition: Mix.h:166
Floats mGains
Definition: Mix.h:183
Definition: Track.h:53
double mTime
Definition: Mix.h:171
bool mApplyTrackGains
Definition: Mix.h:167
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:45
double minSpeed
Definition: Mix.h:95
Used to create a WaveTrack, or a LabelTrack.. Implementation of the functions of this class are dispe...
Definition: Track.h:694
size_t mInterleavedBufferSize
Definition: Mix.h:186
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:29
size_t MixSameRate(int *channelFlags, WaveTrackCache &cache, sampleCount *pos)
Definition: Mix.cpp:539
Definition: Mix.h:83
int format
Definition: ExportPCM.cpp:56
sampleFormat mFormat
Definition: Mix.h:187
unsigned GetNumTracks()
Definition: Mix.h:74
const TimeTrack * timeTrack
Definition: Mix.h:94
const TimeTrack * mTimeTrack
Definition: Mix.h:165
void Reposition(double t)
Definition: Mix.cpp:715
size_t mNumInputTracks
Definition: Mix.h:162
size_t mMaxOut
Definition: Mix.h:181
void ApplyTrackGains(bool apply=true)
Definition: Mix.cpp:351
size_t mProcessLen
Definition: Mix.h:177
ArraysOf< bool > mMap
Definition: Mix.h:64
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:76
ArrayOf< int > mQueueStart
Definition: Mix.h:175
unsigned mNumChannels
Definition: Mix.h:182
size_t mQueueMaxLen
Definition: Mix.h:173
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:243
double mT1
Definition: Mix.h:170
int min(int a, int b)
Definition: CompareAudioCommand.cpp:80
samplePtr GetBuffer()
Retrieve the main buffer or the interleaved buffer.
Definition: Mix.cpp:687
ArrayOf< int > mQueueLen
Definition: Mix.h:176
double mRate
Definition: Mix.h:191
Definition: WaveTrack.h:669
unsigned GetNumChannels()
Definition: Mix.h:71
Interface to libsoxr.
Definition: Resample.h:30
void SetTimesAndSpeed(double t0, double t1, double speed)
Definition: Mix.cpp:731
unsigned GetMaxNumChannels()
Definition: Mix.h:73
bool mMayThrow
Definition: Mix.h:195
WarpOptions(const TimeTrack *t)
Definition: Mix.h:86
Doubles mEnvValues
Definition: Mix.h:168
FloatBuffers mSampleQueue
Definition: Mix.h:174
unsigned mNumTracks
Definition: Mix.h:59
ArrayOf< SampleBuffer > mBuffer
Definition: Mix.h:189
virtual ~Mixer()
Definition: Mix.cpp:347
Functions for doing the mixdown of the tracks.
Definition: Mix.h:79
size_t mBufferSize
Definition: Mix.h:185
ArrayOf< SampleBuffer > mTemp
Definition: Mix.h:189
bool mbVariableRates
Definition: Mix.h:164
MixerSpec * mMixerSpec
Definition: Mix.h:178
void Clear()
Definition: Mix.cpp:356
bool mInterleaved
Definition: Mix.h:188
bool mHighQuality
Definition: Mix.h:193
Floats mFloatBuffer
Definition: Mix.h:190
Class used with Mixer.
Definition: Mix.h:57