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;
21class EffectStage;
22namespace AudioGraph{ class Source; }
23class MixerSource;
24class TrackList;
26
27class MIXER_API Mixer {
28 public:
33 using Stages = std::vector<MixerOptions::StageSpecification>;
34
35 struct Input {
37 std::shared_ptr<const WideSampleSequence> pSequence = {},
38 Stages stages = {}
39 ) : pSequence{ move(pSequence) }, stages{ move(stages) }
40 {}
41
42 std::shared_ptr<const WideSampleSequence> pSequence;
44 };
45 using Inputs = std::vector<Input>;
46
47 enum class ApplyGain
48 {
49 Discard,//< No source gain is applied
50 MapChannels, //< Apply gains per source's channel
51 Mixdown, //< Average gains from all channels in the source, numOutChannels should be 1
52 };
53
54 //
55 // Constructor / Destructor
56 //
57
64 Mixer(Inputs inputs, bool mayThrow,
65 const WarpOptions &warpOptions,
66 double startTime, double stopTime,
67 unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
68 double outRate, sampleFormat outFormat,
69 bool highQuality = true,
71 MixerSpec *mixerSpec = nullptr,
72 ApplyGain applyGain = ApplyGain::MapChannels);
73
74 Mixer(const Mixer&) = delete;
75 Mixer &operator=(const Mixer&) = delete;
76
77 virtual ~ Mixer();
78
79 size_t BufferSize() const { return mBufferSize; }
80
81 //
82 // Processing
83 //
84
87
93 size_t Process(size_t maxSamples);
94
98 size_t Process() { return Process(BufferSize()); }
99
101 void Reposition(double t, bool bSkipping = false);
102
104 void SetTimesAndSpeed(
105 double t0, double t1, double speed, bool bSkipping = false);
106 void SetSpeedForKeyboardScrubbing(double speed, double startTime);
107
109
110 double MixGetCurrentTime();
111
113 constSamplePtr GetBuffer();
114
116 constSamplePtr GetBuffer(int channel);
117
119 sampleFormat EffectiveFormat() const;
120
121 private:
122
123 void Clear();
124
125 private:
126
127 // Input
128 const unsigned mNumChannels;
130
131 // Transformations
132 const size_t mBufferSize;
133
134 std::pair<bool, sampleFormat>
135 NeedsDither(bool needsDither, double rate) const;
136
137 private:
138
139 // Output
141 const bool mHighQuality; // dithering
142 const sampleFormat mFormat; // output format also influences dithering
143 const bool mInterleaved;
144
145 // INPUT
148 bool mHasMixerSpec{false};
149
150 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
151
152 // BUFFERS
153
154 // Resample into these buffers, or produce directly when not resampling
156
157 // Each channel's data is transformed, including application of
158 // gains and pans, and then (maybe many-to-one) mixer specifications
159 // determine where in mTemp it is accumulated
160 std::vector<std::vector<float>> mTemp;
161
162 // Final result applies dithering and interleaving
163 const std::vector<SampleBuffer> mBuffer;
164
165 std::vector<MixerSource> mSources;
166 std::vector<EffectSettings> mSettings;
167 std::vector<AudioGraph::Buffers> mStageBuffers;
168 std::vector<std::unique_ptr<EffectStage>> mStages;
169
171 std::vector<Source> mDecoratedSources;
172};
173#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:58
Accumulates (non-interleaved) data during effect processing.
Upstream producer of sample streams, taking Buffers as external context.
Decorates a source with a non-timewarping effect, which may have latency.
Definition: EffectStage.h:26
Functions for doing the mixdown of the tracks.
Definition: Mix.h:27
AudioGraph::Buffers mFloatBuffers
Definition: Mix.h:155
ApplyGain
Definition: Mix.h:48
const ApplyGain mApplyGain
Definition: Mix.h:140
std::vector< EffectSettings > mSettings
Definition: Mix.h:166
const std::vector< SampleBuffer > mBuffer
Definition: Mix.h:163
std::vector< Input > Inputs
Definition: Mix.h:45
std::vector< std::unique_ptr< EffectStage > > mStages
Definition: Mix.h:168
std::vector< Source > mDecoratedSources
Definition: Mix.h:171
const sampleFormat mFormat
Definition: Mix.h:142
Inputs mInputs
Definition: Mix.h:129
std::vector< std::vector< float > > mTemp
Definition: Mix.h:160
const unsigned mNumChannels
Definition: Mix.h:128
sampleFormat mEffectiveFormat
Definition: Mix.h:146
std::vector< MixerOptions::StageSpecification > Stages
Definition: Mix.h:33
const bool mInterleaved
Definition: Mix.h:143
const size_t mBufferSize
Definition: Mix.h:132
bool mNeedsDither
Definition: Mix.h:147
Mixer(const Mixer &)=delete
std::vector< AudioGraph::Buffers > mStageBuffers
Definition: Mix.h:167
const bool mHighQuality
Definition: Mix.h:141
std::vector< MixerSource > mSources
Definition: Mix.h:165
size_t Process()
Definition: Mix.h:98
size_t BufferSize() const
Definition: Mix.h:79
Mixer & operator=(const Mixer &)=delete
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: Mix.h:150
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:850
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
Stages stages
Definition: Mix.h:43
Input(std::shared_ptr< const WideSampleSequence > pSequence={}, Stages stages={})
Definition: Mix.h:36
std::shared_ptr< const WideSampleSequence > pSequence
Definition: Mix.h:42
AudioGraph::Source & downstream
Definition: Mix.h:170
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56