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#include "SampleCount.h"
20#include <memory>
21
22class Resample;
23class SampleTrack;
25
28
33class MixerSource final : public AudioGraph::Source {
34public:
37
41 MixerSource(const std::shared_ptr<const WideSampleSequence> &seq,
42 size_t bufferSize,
43 double rate, const MixerOptions::Warp &options, bool highQuality,
44 bool mayThrow, std::shared_ptr<TimesAndSpeed> pTimesAndSpeed
45 );
46 MixerSource(MixerSource&&) noexcept = default;
47 ~MixerSource() override;
48
49 unsigned Channels() const { return mnChannels; }
50 const WideSampleSequence &GetSequence() 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
82 size_t MixSameRate(unsigned nChannels, size_t maxOut, float *floatBuffers[]);
83
88 size_t MixVariableRates(
89 unsigned nChannels, size_t maxOut, float *floatBuffers[]);
90
94 void ZeroFill(size_t produced, size_t max, float &floatBuffer);
95
96 const std::shared_ptr<const WideSampleSequence> mpSeq;
97 size_t i;
98
99 const size_t mnChannels;
100 const double mRate; // may require resampling
101
103 const BoundedEnvelope *const mEnvelope; // for time warp which also resamples
104 const bool mMayThrow;
105
106 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
107
109
113
115 std::vector<std::vector<float>> mSampleQueue;
116
119
122
124 std::vector<std::unique_ptr<Resample>> mResample;
125
127 std::vector<double> mEnvValues;
128
130 unsigned mMaxChannels{};
132};
133#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:127
unsigned Channels() const
Definition: MixerSource.h:49
int mQueueStart
Position of the start of the next block to resample.
Definition: MixerSource.h:118
int mQueueLen
The number of available samples after the queue start.
Definition: MixerSource.h:121
const ResampleParameters mResampleParameters
Definition: MixerSource.h:123
const BoundedEnvelope *const mEnvelope
Resampling, as needed, after gain envelope.
Definition: MixerSource.h:103
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: MixerSource.h:106
std::vector< std::vector< float > > mSampleQueue
First intermediate buffer when resampling is needed.
Definition: MixerSource.h:115
MixerSource(const std::shared_ptr< const WideSampleSequence > &seq, size_t bufferSize, double rate, const MixerOptions::Warp &options, bool highQuality, bool mayThrow, std::shared_ptr< TimesAndSpeed > pTimesAndSpeed)
size_t i
Definition: MixerSource.h:97
const std::shared_ptr< const WideSampleSequence > mpSeq
Definition: MixerSource.h:96
sampleCount Remaining() const override
Result includes any amount Acquired and not yet Released.
size_t MixSameRate(unsigned nChannels, size_t maxOut, float *floatBuffers[])
static constexpr size_t sQueueMaxLen
Definition: MixerSource.h:76
bool AcceptsBlockSize(size_t blockSize) const override
bool AcceptsBuffers(const Buffers &buffers) const override
size_t MixVariableRates(unsigned nChannels, size_t maxOut, float *floatBuffers[])
Definition: MixerSource.cpp:68
static constexpr size_t sProcessLen
Definition: MixerSource.h:69
bool Terminates() const override
bool VariableRates() const
Definition: MixerSource.h:61
const bool mMayThrow
Definition: MixerSource.h:104
bool Release() override
Caller is done examining last Acquire()d positions.
size_t mLastProduced
Definition: MixerSource.h:131
std::vector< std::unique_ptr< Resample > > mResample
Definition: MixerSource.h:124
void Reposition(double time, bool skipping)
const double mRate
Definition: MixerSource.h:100
unsigned mMaxChannels
Remember how many channels were passed to Acquire()
Definition: MixerSource.h:130
const size_t mnChannels
Definition: MixerSource.h:99
void ZeroFill(size_t produced, size_t max, float &floatBuffer)
MixerSource(MixerSource &&) noexcept=default
std::optional< size_t > Acquire(Buffers &data, size_t bound) override
Occupy vacant space in Buffers with some data.
void MakeResamplers()
Definition: MixerSource.cpp:40
sampleCount mSamplePos
Fetch position for source.
Definition: MixerSource.h:112
const WideSampleSequence & GetSequence() const
Interface to libsoxr.
Definition: Resample.h:27
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:56