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 "AudioGraphSource.h"
17#include "MixerOptions.h"
18#include "SampleFormat.h"
19#include <optional>
20
21#include "DownmixStage.h"
22
23class sampleCount;
24class BoundedEnvelope;
25class EffectStage;
26class MixerSource;
27class TrackList;
29
30class MIXER_API Mixer final
31{
32public:
37 using Stages = std::vector<MixerOptions::StageSpecification>;
38
39 struct Input {
41 std::shared_ptr<const WideSampleSequence> pSequence = {},
42 Stages stages = {}
43 ) : pSequence{ move(pSequence) }, stages{ move(stages) }
44 {}
45
46 std::shared_ptr<const WideSampleSequence> pSequence;
48 };
49 using Inputs = std::vector<Input>;
50
52
53 //
54 // Constructor / Destructor
55 //
56
63 Mixer(
64 Inputs inputs, std::optional<Stages> masterEffects, bool mayThrow,
65 const WarpOptions& warpOptions, double startTime, double stopTime,
66 unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
67 double outRate, sampleFormat outFormat, bool highQuality = true,
69 MixerSpec* mixerSpec = nullptr,
70 ApplyVolume applyVolume = ApplyVolume::MapChannels);
71
72 Mixer(const Mixer&) = delete;
73 Mixer(Mixer&&) noexcept = delete;
74 Mixer &operator=(const Mixer&) = delete;
75 Mixer &operator=(Mixer&&) noexcept = delete;
76
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 std::unique_ptr<EffectStage>& RegisterEffectStage(
126 AudioGraph::Source& upstream, size_t numChannels,
127 const MixerOptions::StageSpecification& stage, double outRate);
128
129 // Input
130 const unsigned mNumChannels;
132 const std::optional<Stages> mMasterEffects;
133
134 // Transformations
135 const size_t mBufferSize;
136
137 std::pair<bool, sampleFormat>
138 NeedsDither(bool needsDither, double rate) const;
139
140 private:
141
142 // Output
144 const bool mHighQuality; // dithering
145 const sampleFormat mFormat; // output format also influences dithering
146 const bool mInterleaved;
147
148 // INPUT
151 bool mHasMixerSpec{false};
152
153 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
154
155 // BUFFERS
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
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 std::unique_ptr<AudioGraph::Source> mDownmixStage;
170 std::unique_ptr<AudioGraph::Source> mMasterDownmixStage;
171 AudioGraph::Source* mDownstream{};
172};
173#endif
constexpr int BufferSize
static const AttachedProjectObjects::RegisteredFactory masterEffects
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:31
std::unique_ptr< AudioGraph::Source > mDownmixStage
Definition: Mix.h:169
std::vector< EffectSettings > mSettings
Definition: Mix.h:166
const std::vector< SampleBuffer > mBuffer
Definition: Mix.h:163
std::vector< Input > Inputs
Definition: Mix.h:49
std::vector< std::unique_ptr< EffectStage > > mStages
Definition: Mix.h:168
const sampleFormat mFormat
Definition: Mix.h:145
Inputs mInputs
Definition: Mix.h:131
AudioGraph::Buffers mTemp
Definition: Mix.h:160
const ApplyVolume mApplyVolume
Definition: Mix.h:143
const unsigned mNumChannels
Definition: Mix.h:130
sampleFormat mEffectiveFormat
Definition: Mix.h:149
std::unique_ptr< AudioGraph::Source > mMasterDownmixStage
Definition: Mix.h:170
std::vector< MixerOptions::StageSpecification > Stages
Definition: Mix.h:37
const std::optional< Stages > mMasterEffects
Definition: Mix.h:132
const bool mInterleaved
Definition: Mix.h:146
const size_t mBufferSize
Definition: Mix.h:135
bool mNeedsDither
Definition: Mix.h:150
Mixer(const Mixer &)=delete
std::vector< AudioGraph::Buffers > mStageBuffers
Definition: Mix.h:167
const bool mHighQuality
Definition: Mix.h:144
std::vector< MixerSource > mSources
Definition: Mix.h:165
size_t Process()
Definition: Mix.h:98
Mixer(Mixer &&) noexcept=delete
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: Mix.h:153
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:47
Input(std::shared_ptr< const WideSampleSequence > pSequence={}, Stages stages={})
Definition: Mix.h:40
std::shared_ptr< const WideSampleSequence > pSequence
Definition: Mix.h:46
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56