Audacity 3.2.0
MixerSource.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file MixerSource.h
6 @brief Fetches from tracks, applies envelopes, warps time, and resamples
7
8 Dominic Mazzoni
9 Markus Meyer
10
11 Paul Licameli split from Mix.h
12
13***********************************************************************/
14#ifndef __AUDACITY_MIXER_SOURCE__
15#define __AUDACITY_MIXER_SOURCE__
16
17#include "AudioGraphSource.h"
18#include "MixerOptions.h"
19
20class Resample;
22
25
30class MixerSource final : public AudioGraph::Source {
31public:
34
38 MixerSource(const SampleTrack &leader, size_t bufferSize,
39 double rate, const MixerOptions::Warp &options, bool highQuality,
40 bool mayThrow, std::shared_ptr<TimesAndSpeed> pTimesAndSpeed,
42 const ArrayOf<bool> *pMap
43 );
47
48 unsigned Channels() const { return mnChannels; }
49 const SampleTrack *GetChannel(unsigned iChannel) const;
50 const bool *MixerSpec(unsigned iChannel) const;
51
52 bool AcceptsBuffers(const Buffers &buffers) const override;
53 bool AcceptsBlockSize(size_t blockSize) const override;
54 std::optional<size_t> Acquire(Buffers &data, size_t bound) override;
55 sampleCount Remaining() const override;
56 bool Release() override;
58 bool Terminates() const override;
59 void Reposition(double time, bool skipping);
60
62
63private:
64 void MakeResamplers();
65
69 static constexpr size_t sProcessLen = 1024;
70
73
76 static constexpr size_t sQueueMaxLen = 65536;
77
81 size_t MixSameRate(unsigned iChannel, size_t maxOut, float &floatBuffer);
82
86 size_t MixVariableRates(
87 unsigned iChannel, size_t maxOut, float &floatBuffer);
88
92 void ZeroFill(size_t produced, size_t max, float &floatBuffer);
93
94 const std::shared_ptr<const SampleTrack> mpLeader;
95 size_t i;
96
97 const size_t mnChannels;
98 const double mRate; // may require resampling
99
101 const BoundedEnvelope *const mEnvelope; // for time warp which also resamples
102 const bool mMayThrow;
103
104 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
105
107 std::vector<SampleTrackCache> mInputTrack;
108
110
113 std::vector<sampleCount> mSamplePos;
114
116 std::vector<std::vector<float>> mSampleQueue;
117
119 std::vector<int> mQueueStart;
120
122 std::vector<int> mQueueLen;
123
125 std::vector<std::unique_ptr<Resample>> mResample;
126
128 std::vector<double> mEnvValues;
129
132 const ArrayOf<bool> *const mpMap;
133
135 unsigned mMaxChannels{};
137};
138#endif
Upstream producer of sample streams, taking Buffers as external context.
AudioGraph::Buffers Buffers
std::vector< double > mEnvValues
Gain envelopes are applied to input before other transformations.
Definition: MixerSource.h:128
unsigned Channels() const
Definition: MixerSource.h:48
const ResampleParameters mResampleParameters
Definition: MixerSource.h:124
size_t MixVariableRates(unsigned iChannel, size_t maxOut, float &floatBuffer)
Definition: MixerSource.cpp:69
const BoundedEnvelope *const mEnvelope
Resampling, as needed, after gain envelope.
Definition: MixerSource.h:101
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: MixerSource.h:104
std::vector< std::vector< float > > mSampleQueue
First intermediate buffer when resampling is needed.
Definition: MixerSource.h:116
size_t i
Definition: MixerSource.h:95
sampleCount Remaining() const override
Result includes any amount Acquired and not yet Released.
MixerSource & operator=(MixerSource &&)=delete
MixerSource(const SampleTrack &leader, size_t bufferSize, double rate, const MixerOptions::Warp &options, bool highQuality, bool mayThrow, std::shared_ptr< TimesAndSpeed > pTimesAndSpeed, const ArrayOf< bool > *pMap)
const SampleTrack * GetChannel(unsigned iChannel) const
static constexpr size_t sQueueMaxLen
Definition: MixerSource.h:76
bool AcceptsBlockSize(size_t blockSize) const override
std::vector< sampleCount > mSamplePos
Fetch position for source.
Definition: MixerSource.h:113
std::vector< SampleTrackCache > mInputTrack
SampleTrackCaches are the source of data.
Definition: MixerSource.h:107
bool AcceptsBuffers(const Buffers &buffers) const override
static constexpr size_t sProcessLen
Definition: MixerSource.h:69
bool Terminates() const override
const ArrayOf< bool > *const mpMap
Definition: MixerSource.h:132
bool VariableRates() const
Definition: MixerSource.h:61
const bool mMayThrow
Definition: MixerSource.h:102
bool Release() override
Caller is done examining last Acquire()d positions.
size_t mLastProduced
Definition: MixerSource.h:136
std::vector< std::unique_ptr< Resample > > mResample
Definition: MixerSource.h:125
std::vector< int > mQueueLen
For each queue, the number of available samples after the queue start.
Definition: MixerSource.h:122
std::vector< int > mQueueStart
Position in each queue of the start of the next block to resample.
Definition: MixerSource.h:119
MixerSource(MixerSource &&)=default
void Reposition(double time, bool skipping)
const double mRate
Definition: MixerSource.h:98
unsigned mMaxChannels
Remember how many channels were passed to Acquire()
Definition: MixerSource.h:135
const size_t mnChannels
Definition: MixerSource.h:97
void ZeroFill(size_t produced, size_t max, float &floatBuffer)
const bool * MixerSpec(unsigned iChannel) const
std::optional< size_t > Acquire(Buffers &data, size_t bound) override
Occupy vacant space in Buffers with some data.
void MakeResamplers()
Definition: MixerSource.cpp:41
size_t MixSameRate(unsigned iChannel, size_t maxOut, float &floatBuffer)
const std::shared_ptr< const SampleTrack > mpLeader
Definition: MixerSource.h:94
Interface to libsoxr.
Definition: Resample.h:27
A short-lived object, during whose lifetime, the contents of the WaveTrack are assumed not to change.
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:54