Audacity 3.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 "AudioGraphBuffers.h"
16#include "MixerOptions.h"
17#include "SampleFormat.h"
18
19class sampleCount;
20class BoundedEnvelope;
21namespace AudioGraph{ class EffectStage; class Source; }
22class MixerSource;
23class TrackList;
24class SampleTrack;
25
26class SAMPLE_TRACK_API Mixer {
27 public:
32 using Stages = std::vector<MixerOptions::StageSpecification>;
33
34 struct Input {
36 std::shared_ptr<const SampleTrack> pTrack = {}, Stages stages = {}
37 ) : pTrack{ move(pTrack) }, stages{ move(stages) }
38 {}
39
40 std::shared_ptr<const SampleTrack> pTrack;
42 };
43 using Inputs = std::vector<Input>;
44
45 //
46 // Constructor / Destructor
47 //
48
55 Mixer(Inputs inputs, bool mayThrow,
56 const WarpOptions &warpOptions,
57 double startTime, double stopTime,
58 unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
59 double outRate, sampleFormat outFormat,
60 bool highQuality = true,
62 MixerSpec *mixerSpec = nullptr,
63 bool applytTrackGains = true);
64
65 Mixer(const Mixer&) = delete;
66 Mixer &operator=(const Mixer&) = delete;
67
68 virtual ~ Mixer();
69
70 size_t BufferSize() const { return mBufferSize; }
71
72 //
73 // Processing
74 //
75
78
84 size_t Process(size_t maxSamples);
85
89 size_t Process() { return Process(BufferSize()); }
90
92 void Restart();
93
95 void Reposition(double t, bool bSkipping = false);
96
98 void SetTimesAndSpeed(
99 double t0, double t1, double speed, bool bSkipping = false);
100 void SetSpeedForKeyboardScrubbing(double speed, double startTime);
101
103
104 double MixGetCurrentTime();
105
107 constSamplePtr GetBuffer();
108
110 constSamplePtr GetBuffer(int channel);
111
113 sampleFormat EffectiveFormat() const;
114
115 private:
116
117 void Clear();
118
119 private:
120
121 // Input
122 const unsigned mNumChannels;
124
125 // Transformations
126 const size_t mBufferSize;
127
128 std::pair<bool, sampleFormat>
129 NeedsDither(bool needsDither, double rate) const;
130
131 private:
132
133 // Output
135 const bool mHighQuality; // dithering
136 const sampleFormat mFormat; // output format also influences dithering
137 const bool mInterleaved;
138
139 // INPUT
142
143 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
144
145 // BUFFERS
146
147 // Resample into these buffers, or produce directly when not resampling
149
150 // Each channel's data is transformed, including application of
151 // gains and pans, and then (maybe many-to-one) mixer specifications
152 // determine where in mTemp it is accumulated
153 std::vector<std::vector<float>> mTemp;
154
155 // Final result applies dithering and interleaving
156 const std::vector<SampleBuffer> mBuffer;
157
158 std::vector<MixerSource> mSources;
159 std::vector<EffectSettings> mSettings;
160 std::vector<AudioGraph::Buffers> mStageBuffers;
161 std::vector<std::unique_ptr<AudioGraph::EffectStage>> mStages;
162
164 std::vector<Source> mDecoratedSources;
165};
166#endif
constexpr int BufferSize
sampleFormat
The ordering of these values with operator < agrees with the order of increasing bit width.
Definition: SampleFormat.h:30
const char * constSamplePtr
Definition: SampleFormat.h:56
Accumulates (non-interleaved) data during effect processing.
Upstream producer of sample streams, taking Buffers as external context.
Functions for doing the mixdown of the tracks.
Definition: Mix.h:26
AudioGraph::Buffers mFloatBuffers
Definition: Mix.h:148
std::vector< EffectSettings > mSettings
Definition: Mix.h:159
const std::vector< SampleBuffer > mBuffer
Definition: Mix.h:156
std::vector< Input > Inputs
Definition: Mix.h:43
std::vector< Source > mDecoratedSources
Definition: Mix.h:164
const bool mApplyTrackGains
Definition: Mix.h:134
const sampleFormat mFormat
Definition: Mix.h:136
Inputs mInputs
Definition: Mix.h:123
std::vector< std::unique_ptr< AudioGraph::EffectStage > > mStages
Definition: Mix.h:161
std::vector< std::vector< float > > mTemp
Definition: Mix.h:153
void Restart()
Restart processing at beginning of buffer next time Process() is called.
const unsigned mNumChannels
Definition: Mix.h:122
sampleFormat mEffectiveFormat
Definition: Mix.h:140
std::vector< MixerOptions::StageSpecification > Stages
Definition: Mix.h:32
const bool mInterleaved
Definition: Mix.h:137
const size_t mBufferSize
Definition: Mix.h:126
bool mNeedsDither
Definition: Mix.h:141
Mixer(const Mixer &)=delete
std::vector< AudioGraph::Buffers > mStageBuffers
Definition: Mix.h:160
const bool mHighQuality
Definition: Mix.h:135
std::vector< MixerSource > mSources
Definition: Mix.h:158
size_t Process()
Definition: Mix.h:89
size_t BufferSize() const
Definition: Mix.h:70
Mixer & operator=(const Mixer &)=delete
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: Mix.h:143
A matrix of booleans, one row per input channel, column per output.
Definition: MixerOptions.h:32
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1339
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
Stages stages
Definition: Mix.h:41
std::shared_ptr< const SampleTrack > pTrack
Definition: Mix.h:40
Input(std::shared_ptr< const SampleTrack > pTrack={}, Stages stages={})
Definition: Mix.h:35
AudioGraph::Source & downstream
Definition: Mix.h:163
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:54