Audacity 3.2.0
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
AudioUnitInstance Class Reference

#include <AudioUnitInstance.h>

Inheritance diagram for AudioUnitInstance:
[legend]
Collaboration diagram for AudioUnitInstance:
[legend]

Public Member Functions

 AudioUnitInstance (const PerTrackEffect &effect, AudioComponent component, Parameters &parameters, const wxString &identifier, unsigned audioIns, unsigned audioOuts, bool useLatency)
 
void EventListener (const AudioUnitEvent *inEvent, AudioUnitParameterValue inParameterValue)
 
std::unique_ptr< MessageMakeMessage () const override
 Called on the main thread, in which the result may be cloned. More...
 
std::unique_ptr< MessageMakeMessage (AudioUnitParameterID id, AudioUnitParameterValue value) const
 
- Public Member Functions inherited from PerTrackEffect::Instance
 Instance (const PerTrackEffect &processor)
 
 ~Instance () override
 
bool Process (EffectSettings &settings) final
 Uses the other virtual functions of this class. More...
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
 
bool ProcessFinalize () noexcept override
 
- Public Member Functions inherited from EffectInstanceEx
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectSettings &settings)=0
 Actually do the effect here. More...
 
 ~EffectInstanceEx () override
 
- Public Member Functions inherited from EffectInstance
virtual ~EffectInstance ()
 
virtual size_t GetBlockSize () const =0
 
virtual size_t SetBlockSize (size_t maxBlockSize)=0
 
virtual unsigned GetAudioInCount () const =0
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const =0
 How many output buffers to allocate at once. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual std::unique_ptr< MessageMakeMessage () const
 Called on the main thread, in which the result may be cloned. More...
 
virtual bool UsesMessages () const noexcept
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual void RealtimePassThrough (size_t group, EffectSettings &settings, const float *const *inBuf, size_t numSamples)
 Called instead of RealtimeProcess when the effect is bypassed. Default implementation does nothing. More...
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t GetTailSize () const
 
virtual SampleCount GetLatency (const EffectSettings &settings, double sampleRate) const
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap)=0
 
virtual bool ProcessFinalize () noexcept=0
 
virtual size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen)=0
 Called for destructive effect computation. More...
 
- Public Member Functions inherited from AudioUnitWrapper
 AudioUnitWrapper (AudioComponent component, Parameters *pParameters)
 
