11#ifndef __AUDACITY_REALTIME_EFFECT_MANAGER__
12#define __AUDACITY_REALTIME_EFFECT_MANAGER__
19#include <unordered_map>
31 class InitializationScope;
32 class ProcessingScope;
57 using Latency = std::chrono::microseconds;
68 bool IsActive() const noexcept;
112 std::optional<
size_t> FindState(
116 bool GetSuspended()
const
117 {
return mSuspended.load(std::memory_order_relaxed); }
127 { mSuspended.store(value, std::memory_order_relaxed); }
132 std::shared_ptr<RealtimeEffectState>
139 unsigned numPlaybackChannels,
double sampleRate);
145 void Finalize() noexcept;
149 void ProcessStart(
bool suspended);
152 size_t Process(
bool suspended,
154 float *const *buffers,
float *const *scratch,
float *dummy,
155 unsigned nBuffers,
size_t numSamples);
156 void ProcessEnd(
bool suspended) noexcept;
167 template<typename StateVisitor>
177 template<
typename StateVisitor>
185 template<
typename StateVisitor>
192 for (
auto group : mGroups)
199 std::atomic<bool> mSuspended{
true };
201 bool mActive{
false };
207 std::unordered_map<const ChannelGroup *, double>
mRates;
216 std::weak_ptr<AudacityProject> wProject,
double sampleRate,
217 unsigned numPlaybackChannels
222 if (
const auto pProject =
mwProject.lock())
240 unsigned chans,
float rate)
244 .
AddGroup(*
this, group, chans, rate);
260 std::weak_ptr<AudacityProject> wProject)
276 float *
const *buffers,
277 float *
const *scratch,
283 if (
const auto pProject =
mwProject.lock())
287 nBuffers, numSamples);
Utility ClientData::Site to register hooks into a host class that attach client data.
Generalized interface for discovery of plug-ins for one protocol.
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Performs effect computation.
An object that sends messages to an open-ended list of subscribed callbacks.
void Visit(const StateVisitor &func)
Apply the function to all states sequentially.
static RealtimeEffectList & Get(AudacityProject &project)
AudacityProject & mProject
void Initialize(RealtimeEffects::InitializationScope &scope, unsigned numPlaybackChannels, double sampleRate)
Main thread begins to define a set of groups for playback.
void VisitAll(const StateVisitor &func)
Visit the per-project states first, then all groups from AddGroup.
void SetSuspended(bool value)
To be called only from main thread.
static RealtimeEffectManager & Get(AudacityProject &project)
size_t Process(bool suspended, const ChannelGroup *group, float *const *buffers, float *const *scratch, float *dummy, unsigned nBuffers, size_t numSamples)
void ProcessStart(bool suspended)
std::unordered_map< const ChannelGroup *, double > mRates
void Finalize() noexcept
Main thread cleans up after playback.
void AddGroup(RealtimeEffects::InitializationScope &scope, const ChannelGroup &group, unsigned chans, float rate)
void ProcessEnd(bool suspended) noexcept
std::chrono::microseconds Latency
std::vector< const ChannelGroup * > mGroups
all are non-null
void VisitGroup(const ChannelGroup *group, const StateVisitor &func)
Brackets processing setup and cleanup in the main thread.
void AddGroup(const ChannelGroup &group, unsigned chans, float rate)
InitializationScope(std::weak_ptr< AudacityProject > wProject, double sampleRate, unsigned numPlaybackChannels)
InitializationScope(InitializationScope &&other)=default
std::vector< std::shared_ptr< EffectInstance > > mInstances
std::weak_ptr< AudacityProject > mwProject
unsigned mNumPlaybackChannels
InitializationScope & operator=(InitializationScope &&other)=default
Brackets one block of processing in one thread.
ProcessingScope & operator=(ProcessingScope &&other)=default
std::weak_ptr< AudacityProject > mwProject
size_t Process(const ChannelGroup *group, float *const *buffers, float *const *scratch, float *dummy, unsigned nBuffers, size_t numSamples)
ProcessingScope(ProcessingScope &&other)=default
ProcessingScope(InitializationScope &, std::weak_ptr< AudacityProject > wProject)
Require a prior InializationScope to ensure correct nesting.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
constexpr auto sampleRate
static CommandContext::TargetFactory::SubstituteInUnique< InteractiveOutputTargets > scope
A convenient default parameter for class template Site.
Posted when effect is being added or removed to/from channel group or project.
ChannelGroup * group
null, if changes happened in the project scope