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 //
48 // Constructor / Destructor
49 //
50
57 Mixer(Inputs inputs, bool mayThrow,
58 const WarpOptions &warpOptions,
59 double startTime, double stopTime,
60 unsigned numOutChannels, size_t outBufferSize, bool outInterleaved,
61 double outRate, sampleFormat outFormat,
62 bool highQuality = true,
64 MixerSpec *mixerSpec = nullptr,
65 bool applytTrackGains = true);
66
67 Mixer(const Mixer&) = delete;
68 Mixer &operator=(const Mixer&) = delete;
69
70 virtual ~ Mixer();
71
72 size_t BufferSize() const { return mBufferSize; }
73
74 //
75 // Processing
76 //
77
80
86 size_t Process(size_t maxSamples);
87
91 size_t Process() { return Process(BufferSize()); }
92
94 void Reposition(double t, bool bSkipping = false);
95
97 void SetTimesAndSpeed(
98 double t0, double t1, double speed, bool bSkipping = false);
99 void SetSpeedForKeyboardScrubbing(double speed, double startTime);
100
102
103 double MixGetCurrentTime();
104
106 constSamplePtr GetBuffer();
107
109 constSamplePtr GetBuffer(int channel);
110
112 sampleFormat EffectiveFormat() const;
113
114 private:
115
116 void Clear();
117
118 private:
119
120 // Input
121 const unsigned mNumChannels;
123
124 // Transformations
125 const size_t mBufferSize;
126
127 std::pair<bool, sampleFormat>
128 NeedsDither(bool needsDither, double rate) const;
129
130 private:
131
132 // Output
134 const bool mHighQuality; // dithering
135 const sampleFormat mFormat; // output format also influences dithering
136 const bool mInterleaved;
137
138 // INPUT
141
142 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
143
144 // BUFFERS
145
146 // Resample into these buffers, or produce directly when not resampling
148
149 // Each channel's data is transformed, including application of
150 // gains and pans, and then (maybe many-to-one) mixer specifications
151 // determine where in mTemp it is accumulated
152 std::vector<std::vector<float>> mTemp;
153
154 // Final result applies dithering and interleaving
155 const std::vector<SampleBuffer> mBuffer;
156
157 std::vector<MixerSource> mSources;
158 std::vector<EffectSettings> mSettings;
159 std::vector<AudioGraph::Buffers> mStageBuffers;
160 std::vector<std::unique_ptr<EffectStage>> mStages;
161
163 std::vector<Source> mDecoratedSources;
164};
165#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:147
std::vector< EffectSettings > mSettings
Definition: Mix.h:158
const std::vector< SampleBuffer > mBuffer
Definition: Mix.h:155
std::vector< Input > Inputs
Definition: Mix.h:45
std::vector< std::unique_ptr< EffectStage > > mStages
Definition: Mix.h:160
std::vector< Source > mDecoratedSources
Definition: Mix.h:163
const bool mApplyTrackGains
Definition: Mix.h:133
const sampleFormat mFormat
Definition: Mix.h:135
Inputs mInputs
Definition: Mix.h:122
std::vector< std::vector< float > > mTemp
Definition: Mix.h:152
const unsigned mNumChannels
Definition: Mix.h:121
sampleFormat mEffectiveFormat
Definition: Mix.h:139
std::vector< MixerOptions::StageSpecification > Stages
Definition: Mix.h:33
const bool mInterleaved
Definition: Mix.h:136
const size_t mBufferSize
Definition: Mix.h:125
bool mNeedsDither
Definition: Mix.h:140
Mixer(const Mixer &)=delete
std::vector< AudioGraph::Buffers > mStageBuffers
Definition: Mix.h:159
const bool mHighQuality
Definition: Mix.h:134
std::vector< MixerSource > mSources
Definition: Mix.h:157
size_t Process()
Definition: Mix.h:91
size_t BufferSize() const
Definition: Mix.h:72
Mixer & operator=(const Mixer &)=delete
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: Mix.h:142
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:975
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:162
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56