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 **********************************************************************/
11 
12 #ifndef __AUDACITY_MIX__
13 #define __AUDACITY_MIX__
14 
15 #include "MemoryX.h"
16 #include <wx/string.h>
17 #include "SampleFormat.h"
18 
19 class Resample;
20 class DirManager;
21 class TimeTrack;
22 class TrackFactory;
23 class TrackList;
24 class WaveTrack;
26 class WaveTrackCache;
27 
40 void MixAndRender(TrackList * tracks, TrackFactory *factory,
41  double rate, sampleFormat format,
42  double startTime, double endTime,
43  std::unique_ptr<WaveTrack> &uLeft, std::unique_ptr<WaveTrack> &uRight);
44 
45 void MixBuffers(unsigned numChannels, int *channelFlags, float *gains,
46  samplePtr src,
47  samplePtr *dests, int len, bool interleaved);
48 
49 class AUDACITY_DLL_API MixerSpec
50 {
51  unsigned mNumTracks, mNumChannels, mMaxNumChannels;
52 
53  void Alloc();
54 
55 public:
57 
58  MixerSpec( unsigned numTracks, unsigned maxNumChannels );
59  MixerSpec( const MixerSpec &mixerSpec );
60  virtual ~MixerSpec();
61 
62  bool SetNumChannels( unsigned numChannels );
63  unsigned GetNumChannels() { return mNumChannels; }
64 
65  unsigned GetMaxNumChannels() { return mMaxNumChannels; }
66  unsigned GetNumTracks() { return mNumTracks; }
67 
68  MixerSpec& operator=( const MixerSpec &mixerSpec );
69 };
70 
71 class AUDACITY_DLL_API Mixer {
72  public:
73 
74  // An argument to Mixer's constructor
76  {
77  public:
78  explicit WarpOptions(const TimeTrack *t)
79  : timeTrack(t), minSpeed(0.0), maxSpeed(0.0)
80  {}
81 
82  WarpOptions(double min, double max);
83 
84  private:
85  friend class Mixer;
87  double minSpeed, maxSpeed;
88  };
89 
90  //
91  // Constructor / Destructor
92  //
93 
94  Mixer(const WaveTrackConstArray &inputTracks, bool mayThrow,
95  const WarpOptions &warpOptions,
96  double startTime, double stopTime,
97  unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
98  double outRate, sampleFormat outFormat,
99  bool highQuality = true, MixerSpec *mixerSpec = NULL);
100 
101  virtual ~ Mixer();
102 
103  //
104  // Setup
105  //
106 
107  void ApplyTrackGains(bool apply = true); // True by default
108 
109  //
110  // Processing
111  //
112 
117  size_t Process(size_t maxSamples);
118 
121  void Restart();
122 
125  void Reposition(double t);
126 
127  // Used in scrubbing.
128  void SetTimesAndSpeed(double t0, double t1, double speed);
129 
132  double MixGetCurrentTime();
133 
135  samplePtr GetBuffer();
136 
138  samplePtr GetBuffer(int channel);
139 
140  private:
141 
142  void Clear();
143  size_t MixSameRate(int *channelFlags, WaveTrackCache &cache,
144  sampleCount *pos);
145 
146  size_t MixVariableRates(int *channelFlags, WaveTrackCache &cache,
147  sampleCount *pos, float *queue,
148  int *queueStart, int *queueLen,
149  Resample * pResample);
150 
151  private:
152 
153  // Input
161  double mT0; // Start time
162  double mT1; // Stop time (none if mT0==mT1)
163  double mTime; // Current time (renamed from mT to mTime for consistency with AudioIO - mT represented warped time there)
165  size_t mQueueMaxLen;
169  size_t mProcessLen;
171 
172  // Output
173  size_t mMaxOut;
174  unsigned mNumChannels;
176  unsigned mNumBuffers;
177  size_t mBufferSize;
179  sampleFormat mFormat;
183  double mRate;
184  double mSpeed;
186 
187  bool mMayThrow;
188 };
189 
190 #endif
191 
size_t Process(size_t maxSamples)
Definition: Mix.cpp:601
ArrayOf< WaveTrackCache > mInputTrack
Definition: Mix.h:155
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:532
Creates and manages BlockFile objects.
Definition: DirManager.h:52
void Restart()
Definition: Mix.cpp:702
double mT0
Definition: Mix.h:161
double mSpeed
Definition: Mix.h:184
double MixGetCurrentTime()
Definition: Mix.cpp:697
unsigned mNumBuffers
Definition: Mix.h:176
ArrayOf< std::unique_ptr< Resample > > mResample
Definition: Mix.h:164
ArrayOf< sampleCount > mSamplePos
Definition: Mix.h:158
Floats mGains
Definition: Mix.h:175
Definition: Track.h:53
double mTime
Definition: Mix.h:163
bool mApplyTrackGains
Definition: Mix.h:159
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:87
Used to create a WaveTrack, or a LabelTrack.. Implementation of the functions of this class are dispe...
Definition: Track.h:676
size_t mInterleavedBufferSize
Definition: Mix.h:178
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:75
int format
Definition: ExportPCM.cpp:56
sampleFormat mFormat
Definition: Mix.h:179
unsigned GetNumTracks()
Definition: Mix.h:66
const TimeTrack * timeTrack
Definition: Mix.h:86
const TimeTrack * mTimeTrack
Definition: Mix.h:157
void Reposition(double t)
Definition: Mix.cpp:715
size_t mNumInputTracks
Definition: Mix.h:154
size_t mMaxOut
Definition: Mix.h:173
void ApplyTrackGains(bool apply=true)
Definition: Mix.cpp:351
size_t mProcessLen
Definition: Mix.h:169
ArraysOf< bool > mMap
Definition: Mix.h:56
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:167
unsigned mNumChannels
Definition: Mix.h:174
size_t mQueueMaxLen
Definition: Mix.h:165
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:162
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:168
double mRate
Definition: Mix.h:183
Definition: WaveTrack.h:656
unsigned GetNumChannels()
Definition: Mix.h:63
Interface to libsoxr.
Definition: Resample.h:30
void SetTimesAndSpeed(double t0, double t1, double speed)
Definition: Mix.cpp:731
unsigned GetMaxNumChannels()
Definition: Mix.h:65
bool mMayThrow
Definition: Mix.h:187
WarpOptions(const TimeTrack *t)
Definition: Mix.h:78
Doubles mEnvValues
Definition: Mix.h:160
FloatBuffers mSampleQueue
Definition: Mix.h:166
unsigned mNumTracks
Definition: Mix.h:51
ArrayOf< SampleBuffer > mBuffer
Definition: Mix.h:181
virtual ~Mixer()
Definition: Mix.cpp:347
Functions for doing the mixdown of the tracks.
Definition: Mix.h:71
size_t mBufferSize
Definition: Mix.h:177
ArrayOf< SampleBuffer > mTemp
Definition: Mix.h:181
bool mbVariableRates
Definition: Mix.h:156
MixerSpec * mMixerSpec
Definition: Mix.h:170
void Clear()
Definition: Mix.cpp:356
bool mInterleaved
Definition: Mix.h:180
bool mHighQuality
Definition: Mix.h:185
Floats mFloatBuffer
Definition: Mix.h:182
Class used with Mixer.
Definition: Mix.h:49