template<typename T >
OSStatus GetFixedSizeProperty (AudioUnitPropertyID inID, T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
 
template<typename T >
OSStatus GetVariableSizeProperty (AudioUnitPropertyID inID, PackedArray::Ptr< T > &pObject, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
 
template<typename T >
OSStatus SetProperty (AudioUnitPropertyID inID, const T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
 
void ForEachParameter (ParameterVisitor visitor) const
 
bool LoadPreset (const EffectDefinitionInterface &effect, const RegistryPath &group, EffectSettings &settings) const
 
bool LoadFactoryPreset (const EffectDefinitionInterface &effect, int id, EffectSettings *pSettings) const
 
std::pair< CF_ptr< CFDataRef >, TranslatableStringMakeBlob (const EffectDefinitionInterface &effect, const AudioUnitEffectSettings &settings, const wxCFStringRef &cfname, bool binary) const
 Obtain dump of the setting state of an AudioUnit instance. More...
 
TranslatableString InterpretBlob (AudioUnitEffectSettings &settings, const wxString &group, const wxMemoryBuffer &buf) const
 Interpret the dump made before by MakeBlob. More...
 
bool FetchSettings (AudioUnitEffectSettings &settings, bool fetchValues, bool fetchPreset=false) const
 May allocate memory, so should be called only in the main thread. More...
 
bool StoreSettings (const EffectDefinitionInterface &effect, const AudioUnitEffectSettings &settings) const
 
bool CreateAudioUnit ()
 
AudioUnit GetAudioUnit () const
 
AudioComponent GetComponent () const
 
const ParametersGetParameters () const
 
bool SetRateAndChannels (double sampleRate, const wxString &identifier)
 

Private Member Functions

size_t InitialBlockSize () const
 
SampleCount GetLatency (const EffectSettings &settings, double sampleRate) const override
 
size_t GetBlockSize () const override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
 
bool ProcessFinalize () noexcept override
 
size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
 Called for destructive effect computation. More...
 
bool RealtimeInitialize (EffectSettings &settings, double sampleRate) override
 
bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize (EffectSettings &settings) noexcept override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool UsesMessages () const noexcept override
 
bool RealtimeProcessStart (MessagePackage &package) override
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inbuf, float *const *outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd (EffectSettings &settings) noexcept override
 settings can be updated to let a dialog change appearance at idle More...
 
OSStatus Render (AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
 
bool BypassEffect (bool bypass)
 

Static Private Member Functions

static OSStatus RenderCallback (void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
 

Private Attributes

bool mRecruited { false }
 Whether the master instance is now allocated to a group number. More...
 
std::vector< std::unique_ptr< AudioUnitInstance > > mSlaves
 
AudioUnitCleanup< AudioUnit, AudioUnitUninitialize > mInitialization
 
AudioTimeStamp mTimeStamp {}
 
PackedArray::Ptr< AudioBufferList > mInputList
 
PackedArray::Ptr< AudioBufferList > mOutputList
 
const wxString & mIdentifier
 
const size_t mBlockSize
 
const bool mUseLatency
 

Additional Inherited Members

- Public Types inherited from EffectInstance
using Message = EffectSettingsAccess::Message
 
using SampleCount = uint64_t
 
- Public Types inherited from AudioUnitWrapper
using Parameters = PackedArray::Ptr< const AudioUnitParameterID >
 
using ParameterVisitor = std::function< bool(const ParameterInfo &pi, AudioUnitParameterID ID) >
 Return value: if true, continue visiting. More...
 
- Static Public Member Functions inherited from AudioUnitWrapper
static AudioUnitEffectSettingsGetSettings (EffectSettings &settings)
 
static const AudioUnitEffectSettingsGetSettings (const EffectSettings &settings)
 
static bool MoveSettingsContents (AudioUnitEffectSettings &&src, AudioUnitEffectSettings &dst, bool merge)
 Copy, then clear the optionals in src. More...
 
- Protected Attributes inherited from PerTrackEffect::Instance
const PerTrackEffectmProcessor
 
- Protected Attributes inherited from AudioUnitWrapper
const AudioComponent mComponent
 
AudioUnitCleanup< AudioUnit, AudioComponentInstanceDispose > mUnit
 
Parameters mOwnParameters
 
ParametersmParameters
 
unsigned mAudioIns { 2 }
 
unsigned mAudioOuts { 2 }
 

Detailed Description

Definition at line 19 of file AudioUnitInstance.h.

Constructor & Destructor Documentation

◆ AudioUnitInstance()

AudioUnitInstance::AudioUnitInstance ( const PerTrackEffect effect,
AudioComponent  component,
Parameters parameters,
const wxString &  identifier,
unsigned  audioIns,
unsigned  audioOuts,
bool  useLatency 
)

Definition at line 58 of file AudioUnitInstance.cpp.

62 : PerTrackEffect::Instance{ effect }
63 , AudioUnitWrapper{ component, &parameters }
64 , mIdentifier{ identifier }
66 , mUseLatency{ useLatency }
67{
68 mAudioIns = audioIns;
69 mAudioOuts = audioOuts;
71}
const size_t mBlockSize
const wxString & mIdentifier
size_t InitialBlockSize() const
Manages and interacts with an AudioUnit, providing operations on audio effects.

References AudioUnitWrapper::CreateAudioUnit(), AudioUnitWrapper::mAudioIns, and AudioUnitWrapper::mAudioOuts.

Here is the call graph for this function:

Member Function Documentation

◆ BypassEffect()

bool AudioUnitInstance::BypassEffect ( bool  bypass)
private

Definition at line 422 of file AudioUnitInstance.cpp.

423{
424 UInt32 value = (bypass ? 1 : 0);
425 if (bypass && AudioUnitReset(mUnit.get(), kAudioUnitScope_Global, 0))
426 return false;
427 return !SetProperty(kAudioUnitProperty_BypassEffect, value);
428}
AudioUnitCleanup< AudioUnit, AudioComponentInstanceDispose > mUnit
OSStatus SetProperty(AudioUnitPropertyID inID, const T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const

References AudioUnitWrapper::mUnit, and AudioUnitWrapper::SetProperty().

Referenced by ProcessInitialize(), RealtimeResume(), and RealtimeSuspend().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EventListener()

void AudioUnitInstance::EventListener ( const AudioUnitEvent *  inEvent,
AudioUnitParameterValue  inParameterValue 
)

Definition at line 388 of file AudioUnitInstance.cpp.

390{
391 // Handle property changes
392 if (inEvent->mEventType == kAudioUnitEvent_PropertyChange) {
393 // Handle latency changes
394 if (inEvent->mArgument.mProperty.mPropertyID ==
395 kAudioUnitProperty_Latency) {
396 // Do what?
397 }
398 return;
399 }
400
401 if (inEvent->mEventType != kAudioUnitEvent_ParameterValueChange)
402 return;
403
404 // Only parameter changes at this point
405 const auto parameterStorer = [inParameterValue,
406 ID = inEvent->mArgument.mParameter.mParameterID
407 ](AudioUnit pUnit){
408 AudioUnitSetParameter(pUnit, ID,
409 kAudioUnitScope_Global, 0, inParameterValue, 0);
410 };
411
412 // Save the parameter change in the instance, so it can be
413 // fetched into Settings, used to initialize any new slave's state
414 // This is like StoreSettings but for just one setting
415 parameterStorer(GetAudioUnit());
416
417 // Propagate the parameter
418 for (auto &worker : mSlaves)
419 parameterStorer(worker->GetAudioUnit());
420}
std::vector< std::unique_ptr< AudioUnitInstance > > mSlaves
AudioUnit GetAudioUnit() const

References AudioUnitWrapper::GetAudioUnit(), and mSlaves.

Referenced by AudioUnitEditor::EventListener().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAudioInCount()

unsigned AudioUnitInstance::GetAudioInCount ( ) const
overrideprivatevirtual

How many input buffers to allocate at once.

If the instance processes channels independently, this can return 1 The result is not necessarily well defined before RealtimeInitialize

Implements EffectInstance.

Definition at line 96 of file AudioUnitInstance.cpp.

97{
98 return mAudioIns;
99}

References AudioUnitWrapper::mAudioIns.

◆ GetAudioOutCount()

unsigned AudioUnitInstance::GetAudioOutCount ( ) const
overrideprivatevirtual

How many output buffers to allocate at once.

The result is not necessarily well defined before RealtimeInitialize

Implements EffectInstance.

Definition at line 101 of file AudioUnitInstance.cpp.

102{
103 return mAudioOuts;
104}

References AudioUnitWrapper::mAudioOuts.

◆ GetBlockSize()

size_t AudioUnitInstance::GetBlockSize ( ) const
overrideprivatevirtual

Implements EffectInstance.

Definition at line 91 of file AudioUnitInstance.cpp.

92{
93 return mBlockSize;
94}

References mBlockSize.

◆ GetLatency()

auto AudioUnitInstance::GetLatency ( const EffectSettings settings,
double  sampleRate 
) const
overrideprivatevirtual

Default implementation returns 0

Reimplemented from EffectInstance.

Definition at line 106 of file AudioUnitInstance.cpp.

108{
109 // Retrieve the latency (can be updated via an event)
110 if (mUseLatency) {
111 Float64 latency = 0.0;
112 if (!GetFixedSizeProperty(kAudioUnitProperty_Latency, latency))
113 return latency * sampleRate;
114 }
115 return 0;
116}
OSStatus GetFixedSizeProperty(AudioUnitPropertyID inID, T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const

References AudioUnitUtils::GetFixedSizeProperty(), and anonymous_namespace{ClipSegmentTest.cpp}::sampleRate.

Here is the call graph for this function:

◆ InitialBlockSize()

size_t AudioUnitInstance::InitialBlockSize ( ) const
private

Definition at line 73 of file AudioUnitInstance.cpp.

74{
75 // Retrieve the desired number of frames per slice
76 UInt32 blockSize{};
78 kAudioUnitProperty_MaximumFramesPerSlice, blockSize))
79 // Call failed? Then supply a default:
80 return 512;
81 else
82 return blockSize;
83}

References AudioUnitWrapper::GetFixedSizeProperty().

Here is the call graph for this function:

◆ MakeMessage() [1/2]

auto AudioUnitInstance::MakeMessage ( ) const
overridevirtual

Called on the main thread, in which the result may be cloned.

Default implementation returns a null

Reimplemented from EffectInstance.

Definition at line 285 of file AudioUnitInstance.cpp.

286{
287 // Like AudioUnitEffect::MakeSettings, except it only allocates map entries
288 // containing nullopt
290 FetchSettings(settings, false);
291 return std::make_unique<AudioUnitMessage>(std::move(settings));
292}
static Settings & settings()
Definition: TrackInfo.cpp:51
Represents a cached copy of the state stored in an AudioUnit, but can outlive the original AudioUnit.
bool FetchSettings(AudioUnitEffectSettings &settings, bool fetchValues, bool fetchPreset=false) const
May allocate memory, so should be called only in the main thread.

References AudioUnitWrapper::FetchSettings(), and settings().

Referenced by AudioUnitEditor::EventListener().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeMessage() [2/2]

auto AudioUnitInstance::MakeMessage ( AudioUnitParameterID  id,
AudioUnitParameterValue  value 
) const

Definition at line 294 of file AudioUnitInstance.cpp.

297{
299 settings.values[id].emplace(wxString{}, value);
300 return std::make_unique<AudioUnitMessage>(std::move(settings));
301}
int id

References id, and settings().

Here is the call graph for this function:

◆ ProcessBlock()

size_t AudioUnitInstance::ProcessBlock ( EffectSettings settings,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)
overrideprivatevirtual

Called for destructive effect computation.

Implements EffectInstance.

Definition at line 188 of file AudioUnitInstance.cpp.

190{
191 // mAudioIns and mAudioOuts don't change after plugin initialization,
192 // so ProcessInitialize() made sufficient allocations
193 assert(Count(mInputList) >= mAudioIns);
194 for (size_t i = 0; i < mAudioIns; ++i)
195 mInputList[i] = { 1, static_cast<UInt32>(sizeof(float) * blockLen),
196 const_cast<float*>(inBlock[i]) };
197
198 // See previous comment
199 assert(Count(mOutputList) >= mAudioOuts);
200 for (size_t i = 0; i < mAudioOuts; ++i)
201 mOutputList[i] = { 1, static_cast<UInt32>(sizeof(float) * blockLen),
202 outBlock[i] };
203
204 AudioUnitRenderActionFlags flags = 0;
205 OSStatus result;
206
207 result = AudioUnitRender(mUnit.get(),
208 &flags,
209 &mTimeStamp,
210 0,
211 blockLen,
212 mOutputList.get());
213 if (result != noErr) {
214 wxLogError("Render failed: %d %4.4s\n",
215 static_cast<int>(result), reinterpret_cast<char *>(&result));
216 return 0;
217 }
218
219 mTimeStamp.mSampleTime += blockLen;
220 return blockLen;
221}
PackedArray::Ptr< AudioBufferList > mInputList
AudioTimeStamp mTimeStamp
PackedArray::Ptr< AudioBufferList > mOutputList
size_t Count(const Ptr< Type, BaseDeleter > &p)
Find out how many elements were allocated with a Ptr.
Definition: PackedArray.h:143

References PackedArray::Count(), AudioUnitWrapper::mAudioIns, AudioUnitWrapper::mAudioOuts, mInputList, mOutputList, mTimeStamp, and AudioUnitWrapper::mUnit.

Here is the call graph for this function:

◆ ProcessFinalize()

bool AudioUnitInstance::ProcessFinalize ( )
overrideprivatevirtualnoexcept

Called at end of destructive processing, for each (mono/stereo) track Default implementation does nothing, returns true This may be called during stack unwinding:

Implements EffectInstance.

Definition at line 181 of file AudioUnitInstance.cpp.

182{
183 mOutputList.reset();
184 mInputList.reset();
185 return true;
186}

References mInputList, and mOutputList.

◆ ProcessInitialize()

bool AudioUnitInstance::ProcessInitialize ( EffectSettings settings,
double  sampleRate,
ChannelNames  chanMap 
)
overrideprivatevirtual

Called at start of destructive processing, for each (mono/stereo) track Default implementation does nothing, returns true

Parameters
chanMapnull or array terminated with ChannelNameEOL. Do not retain the pointer
Postcondition
GetAudioInCount() and GetAudioOutCount() are well defined

Implements EffectInstance.

Definition at line 129 of file AudioUnitInstance.cpp.

131{
133 return false;
134
135 mInputList =
136 PackedArray::AllocateCount<AudioBufferList>(mAudioIns)(mAudioIns);
138 PackedArray::AllocateCount<AudioBufferList>(mAudioOuts)(mAudioOuts);
139
140 memset(&mTimeStamp, 0, sizeof(AudioTimeStamp));
141 mTimeStamp.mSampleTime = 0; // This is a double-precision number that should
142 // accumulate the number of frames processed so far
143 mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
144
145 mInitialization.reset();
146 // Redo this with the correct sample rate, not the arbirary 44100 that the
147 // effect used
148 auto ins = mAudioIns;
149 auto outs = mAudioOuts;
151 return false;
152 if (AudioUnitInitialize(mUnit.get())) {
153 wxLogError("Couldn't initialize audio unit\n");
154 return false;
155 }
156 if (ins != mAudioIns || outs != mAudioOuts) {
157 // A change of channels with changing rate? This is unexpected!
158 ins = mAudioIns;
159 outs = mAudioOuts;
160 return false;
161 }
162 mInitialization.reset(mUnit.get());
163
164 if (SetProperty(kAudioUnitProperty_SetRenderCallback,
166 kAudioUnitScope_Input)) {
167 wxLogError("Setting input render callback failed.\n");
168 return false;
169 }
170
171 if (AudioUnitReset(mUnit.get(), kAudioUnitScope_Global, 0))
172 return false;
173
174 if (!BypassEffect(false))
175 // Ignore bad return value. Some (like Xfer OTT) give a bad status.
176 ;
177
178 return true;
179}
AudioUnitCleanup< AudioUnit, AudioUnitUninitialize > mInitialization
bool BypassEffect(bool bypass)
static OSStatus RenderCallback(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
const PerTrackEffect & mProcessor
bool StoreSettings(const EffectDefinitionInterface &effect, const AudioUnitEffectSettings &settings) const
bool SetRateAndChannels(double sampleRate, const wxString &identifier)
static AudioUnitEffectSettings & GetSettings(EffectSettings &settings)

References BypassEffect(), AudioUnitWrapper::GetSettings(), AudioUnitWrapper::mAudioIns, AudioUnitWrapper::mAudioOuts, mIdentifier, mInitialization, mInputList, mOutputList, PerTrackEffect::Instance::mProcessor, mTimeStamp, AudioUnitWrapper::mUnit, RenderCallback(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, AudioUnitWrapper::SetProperty(), AudioUnitWrapper::SetRateAndChannels(), settings(), and AudioUnitWrapper::StoreSettings().

Referenced by RealtimeInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RealtimeAddProcessor()

bool AudioUnitInstance::RealtimeAddProcessor ( EffectSettings settings,
EffectOutputs pOutputs,
unsigned  numChannels,
float  sampleRate 
)
overrideprivatevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 229 of file AudioUnitInstance.cpp.

231{
232 if (!mRecruited) {
233 // Assign self to the first processor
234 mRecruited = true;
235 return true;
236 }
237
238 // Assign another instance with independent state to other processors
239 auto &effect = static_cast<const PerTrackEffect&>(mProcessor);
240 auto uProcessor = std::make_unique<AudioUnitInstance>(effect,
243 uProcessor->SetBlockSize(mBlockSize);
244 if (!uProcessor->ProcessInitialize(settings, sampleRate, nullptr))
245 return false;
246 mSlaves.push_back(move(uProcessor));
247 return true;
248}
bool mRecruited
Whether the master instance is now allocated to a group number.
Base class for many of the effects in Audacity.
Parameters & mParameters
const AudioComponent mComponent

References AudioUnitWrapper::mAudioIns, AudioUnitWrapper::mAudioOuts, mBlockSize, AudioUnitWrapper::mComponent, mIdentifier, AudioUnitWrapper::mParameters, PerTrackEffect::Instance::mProcessor, mRecruited, mSlaves, mUseLatency, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeFinalize()

bool AudioUnitInstance::RealtimeFinalize ( EffectSettings settings)
overrideprivatevirtualnoexcept
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 250 of file AudioUnitInstance.cpp.

251{
252return GuardedCall<bool>([&]{
253 for (auto &pSlave : mSlaves)
254 pSlave->ProcessFinalize();
255 mSlaves.clear();
256 mRecruited = false;
257 return ProcessFinalize();
258});
259}
bool ProcessFinalize() noexcept override

◆ RealtimeInitialize()

bool AudioUnitInstance::RealtimeInitialize ( EffectSettings settings,
double  sampleRate 
)
overrideprivatevirtual
Returns
success
Postcondition
GetAudioInCount() and GetAudioOutCount() are well defined

Default implementation does nothing, returns false (so assume realtime is not supported). Other member functions related to realtime return true or zero, but will not be called, unless a derived class overrides RealtimeInitialize.

Reimplemented from EffectInstance.

Definition at line 223 of file AudioUnitInstance.cpp.

225{
226 return ProcessInitialize(settings, sampleRate, nullptr);
227}
bool ProcessInitialize(EffectSettings &settings, double sampleRate, ChannelNames chanMap) override

References ProcessInitialize(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeProcess()

size_t AudioUnitInstance::RealtimeProcess ( size_t  group,
EffectSettings settings,
const float *const *  inBuf,
float *const *  outBuf,
size_t  numSamples 
)
overrideprivatevirtual
Returns
success Default implementation does nothing, returns 0

Reimplemented from EffectInstance.

Definition at line 339 of file AudioUnitInstance.cpp.

341{
342 wxASSERT(numSamples <= mBlockSize);
343 // Interpret the group number consistently with RealtimeAddProcessor
344 if (!mRecruited)
345 return 0;
346 decltype(this) pSlave{};
347 if (group == 0)
348 pSlave = this;
349 else if (--group < mSlaves.size())
350 pSlave = mSlaves[group].get();
351 if (pSlave)
352 return pSlave->ProcessBlock(settings, inbuf, outbuf, numSamples);
353 else
354 return 0;
355}

References mBlockSize, mRecruited, mSlaves, and settings().

Here is the call graph for this function:

◆ RealtimeProcessEnd()

bool AudioUnitInstance::RealtimeProcessEnd ( EffectSettings settings)
overrideprivatevirtualnoexcept

settings can be updated to let a dialog change appearance at idle

Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 357 of file AudioUnitInstance.cpp.

358{
359 return true;
360}

◆ RealtimeProcessStart()

bool AudioUnitInstance::RealtimeProcessStart ( MessagePackage package)
overrideprivatevirtual

settings are possibly changed, since last call, by an asynchronous dialog

Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 308 of file AudioUnitInstance.cpp.

309{
310 if (!package.pMessage)
311 return true;
312 auto &values = static_cast<AudioUnitMessage*>(package.pMessage)
313 ->settings.values;
314 auto storeSettings = [&](AudioUnitInstance &instance){
315 for (auto &[ID, oPair] : values)
316 if (oPair.has_value()) {
317 auto value = oPair->second;
318 if (AudioUnitSetParameter(mUnit.get(), ID,
319 kAudioUnitScope_Global, 0, value, 0)) {
320 // Probably failed because of an invalid parameter when
321 // a plug-in is in a certain mode that doesn't contain
322 // the parameter. Ignore the failure
323 }
324 }
325 };
326 storeSettings(*this);
327 for (auto &pSlave : mSlaves)
328 storeSettings(*pSlave);
329
330 // Consume the settings change so we don't repeat setting of parameters
331 // until more inter-thread messages arrive
332 for (auto &[_, oPair] : values)
333 oPair.reset();
334
335 return true;
336}
const wxChar * values
#define _(s)
Definition: Internat.h:73

References _, mSlaves, AudioUnitWrapper::mUnit, EffectInstance::MessagePackage::pMessage, settings(), and values.

Here is the call graph for this function:

◆ RealtimeResume()

bool AudioUnitInstance::RealtimeResume ( )
overrideprivatevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 273 of file AudioUnitInstance.cpp.

274{
275 if (!BypassEffect(false))
276 //return false
277 ;
278 for (auto &pSlave: mSlaves)
279 if (!pSlave->BypassEffect(false))
280 //return false
281 ;
282 return true;
283}

References BypassEffect(), and mSlaves.

Here is the call graph for this function:

◆ RealtimeSuspend()

bool AudioUnitInstance::RealtimeSuspend ( )
overrideprivatevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 261 of file AudioUnitInstance.cpp.

262{
263 if (!BypassEffect(true))
264 //return false
265 ;
266 for (auto &pSlave : mSlaves)
267 if (!pSlave->BypassEffect(true))
268 //return false
269 ;
270 return true;
271}

References BypassEffect(), and mSlaves.

Here is the call graph for this function:

◆ Render()

OSStatus AudioUnitInstance::Render ( AudioUnitRenderActionFlags *  inActionFlags,
const AudioTimeStamp *  inTimeStamp,
UInt32  inBusNumber,
UInt32  inNumFrames,
AudioBufferList *  ioData 
)
private

Definition at line 362 of file AudioUnitInstance.cpp.

366{
367 size_t i = 0;
368 auto size = std::min<size_t>(ioData->mNumberBuffers, Count(mInputList));
369 for (; i < size; ++i)
370 ioData->mBuffers[i].mData = mInputList[i].mData;
371 // Some defensive code here just in case SDK requests from us an unexpectedly
372 // large number of buffers:
373 for (; i < ioData->mNumberBuffers; ++i)
374 ioData->mBuffers[i].mData = nullptr;
375 return 0;
376}
for(int ii=0, nn=names.size();ii< nn;++ii)

References PackedArray::Count(), for(), mInputList, and size.

Referenced by RenderCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RenderCallback()

OSStatus AudioUnitInstance::RenderCallback ( void *  inRefCon,
AudioUnitRenderActionFlags *  inActionFlags,
const AudioTimeStamp *  inTimeStamp,
UInt32  inBusNumber,
UInt32  inNumFrames,
AudioBufferList *  ioData 
)
staticprivate

Definition at line 379 of file AudioUnitInstance.cpp.

383{
384 return static_cast<AudioUnitInstance*>(inRefCon)->Render(inActionFlags,
385 inTimeStamp, inBusNumber, inNumFrames, ioData);
386}
OSStatus Render(AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)

References Render().

Referenced by ProcessInitialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBlockSize()

size_t AudioUnitInstance::SetBlockSize ( size_t  maxBlockSize)
overrideprivatevirtual

Implements EffectInstance.

Definition at line 85 of file AudioUnitInstance.cpp.

86{
87 // Ignore the argument! Too-large block sizes won't work
88 return mBlockSize;
89}

References mBlockSize.

◆ UsesMessages()

bool AudioUnitInstance::UsesMessages ( ) const
overrideprivatevirtualnoexcept

If true, the effect makes no use EffectSettings for inter-thread comminication

Default implementation returns false. In future, all effects should be rewritten to use messages and this function will be removed.

Reimplemented from EffectInstance.

Definition at line 303 of file AudioUnitInstance.cpp.

304{
305 return true;
306}

Member Data Documentation

◆ mBlockSize

const size_t AudioUnitInstance::mBlockSize
private

◆ mIdentifier

const wxString& AudioUnitInstance::mIdentifier
private

Definition at line 94 of file AudioUnitInstance.h.

Referenced by ProcessInitialize(), and RealtimeAddProcessor().

◆ mInitialization

AudioUnitCleanup<AudioUnit, AudioUnitUninitialize> AudioUnitInstance::mInitialization
private

Definition at line 88 of file AudioUnitInstance.h.

Referenced by ProcessInitialize().

◆ mInputList

PackedArray::Ptr<AudioBufferList> AudioUnitInstance::mInputList
private

Definition at line 90 of file AudioUnitInstance.h.

Referenced by ProcessBlock(), ProcessFinalize(), ProcessInitialize(), and Render().

◆ mOutputList

PackedArray::Ptr<AudioBufferList> AudioUnitInstance::mOutputList
private

Definition at line 91 of file AudioUnitInstance.h.

Referenced by ProcessBlock(), ProcessFinalize(), and ProcessInitialize().

◆ mRecruited

bool AudioUnitInstance::mRecruited { false }
private

Whether the master instance is now allocated to a group number.

Definition at line 85 of file AudioUnitInstance.h.

Referenced by RealtimeAddProcessor(), and RealtimeProcess().

◆ mSlaves

std::vector<std::unique_ptr<AudioUnitInstance> > AudioUnitInstance::mSlaves
private

◆ mTimeStamp

AudioTimeStamp AudioUnitInstance::mTimeStamp {}
private

Definition at line 89 of file AudioUnitInstance.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mUseLatency

const bool AudioUnitInstance::mUseLatency
private

Definition at line 96 of file AudioUnitInstance.h.

Referenced by RealtimeAddProcessor().


The documentation for this class was generated from the following files: