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
61private:
62 void MakeResamplers();
63
67 static constexpr size_t sProcessLen = 1024;
68
71
74 static constexpr size_t sQueueMaxLen = 65536;
75
79 size_t MixSameRate(unsigned iChannel, size_t maxOut, float &floatBuffer);
80
84 size_t MixVariableRates(
85 unsigned iChannel, size_t maxOut, float &floatBuffer);
86
90 void ZeroFill(size_t produced, size_t max, float &floatBuffer);
91
92 const std::shared_ptr<const SampleTrack> mpLeader;
93 size_t i;
94
95 const size_t mnChannels;
96 const double mRate; // may require resampling
97
99 const BoundedEnvelope *const mEnvelope; // for time warp which also resamples
100 const bool mMayThrow;
101
102 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
103
105 std::vector<SampleTrackCache> mInputTrack;
106
108
111 std::vector<sampleCount> mSamplePos;
112
114 std::vector<std::vector<float>> mSampleQueue;
115
117 std::vector<int> mQueueStart;
118
120 std::vector<int> mQueueLen;
121
123 std::vector<std::unique_ptr<Resample>> mResample;
124
126 std::vector<double> mEnvValues;
127
130 const ArrayOf<bool> *const mpMap;
131
133 unsigned mMaxChannels{};
135};
136#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:126
unsigned Channels() const
Definition: MixerSource.h:48
const ResampleParameters mResampleParameters
Definition: MixerSource.h:122
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:99
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: MixerSource.h:102
std::vector< std::vector< float > > mSampleQueue
First intermediate buffer when resampling is needed.
Definition: MixerSource.h:114
size_t i
Definition: MixerSource.h:93
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:74
bool AcceptsBlockSize(size_t blockSize) const override
std::vector< sampleCount > mSamplePos
Fetch position for source.
Definition: MixerSource.h:111
std::vector< SampleTrackCache > mInputTrack
SampleTrackCaches are the source of data.
Definition: MixerSource.h:105
bool AcceptsBuffers(const Buffers &buffers) const override
static constexpr size_t sProcessLen
Definition: MixerSource.h:67
bool Terminates() const override
const ArrayOf< bool > *const mpMap
Definition: MixerSource.h:130
const bool mMayThrow
Definition: MixerSource.h:100
bool Release() override
Caller is done examining last Acquire()d positions.
size_t mLastProduced
Definition: MixerSource.h:134
std::vector< std::unique_ptr< Resample > > mResample
Definition: MixerSource.h:123
std::vector< int > mQueueLen
For each queue, the number of available samples after the queue start.
Definition: MixerSource.h:120
std::vector< int > mQueueStart
Position in each queue of the start of the next block to resample.
Definition: MixerSource.h:117
MixerSource(MixerSource &&)=default
void Reposition(double time, bool skipping)
const double mRate
Definition: MixerSource.h:96
unsigned mMaxChannels
Remember how many channels were passed to Acquire()
Definition: MixerSource.h:133
const size_t mnChannels
Definition: MixerSource.h:95
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:92
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