Audacity 3.2.0
EffectStage.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file EffectStage.h
6 @brief decorator of a Sink with a non-time-warping effect
7
8 Dominic Mazzoni
9 Vaughan Johnson
10
11 Paul Licameli split from Effect.h
12
13**********************************************************************/
14
15#ifndef __AUDACITY_EFFECT_STAGE__
16#define __AUDACITY_EFFECT_STAGE__
17
18#include "AudioGraphSource.h" // to inherit
19#include "EffectInterface.h"
20#include "SampleCount.h"
21#include <functional>
22
24
26class MIXER_API EffectStage final : public AudioGraph::Source {
27 // To force usage of Create() instead
28 struct CreateToken {};
29public:
30 using Factory = std::function<std::shared_ptr<EffectInstance>()>;
31
33
45 CreateToken, int channel, int nInputChannels, Source& upstream,
46 Buffers& inBuffers, const Factory& factory, EffectSettings& settings,
47 double sampleRate, std::optional<sampleCount> genLength);
48
50 static std::unique_ptr<EffectStage> Create(
51 int channel, int nInputChannels, Source& upstream, Buffers& inBuffers,
53 std::optional<sampleCount> genLength);
54
55 EffectStage(const EffectStage&) = delete;
56 EffectStage &operator =(const EffectStage &) = delete;
58 ~EffectStage() override;
59
63 bool AcceptsBuffers(const Buffers &buffers) const override;
65 bool AcceptsBlockSize(size_t size) const override;
66
67 std::optional<size_t> Acquire(Buffers &data, size_t bound) override;
68 sampleCount Remaining() const override;
69 bool Release() override;
70
71private:
73 { return std::max<sampleCount>(0, mDelayRemaining); }
74
76
82 bool Process(EffectInstance &instance, size_t channel,
83 const Buffers &data, size_t curBlockSize, size_t outBufferOffset) const;
84
85 [[nodiscard]] std::optional<size_t> FetchProcessAndAdvance(
86 Buffers &data, size_t bound, bool doZeros, size_t outBufferOffset = 0);
87
88 Source &mUpstream;
91 const std::vector<std::shared_ptr<EffectInstance>> mInstances;
93 const double mSampleRate;
94 const bool mIsProcessor;
95
97 size_t mLastProduced{};
98 size_t mLastZeroes{};
99 bool mLatencyDone{ false };
100 bool mCleared{ false };
101};
102
103/*
104 @param channel selects one channel if non-negative; else all channels
105 @param[out] map terminated with ChannelNameEOL
106 @return 1 if `channel >= 0`, else the number of channels
107
108 @pre `channel < nInputChannels`
109 */
110MIXER_API
111unsigned MakeChannelMap(
112 int nInputChannels, int channel,
113 // TODO: more-than-two-channels
114 ChannelName map[3]);
115
116#endif
static RegisteredToolbarFactory factory
ChannelName
MIXER_API unsigned MakeChannelMap(int nInputChannels, int channel, ChannelName map[3])
static Settings & settings()
Definition: TrackInfo.cpp:51
Accumulates (non-interleaved) data during effect processing.
Upstream producer of sample streams, taking Buffers as external context.
virtual sampleCount Remaining() const =0
Result includes any amount Acquired and not yet Released.
virtual bool AcceptsBlockSize(size_t blockSize) const =0
virtual bool AcceptsBuffers(const Buffers &buffers) const =0
virtual std::optional< size_t > Acquire(Buffers &data, size_t bound)=0
Occupy vacant space in Buffers with some data.
virtual bool Release()=0
Caller is done examining last Acquire()d positions.
Performs effect computation.
Decorates a source with a non-timewarping effect, which may have latency.
Definition: EffectStage.h:26
Source & mUpstream
Definition: EffectStage.h:88
const std::vector< std::shared_ptr< EffectInstance > > mInstances
Definition: EffectStage.h:91
const double mSampleRate
Definition: EffectStage.h:93
sampleCount mDelayRemaining
Definition: EffectStage.h:96
EffectStage(const EffectStage &)=delete
std::function< std::shared_ptr< EffectInstance >()> Factory
Definition: EffectStage.h:30
Buffers & mInBuffers
Definition: EffectStage.h:90
sampleCount DelayRemaining() const
Definition: EffectStage.h:72
const bool mIsProcessor
Definition: EffectStage.h:94
EffectSettings & mSettings
Definition: EffectStage.h:92
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
Externalized state of a plug-in.