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;
109 std::optional<
size_t> FindState(
113 bool GetSuspended()
const
114 {
return mSuspended.load(std::memory_order_relaxed); }
124 { mSuspended.store(value, std::memory_order_relaxed); }
132 std::shared_ptr<RealtimeEffectState>
148 void Finalize() noexcept;
160 void ProcessStart(
bool suspended);
162 size_t Process(
bool suspended,
164 float *
const *buffers,
float *
const *scratch,
float *dummy,
165 unsigned nBuffers,
size_t numSamples);
166 void ProcessEnd(
bool suspended)
noexcept;
177 template<
typename StateVisitor>
187 template<
typename StateVisitor>
200 template<
typename StateVisitor>
207 for (
auto group : mGroups)
214 std::atomic<bool> mSuspended{
true };
216 bool mActive{
false };
222 std::unordered_map<const ChannelGroup *, double>
mRates;
231 std::weak_ptr<AudacityProject> wProject,
double sampleRate,
232 unsigned numPlaybackChannels
252 unsigned chans,
float rate)
256 .
AddGroup(*
this, group, chans, rate);
280 std::weak_ptr<AudacityProject> wProject)
296 float *
const *buffers,
297 float *
const *scratch,
306 nBuffers, numSamples);
static AudioUnitEffectsModule::Factory::SubstituteInUnique< AudioUnitEffect > scope
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 leader if not null.
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
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