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
23class Track;
24
25namespace AudioGraph {
26
28class AUDIO_GRAPH_API EffectStage final : public Source {
29 // To force usage of Create() instead
30 struct CreateToken {};
31public:
32 using Factory = std::function<std::shared_ptr<EffectInstanceEx>()>;
33
35
43 EffectStage(CreateToken, bool multi, Source &upstream, Buffers &inBuffers,
45 double sampleRate,
46 std::optional<sampleCount> genLength, const Track &track);
47
49 static std::unique_ptr<EffectStage> Create(bool multi,
50 Source &upstream, Buffers &inBuffers,
52 double sampleRate,
53 std::optional<sampleCount> genLength, const Track &track);
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(EffectInstanceEx &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
91 const std::vector<std::shared_ptr<EffectInstanceEx>> 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 multichannel true only when effect does not process each channel
105 of track independently
106 @param[out] map terminated with ChannelNameEOL
107 */
108AUDIO_GRAPH_API
109unsigned MakeChannelMap(const Track &track, bool multichannel,
110 // TODO: more-than-two-channels
111 ChannelName map[3]);
112}
113#endif
ChannelName
static Settings & settings()
Definition: TrackInfo.cpp:87
Accumulates (non-interleaved) data during effect processing.
Decorates a source with a non-timewarping effect, which may have latency.
Definition: EffectStage.h:28
const std::vector< std::shared_ptr< EffectInstanceEx > > mInstances
Definition: EffectStage.h:91
sampleCount DelayRemaining() const
Definition: EffectStage.h:72
const double mSampleRate
Definition: EffectStage.h:93
EffectStage(const EffectStage &)=delete
std::function< std::shared_ptr< EffectInstanceEx >()> Factory
Definition: EffectStage.h:32
sampleCount mDelayRemaining
Definition: EffectStage.h:96
EffectSettings & mSettings
Definition: EffectStage.h:92
Upstream producer of sample streams, taking Buffers as external context.
Performs effect computation.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
AUDIO_GRAPH_API unsigned MakeChannelMap(const Track &track, bool multichannel, ChannelName map[3])
void Release(wxWindow *handler)
static RegisteredToolbarFactory factory
Externalized state of a plug-in.