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,
46 const ArrayOf<bool> *pMap
47 );
51
52 unsigned Channels() const { return mnChannels; }
53 const WideSampleSequence &GetSequence() const;
54 const bool *MixerSpec(unsigned iChannel) const;
55
56 bool AcceptsBuffers(const Buffers &buffers) const override;
57 bool AcceptsBlockSize(size_t blockSize) const override;
58 std::optional<size_t> Acquire(Buffers &data, size_t bound) override;
59 sampleCount Remaining() const override;
60 bool Release() override;
62 bool Terminates() const override;
63 void Reposition(double time, bool skipping);
64
66
67private:
68 void MakeResamplers();
69
73 static constexpr size_t sProcessLen = 1024;
74
77
80 static constexpr size_t sQueueMaxLen = 65536;
81
86 size_t MixSameRate(unsigned nChannels, size_t maxOut, float *floatBuffers[]);
87
92 size_t MixVariableRates(
93 unsigned nChannels, size_t maxOut, float *floatBuffers[]);
94
98 void ZeroFill(size_t produced, size_t max, float &floatBuffer);
99
100 const std::shared_ptr<const WideSampleSequence> mpSeq;
101 size_t i;
102
103 const size_t mnChannels;
104 const double mRate; // may require resampling
105
107 const BoundedEnvelope *const mEnvelope; // for time warp which also resamples
108 const bool mMayThrow;
109
110 const std::shared_ptr<TimesAndSpeed> mTimesAndSpeed;
111
113
117
119 std::vector<std::vector<float>> mSampleQueue;
120
123
126
128 std::vector<std::unique_ptr<Resample>> mResample;
129
131 std::vector<double> mEnvValues;
132
135 const ArrayOf<bool> *const mpMap;
136
138 unsigned mMaxChannels{};
140};
141#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:131
unsigned Channels() const
Definition: MixerSource.h:52
int mQueueStart
Position of the start of the next block to resample.
Definition: MixerSource.h:122
int mQueueLen
The number of available samples after the queue start.
Definition: MixerSource.h:125
const ResampleParameters mResampleParameters
Definition: MixerSource.h:127
const BoundedEnvelope *const mEnvelope
Resampling, as needed, after gain envelope.
Definition: MixerSource.h:107
const std::shared_ptr< TimesAndSpeed > mTimesAndSpeed
Definition: MixerSource.h:110
std::vector< std::vector< float > > mSampleQueue
First intermediate buffer when resampling is needed.
Definition: MixerSource.h:119
const std::shared_ptr< const WideSampleSequence > mpSeq
Definition: MixerSource.h:100
sampleCount Remaining() const override
Result includes any amount Acquired and not yet Released.
MixerSource & operator=(MixerSource &&)=delete
size_t MixSameRate(unsigned nChannels, size_t maxOut, float *floatBuffers[])
static constexpr size_t sQueueMaxLen
Definition: MixerSource.h:80
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:73
bool Terminates() const override
const ArrayOf< bool > *const mpMap
Definition: MixerSource.h:135
bool VariableRates() const
Definition: MixerSource.h:65
const bool mMayThrow
Definition: MixerSource.h:108
bool Release() override
Caller is done examining last Acquire()d positions.
size_t mLastProduced
Definition: MixerSource.h:139
std::vector< std::unique_ptr< Resample > > mResample
Definition: MixerSource.h:128
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, const ArrayOf< bool > *pMap)
MixerSource(MixerSource &&)=default
void Reposition(double time, bool skipping)
const double mRate
Definition: MixerSource.h:104
unsigned mMaxChannels
Remember how many channels were passed to Acquire()
Definition: MixerSource.h:138
const size_t mnChannels
Definition: MixerSource.h:103
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:40
sampleCount mSamplePos
Fetch position for source.
Definition: MixerSource.h:116
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