Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
EffectReverb::Instance Struct Reference
Inheritance diagram for EffectReverb::Instance:
[legend]
Collaboration diagram for EffectReverb::Instance:
[legend]

Public Member Functions

 Instance (const PerTrackEffect &effect)
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap) override
 
size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen) override
 Called for destructive effect computation. More...
 
bool ProcessFinalize (void) noexcept override
 
bool RealtimeInitialize (EffectSettings &settings, double sampleRate) override
 
bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *, unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize (EffectSettings &settings) noexcept override
 
size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inbuf, float *const *outbuf, size_t numSamples) override
 
bool RealtimeSuspend () override
 
unsigned GetAudioOutCount () const override
 How many output buffers to allocate at once. More...
 
unsigned GetAudioInCount () const override
 How many input buffers to allocate at once. More...
 
bool InstanceInit (EffectSettings &settings, double sampleRate, EffectReverbState &data, ChannelNames chanMap, bool forceStereo)
 
size_t InstanceProcess (EffectSettings &settings, EffectReverbState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 
- 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 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 EffectInstanceWithBlockSize
 ~EffectInstanceWithBlockSize () override
 
size_t GetBlockSize () const override
 
size_t SetBlockSize (size_t maxBlockSize) override
 

Public Attributes

EffectReverbState mState
 
std::vector< EffectReverb::InstancemSlaves
 
unsigned mChannels { 2 }
 
EffectReverbSettings mLastAppliedSettings
 
double mLastSampleRate { 0 }
 

Additional Inherited Members

- Public Types inherited from EffectInstance
using Message = EffectSettingsAccess::Message
 
using SampleCount = uint64_t
 
- Protected Attributes inherited from PerTrackEffect::Instance
const PerTrackEffectmProcessor
 
- Protected Attributes inherited from EffectInstanceWithBlockSize
size_t mBlockSize { 0 }
 

Detailed Description

Definition at line 183 of file Reverb.cpp.

Constructor & Destructor Documentation

◆ Instance()

EffectReverb::Instance::Instance ( const PerTrackEffect effect)
inlineexplicit

Definition at line 187 of file Reverb.cpp.

Member Function Documentation

◆ GetAudioInCount()

unsigned EffectReverb::Instance::GetAudioInCount ( ) const
inlineoverridevirtual

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 293 of file Reverb.cpp.

294 {
295 return mChannels;
296 }

References mChannels.

◆ GetAudioOutCount()

unsigned EffectReverb::Instance::GetAudioOutCount ( ) const
inlineoverridevirtual

How many output buffers to allocate at once.

The result is not necessarily well defined before RealtimeInitialize

Implements EffectInstance.

Definition at line 288 of file Reverb.cpp.

289 {
290 return mChannels;
291 }

References mChannels.

◆ InstanceInit()

bool EffectReverb::Instance::InstanceInit ( EffectSettings settings,
double  sampleRate,
EffectReverbState data,
ChannelNames  chanMap,
bool  forceStereo 
)

Definition at line 374 of file Reverb.cpp.

377{
378 auto& rs = GetSettings(settings);
379
380 bool isStereo = false;
381 state.mNumChans = 1;
382 if ( (chanMap && chanMap[0] != ChannelNameEOL && chanMap[1] == ChannelNameFrontRight)
383 || forceStereo )
384 {
385 isStereo = true;
386 state.mNumChans = 2;
387 }
388
389 state.mP = std::make_unique<Reverb_priv_ex[]>(state.mNumChans);
390
391 for (unsigned int i = 0; i < state.mNumChans; i++)
392 {
393 reverb_create(&state.mP[i].reverb,
395 rs.mWetGain,
396 rs.mRoomSize,
397 rs.mReverberance,
398 rs.mHfDamping,
399 rs.mPreDelay,
400 rs.mStereoWidth * (isStereo ? 1 : 0),
401 rs.mToneLow,
402 rs.mToneHigh,
403 BLOCK,
404 state.mP[i].wet);
405 }
406
407 return true;
408}
@ ChannelNameEOL
@ ChannelNameFrontRight
static size_t BLOCK
Definition: Reverb.cpp:360
static void reverb_create(reverb_t *p, double sample_rate_Hz, double wet_gain_dB, double room_scale, double reverberance, double hf_damping, double pre_delay_ms, double stereo_depth, double tone_low, double tone_high, size_t buffer_size, float **out)
static Settings & settings()
Definition: TrackInfo.cpp:69
static EffectReverbSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:169

References BLOCK, ChannelNameEOL, ChannelNameFrontRight, EffectWithSettings< EffectReverbSettings, StatelessPerTrackEffect >::GetSettings(), EffectReverbState::mNumChans, EffectReverbState::mP, reverb_create(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Referenced by RealtimeAddProcessor().

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

◆ InstanceProcess()

size_t EffectReverb::Instance::InstanceProcess ( EffectSettings settings,
EffectReverbState data,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)

Definition at line 421 of file Reverb.cpp.

423{
424 auto& rs = GetSettings(settings);
425
426 const float *ichans[2] = {NULL, NULL};
427 float *ochans[2] = {NULL, NULL};
428
429 for (unsigned int c = 0; c < state.mNumChans; c++)
430 {
431 ichans[c] = inBlock[c];
432 ochans[c] = outBlock[c];
433 }
434
435 float const dryMult = rs.mWetOnly ? 0 : dB_to_linear(rs.mDryGain);
436
437 auto remaining = blockLen;
438
439 while (remaining)
440 {
441 auto len = std::min(remaining, decltype(remaining)(BLOCK));
442 for (unsigned int c = 0; c < state.mNumChans; c++)
443 {
444 // Write the input samples to the reverb fifo. Returned value is the address of the
445 // fifo buffer which contains a copy of the input samples.
446 state.mP[c].dry = (float *) fifo_write(&state.mP[c].reverb.input_fifo, len, ichans[c]);
447 reverb_process(&state.mP[c].reverb, len);
448 }
449
450 if (state.mNumChans == 2)
451 {
452 for (decltype(len) i = 0; i < len; i++)
453 {
454 for (int w = 0; w < 2; w++)
455 {
456 ochans[w][i] = dryMult *
457 state.mP[w].dry[i] +
458 0.5 *
459 (state.mP[0].wet[w][i] + state.mP[1].wet[w][i]);
460 }
461 }
462 }
463 else
464 {
465 for (decltype(len) i = 0; i < len; i++)
466 {
467 ochans[0][i] = dryMult *
468 state.mP[0].dry[i] +
469 state.mP[0].wet[0][i];
470 }
471 }
472
473 remaining -= len;
474
475 for (unsigned int c = 0; c < state.mNumChans; c++)
476 {
477 ichans[c] += len;
478 ochans[c] += len;
479 }
480 }
481
482 return blockLen;
483}
int min(int a, int b)
#define dB_to_linear(x)
Definition: Reverb_libSoX.h:27
static void reverb_process(reverb_t *p, size_t length)
static void * fifo_write(fifo_t *f, FIFO_SIZE_T n, void const *data)
Definition: Reverb_libSoX.h:81

References BLOCK, dB_to_linear, fifo_write(), EffectWithSettings< EffectReverbSettings, StatelessPerTrackEffect >::GetSettings(), min(), EffectReverbState::mNumChans, EffectReverbState::mP, reverb_process(), and settings().

Referenced by RealtimeProcess().

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

◆ ProcessBlock()

size_t EffectReverb::Instance::ProcessBlock ( EffectSettings settings,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)
overridevirtual

Called for destructive effect computation.

Implements EffectInstance.

Definition at line 415 of file Reverb.cpp.

417{
418 return InstanceProcess(settings, mState, inBlock, outBlock, blockLen);
419}
size_t InstanceProcess(EffectSettings &settings, EffectReverbState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
Definition: Reverb.cpp:421
EffectReverbState mState
Definition: Reverb.cpp:304

References mState, and settings().

Here is the call graph for this function:

◆ ProcessFinalize()

bool EffectReverb::Instance::ProcessFinalize ( void  )
overridevirtualnoexcept

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 410 of file Reverb.cpp.

411{
412 return true;
413}

◆ ProcessInitialize()

bool EffectReverb::Instance::ProcessInitialize ( EffectSettings settings,
double  sampleRate,
ChannelNames  chanMap 
)
overridevirtual

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 362 of file Reverb.cpp.

364{
365 // For descructive processing, fix the number of channels, maybe as 1 not 2
366 auto& rs = GetSettings(settings);
367 mChannels = rs.mStereoWidth ? 2 : 1;
368
369 return InstanceInit(settings,
370 sampleRate, mState, chanMap, /* forceStereo = */ false);
371}
bool InstanceInit(EffectSettings &settings, double sampleRate, EffectReverbState &data, ChannelNames chanMap, bool forceStereo)
Definition: Reverb.cpp:374

References EffectWithSettings< EffectReverbSettings, StatelessPerTrackEffect >::GetSettings(), mState, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeAddProcessor()

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

Reimplemented from EffectInstance.

Definition at line 212 of file Reverb.cpp.

214 {
216
217 // The notion of ChannelNames is unavailable here,
218 // so we'll have to force the stereo init, if this is the case
219 //
221 slave.mState, /*ChannelNames=*/nullptr, /*forceStereo=*/(numChannels == 2));
222
223 mSlaves.push_back( std::move(slave) );
224 return true;
225 }
const PerTrackEffect & mProcessor
std::vector< EffectReverb::Instance > mSlaves
Definition: Reverb.cpp:305

References InstanceInit(), PerTrackEffect::Instance::mProcessor, mSlaves, mState, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeFinalize()

bool EffectReverb::Instance::RealtimeFinalize ( EffectSettings settings)
inlineoverridevirtualnoexcept
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 227 of file Reverb.cpp.

228 {
229 mSlaves.clear();
230 return true;
231 }

References mSlaves.

◆ RealtimeInitialize()

bool EffectReverb::Instance::RealtimeInitialize ( EffectSettings settings,
double  sampleRate 
)
inlineoverridevirtual
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 201 of file Reverb.cpp.

202 {
203 SetBlockSize(512);
204 mSlaves.clear();
205
208
209 return true;
210 }
size_t SetBlockSize(size_t maxBlockSize) override
EffectReverbSettings mLastAppliedSettings
Definition: Reverb.cpp:309

References EffectWithSettings< EffectReverbSettings, StatelessPerTrackEffect >::GetSettings(), mLastAppliedSettings, mLastSampleRate, mSlaves, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, EffectInstanceWithBlockSize::SetBlockSize(), and settings().

Here is the call graph for this function:

◆ RealtimeProcess()

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

Reimplemented from EffectInstance.

Definition at line 233 of file Reverb.cpp.

235 {
236
237 const auto& incomingSettings = GetSettings(settings);
238 if ( !(incomingSettings == mLastAppliedSettings) )
239 {
240 const bool onlySimpleOnes = OnlySimpleParametersChanged(incomingSettings, mLastAppliedSettings);
241
242 for (auto& slave : mSlaves)
243 {
244 for (unsigned int i = 0; i < slave.mState.mNumChans; i++)
245 {
246 auto& reverbCore = slave.mState.mP[i].reverb;
247 const auto& is = incomingSettings;
248
249 if (onlySimpleOnes)
250 {
252 is.mWetGain, is.mReverberance, is.mHfDamping, is.mToneLow, is.mToneHigh);
253 }
254 else
255 {
256 // One of the non-simple parameters changed, so we need to do a full reinit
257 reverb_init(&reverbCore, mLastSampleRate,
258 is.mWetGain, is.mRoomSize, is.mReverberance, is.mHfDamping,
259 is.mPreDelay, is.mStereoWidth, is.mToneLow, is.mToneHigh );
260 }
261 }
262 }
263
264 mLastAppliedSettings = incomingSettings;
265 }
266
267
268 if (group >= mSlaves.size())
269 return 0;
270 return InstanceProcess(settings, mSlaves[group].mState, inbuf, outbuf, numSamples);
271 }
bool OnlySimpleParametersChanged(const EffectReverbSettings &a, const EffectReverbSettings &b)
Definition: Reverb.cpp:647
static void reverb_init(reverb_t *p, double sample_rate_Hz, double wet_gain_dB, double room_scale, double reverberance, double hf_damping, double pre_delay_ms, double stereo_depth, double tone_low, double tone_high)
static void reverb_set_simple_params(reverb_t *p, double sample_rate_Hz, double wet_gain_dB, double reverberance, double hf_damping, double tone_low, double tone_high)

References EffectWithSettings< EffectReverbSettings, StatelessPerTrackEffect >::GetSettings(), InstanceProcess(), mLastAppliedSettings, mLastSampleRate, mSlaves, mState, OnlySimpleParametersChanged(), reverb_init(), reverb_set_simple_params(), and settings().

Here is the call graph for this function:

◆ RealtimeSuspend()

bool EffectReverb::Instance::RealtimeSuspend ( )
inlineoverridevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 274 of file Reverb.cpp.

275 {
276 for (auto& slave : mSlaves)
277 {
278 for (unsigned int i = 0; i < slave.mState.mNumChans; i++)
279 {
280 reverb_clear( &(slave.mState.mP[i].reverb) );
281 }
282 }
283
284 return true;
285 }
static void reverb_clear(reverb_t *p)

References mSlaves, and reverb_clear().

Here is the call graph for this function:

Member Data Documentation

◆ mChannels

unsigned EffectReverb::Instance::mChannels { 2 }

Definition at line 307 of file Reverb.cpp.

Referenced by GetAudioInCount(), and GetAudioOutCount().

◆ mLastAppliedSettings

EffectReverbSettings EffectReverb::Instance::mLastAppliedSettings

Definition at line 309 of file Reverb.cpp.

Referenced by RealtimeInitialize(), and RealtimeProcess().

◆ mLastSampleRate

double EffectReverb::Instance::mLastSampleRate { 0 }

Definition at line 310 of file Reverb.cpp.

Referenced by RealtimeInitialize(), and RealtimeProcess().

◆ mSlaves

std::vector<EffectReverb::Instance> EffectReverb::Instance::mSlaves

◆ mState

EffectReverbState EffectReverb::Instance::mState

Definition at line 304 of file Reverb.cpp.

Referenced by RealtimeAddProcessor(), and RealtimeProcess().


The documentation for this struct was generated from the following file: