Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
ReverbBase::Instance Struct Reference

#include <ReverbBase.h>

Inheritance diagram for ReverbBase::Instance:
[legend]
Collaboration diagram for ReverbBase::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, ReverbState &data, ChannelNames chanMap, bool forceStereo)
 
size_t InstanceProcess (EffectSettings &settings, ReverbState &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 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 EffectInstanceWithBlockSize
 ~EffectInstanceWithBlockSize () override
 
size_t GetBlockSize () const override
 
size_t SetBlockSize (size_t maxBlockSize) override
 

Public Attributes

ReverbState mState
 
std::vector< ReverbBase::InstancemSlaves
 
unsigned mChannels { 2 }
 
ReverbSettings 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 86 of file ReverbBase.h.

Constructor & Destructor Documentation

◆ Instance()

ReverbBase::Instance::Instance ( const PerTrackEffect effect)
explicit

Definition at line 107 of file ReverbBase.cpp.

Member Function Documentation

◆ GetAudioInCount()

unsigned ReverbBase::Instance::GetAudioInCount ( ) const
overridevirtual

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 257 of file ReverbBase.cpp.

258{
259 return mChannels;
260}

◆ GetAudioOutCount()

unsigned ReverbBase::Instance::GetAudioOutCount ( ) const
overridevirtual

How many output buffers to allocate at once.

The result is not necessarily well defined before RealtimeInitialize

Implements EffectInstance.

Definition at line 252 of file ReverbBase.cpp.

253{
254 return mChannels;
255}

◆ InstanceInit()

bool ReverbBase::Instance::InstanceInit ( EffectSettings settings,
double  sampleRate,
ReverbState data,
ChannelNames  chanMap,
bool  forceStereo 
)

Definition at line 123 of file ReverbBase.cpp.

126{
127 auto& rs = GetSettings(settings);
128
129 bool isStereo = false;
130 state.mNumChans = 1;
131 if (
132 (chanMap && chanMap[0] != ChannelNameEOL &&
133 chanMap[1] == ChannelNameFrontRight) ||
134 forceStereo)
135 {
136 isStereo = true;
137 state.mNumChans = 2;
138 }
139
140 state.mP = std::make_unique<Reverb_priv_ex[]>(state.mNumChans);
141
142 for (unsigned int i = 0; i < state.mNumChans; i++)
143 {
145 &state.mP[i].reverb, sampleRate, rs.mWetGain, rs.mRoomSize,
146 rs.mReverberance, rs.mHfDamping, rs.mPreDelay,
147 rs.mStereoWidth * (isStereo ? 1 : 0), rs.mToneLow, rs.mToneHigh, BLOCK,
148 state.mP[i].wet);
149 }
150
151 return true;
152}
@ ChannelNameEOL
@ ChannelNameFrontRight
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 size_t BLOCK
Definition: ReverbBase.cpp:105
static Settings & settings()
Definition: TrackInfo.cpp:51
static ReverbSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:166

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

Here is the call graph for this function:

◆ InstanceProcess()

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

Definition at line 269 of file ReverbBase.cpp.

272{
273 auto& rs = GetSettings(settings);
274
275 const float* ichans[2] = { NULL, NULL };
276 float* ochans[2] = { NULL, NULL };
277
278 for (unsigned int c = 0; c < state.mNumChans; c++)
279 {
280 ichans[c] = inBlock[c];
281 ochans[c] = outBlock[c];
282 }
283
284 float const dryMult = rs.mWetOnly ? 0 : dB_to_linear(rs.mDryGain);
285
286 auto remaining = blockLen;
287
288 while (remaining)
289 {
290 auto len = std::min(remaining, decltype(remaining)(BLOCK));
291 for (unsigned int c = 0; c < state.mNumChans; c++)
292 {
293 // Write the input samples to the reverb fifo. Returned value is the
294 // address of the fifo buffer which contains a copy of the input
295 // samples.
296 state.mP[c].dry =
297 (float*)fifo_write(&state.mP[c].reverb.input_fifo, len, ichans[c]);
298 reverb_process(&state.mP[c].reverb, len);
299 }
300
301 if (state.mNumChans == 2)
302 {
303 for (decltype(len) i = 0; i < len; i++)
304 {
305 for (int w = 0; w < 2; w++)
306 {
307 ochans[w][i] =
308 dryMult * state.mP[w].dry[i] +
309 0.5 * (state.mP[0].wet[w][i] + state.mP[1].wet[w][i]);
310 }
311 }
312 }
313 else
314 {
315 for (decltype(len) i = 0; i < len; i++)
316 {
317 ochans[0][i] = dryMult * state.mP[0].dry[i] + state.mP[0].wet[0][i];
318 }
319 }
320
321 remaining -= len;
322
323 for (unsigned int c = 0; c < state.mNumChans; c++)
324 {
325 ichans[c] += len;
326 ochans[c] += len;
327 }
328 }
329
330 return blockLen;
331}
int min(int a, int b)
#define dB_to_linear(x)
Definition: Reverb_libSoX.h:29
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:83

References BLOCK, dB_to_linear, fifo_write(), EffectWithSettings< ReverbSettings, PerTrackEffect >::GetSettings(), min(), ReverbState::mNumChans, ReverbState::mP, reverb_process(), and settings().

Here is the call graph for this function:

◆ ProcessBlock()

size_t ReverbBase::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 262 of file ReverbBase.cpp.

