11#ifndef __AUDACITY_REALTIME_EFFECT_MANAGER__
12#define __AUDACITY_REALTIME_EFFECT_MANAGER__
19#include <unordered_map>
31 class InitializationScope;
32 class ProcessingScope;
53 using Latency = std::chrono::microseconds;
64 bool IsActive() const noexcept;
108 std::optional<
size_t> FindState(
112 bool GetSuspended()
const
113 {
return mSuspended.load(std::memory_order_relaxed); }
123 { mSuspended.store(value, std::memory_order_relaxed); }
128 std::shared_ptr<RealtimeEffectState>
141 void Finalize() noexcept;
153 void ProcessStart(
bool suspended);
155 size_t Process(
bool suspended,
157 float *
const *buffers,
float *
const *scratch,
float *dummy,
158 unsigned nBuffers,
size_t numSamples);
159 void ProcessEnd(
bool suspended)
noexcept;
170 template<
typename StateVisitor>
180 template<
typename StateVisitor>
193 template<
typename StateVisitor>
200 for (
auto group : mGroups)
207 std::atomic<bool> mSuspended{
true };
209 bool mActive{
false };
215 std::unordered_map<const ChannelGroup *, double>
mRates;
224 std::weak_ptr<AudacityProject> wProject,
double sampleRate,
225 unsigned numPlaybackChannels
242 unsigned chans,
float rate)
246 .
AddGroup(*
this, group, chans, rate);
270 std::weak_ptr<AudacityProject> wProject)
286 float *
const *buffers,
287 float *
const *scratch,
296 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.
static const AttachedProjectObjects::RegisteredFactory manager
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 VisitGroup(ChannelGroup &group, const StateVisitor &func)
Visit the per-project states first, then states for group.
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)
void Initialize(RealtimeEffects::InitializationScope &scope, double sampleRate)
Main thread begins to define a set of groups for playback.
void ProcessStart(bool suspended)
std::unordered_map< const ChannelGroup *, double > mRates
void Finalize() noexcept
Main thread cleans up after playback.
size_t Process(bool suspended, const ChannelGroup &group, float *const *buffers, float *const *scratch, float *dummy, unsigned nBuffers, size_t numSamples)
RealtimeEffectManager & operator=(const RealtimeEffectManager &)=delete
void AddGroup(RealtimeEffects::InitializationScope &scope, const ChannelGroup &group, unsigned chans, float rate)
void ProcessEnd(bool suspended) noexcept
std::chrono::microseconds Latency
void VisitGroup(const ChannelGroup &group, const StateVisitor &func)
std::vector< const ChannelGroup * > mGroups
all are non-null
RealtimeEffectManager(const RealtimeEffectManager &)=delete
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.
size_t Process(const ChannelGroup &group, float *const *buffers, float *const *scratch, float *dummy, unsigned nBuffers, size_t numSamples)
ProcessingScope & operator=(ProcessingScope &&other)=default
std::weak_ptr< AudacityProject > mwProject
RealtimeEffectManager::AllListsLock mLocks
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