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
80
84 size_t Process(size_t maxSamples);
85
89 size_t Process() { return Process(BufferSize()); }
90
93 void Restart();
94
97 void Reposition(double t, bool bSkipping = false);
98
99 // Used in scrubbing and other nonuniform playback policies.
100 void SetTimesAndSpeed(
101 double t0, double t1, double speed, bool bSkipping = false);
102 void SetSpeedForKeyboardScrubbing(double speed, double startTime);
103
106 double MixGetCurrentTime();
107
109 constSamplePtr GetBuffer();
110
112 constSamplePtr GetBuffer(int channel);
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 // Output
129 const bool mHighQuality; // dithering
130 const sampleFormat mFormat; // output format also influences dithering
131 const bool mInterleaved;
132
133 // INPUT
134
135 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
136
137 // BUFFERS
138
139 // Resample into these buffers, or produce directly when not resampling
141
142 // Each channel's data is transformed, including application of
143 // gains and pans, and then (maybe many-to-one) mixer specifications
144 // determine where in mTemp it is accumulated
145 std::vector<std::vector<float>> mTemp;
146
147 // Final result applies dithering and interleaving
148 const std::vector<SampleBuffer> mBuffer;
149
150 std::vector<MixerSource> mSources;
151 std::vector<EffectSettings> mSettings;
152 std::vector<AudioGraph::Buffers> mStageBuffers;
153 std::vector<std::unique_ptr<AudioGraph::EffectStage>> mStages;
154
156 std::vector<Source> mDecoratedSources;
157};
158#endif
constexpr int BufferSize
sampleFormat
Definition: SampleFormat.h:29
const char * constSamplePtr
Definition: SampleFormat.h:50
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:140
std::vector< EffectSettings > mSettings
Definition: Mix.h:151
const std::vector< SampleBuffer > mBuffer
Definition: Mix.h:148
std::vector< Input > Inputs
Definition: Mix.h:43
std::vector< Source > mDecoratedSources
Definition: Mix.h:156
const bool mApplyTrackGains
Definition: Mix.h:128
const sampleFormat mFormat
Definition: Mix.h:130
Inputs mInputs
Definition: Mix.h:122
std::vector< std::unique_ptr< AudioGraph::EffectStage > > mStages
Definition: Mix.h:153
std::vector< std::vector< float > > mTemp
Definition: Mix.h:145
void Restart()
const unsigned mNumChannels
Definition: Mix.h:121
std::vector< MixerOptions::StageSpecification > Stages
Definition: Mix.h:32
const bool mInterleaved
Definition: Mix.h:131
const size_t mBufferSize
Definition: Mix.h:125
Mixer(const Mixer &)=delete
std::vector< AudioGraph::Buffers > mStageBuffers
Definition: Mix.h:152
const bool mHighQuality
Definition: Mix.h:129
std::vector< MixerSource > mSources
Definition: Mix.h:150
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:135
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:1338
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:155
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:54