265{
266 return InstanceProcess(settings, mState, inBlock, outBlock, blockLen);
267}
size_t InstanceProcess(EffectSettings &settings, ReverbState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
Definition: ReverbBase.cpp:269
ReverbState mState
Definition: ReverbBase.h:131

References mState, and settings().

Here is the call graph for this function:

◆ ProcessFinalize()

bool ReverbBase::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 154 of file ReverbBase.cpp.

155{
156 return true;
157}

◆ ProcessInitialize()

bool ReverbBase::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 112 of file ReverbBase.cpp.

114{
115 // For descructive processing, fix the number of channels, maybe as 1 not 2
116 auto& rs = GetSettings(settings);
117 mChannels = rs.mStereoWidth ? 2 : 1;
118
119 return InstanceInit(
120 settings, sampleRate, mState, chanMap, /* forceStereo = */ false);
121}
bool InstanceInit(EffectSettings &settings, double sampleRate, ReverbState &data, ChannelNames chanMap, bool forceStereo)
Definition: ReverbBase.cpp:123

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

Here is the call graph for this function:

◆ RealtimeAddProcessor()

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

Reimplemented from EffectInstance.

Definition at line 171 of file ReverbBase.cpp.

174{
176
177 // The notion of ChannelNames is unavailable here,
178 // so we'll have to force the stereo init, if this is the case
179 //
181 settings, sampleRate, slave.mState, /*ChannelNames=*/nullptr,
182 /*forceStereo=*/(numChannels == 2));
183
184 mSlaves.push_back(std::move(slave));
185 return true;
186}
const PerTrackEffect & mProcessor
std::vector< ReverbBase::Instance > mSlaves
Definition: ReverbBase.h:132

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

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 188 of file ReverbBase.cpp.

189{
190 mSlaves.clear();
191 return true;
192}

◆ RealtimeInitialize()

bool ReverbBase::Instance::RealtimeInitialize ( EffectSettings settings,
double  sampleRate 
)
overridevirtual
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 159 of file ReverbBase.cpp.

161{
162 SetBlockSize(512);
163 mSlaves.clear();
164
167
168 return true;
169}
size_t SetBlockSize(size_t maxBlockSize) override
ReverbSettings mLastAppliedSettings
Definition: ReverbBase.h:136

References EffectWithSettings< ReverbSettings, PerTrackEffect >::GetSettings(), anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, and settings().

Here is the call graph for this function:

◆ RealtimeProcess()

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

Reimplemented from EffectInstance.

Definition at line 194 of file ReverbBase.cpp.

197{
198
199 const auto& incomingSettings = GetSettings(settings);
200 if (!(incomingSettings == mLastAppliedSettings))
201 {
202 const bool onlySimpleOnes =
204
205 for (auto& slave : mSlaves)
206 {
207 for (unsigned int i = 0; i < slave.mState.mNumChans; i++)
208 {
209 auto& reverbCore = slave.mState.mP[i].reverb;
210 const auto& is = incomingSettings;
211
212 if (onlySimpleOnes)
213 {
215 &reverbCore, mLastSampleRate, is.mWetGain, is.mReverberance,
216 is.mHfDamping, is.mToneLow, is.mToneHigh);
217 }
218 else
219 {
220 // One of the non-simple parameters changed, so we need to
221 // do a full reinit
223 &reverbCore, mLastSampleRate, is.mWetGain, is.mRoomSize,
224 is.mReverberance, is.mHfDamping, is.mPreDelay,
225 is.mStereoWidth, is.mToneLow, is.mToneHigh);
226 }
227 }
228 }
229
230 mLastAppliedSettings = incomingSettings;
231 }
232
233 if (group >= mSlaves.size())
234 return 0;
235 return InstanceProcess(
236 settings, mSlaves[group].mState, inbuf, outbuf, numSamples);
237}
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)
bool OnlySimpleParametersChanged(const ReverbSettings &a, const ReverbSettings &b)
Definition: ReverbBase.cpp:369

References EffectWithSettings< ReverbSettings, PerTrackEffect >::GetSettings(), mState, OnlySimpleParametersChanged(), reverb_init(), reverb_set_simple_params(), and settings().

Here is the call graph for this function:

◆ RealtimeSuspend()

bool ReverbBase::Instance::RealtimeSuspend ( )
overridevirtual
Returns
success Default implementation does nothing, returns true

Reimplemented from EffectInstance.

Definition at line 239 of file ReverbBase.cpp.

240{
241 for (auto& slave : mSlaves)
242 {
243 for (unsigned int i = 0; i < slave.mState.mNumChans; i++)
244 {
245 reverb_clear(&(slave.mState.mP[i].reverb));
246 }
247 }
248
249 return true;
250}
static void reverb_clear(reverb_t *p)

References reverb_clear().

Here is the call graph for this function:

Member Data Documentation

◆ mChannels

unsigned ReverbBase::Instance::mChannels { 2 }

Definition at line 134 of file ReverbBase.h.

◆ mLastAppliedSettings

ReverbSettings ReverbBase::Instance::mLastAppliedSettings

Definition at line 136 of file ReverbBase.h.

◆ mLastSampleRate

double ReverbBase::Instance::mLastSampleRate { 0 }

Definition at line 137 of file ReverbBase.h.

◆ mSlaves

std::vector<ReverbBase::Instance> ReverbBase::Instance::mSlaves

Definition at line 132 of file ReverbBase.h.

◆ mState

ReverbState ReverbBase::Instance::mState

Definition at line 131 of file ReverbBase.h.

Referenced by RealtimeAddProcessor().


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