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

#include <PhaserBase.h>

Inheritance diagram for PhaserBase::Instance:
[legend]
Collaboration diagram for PhaserBase::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 RealtimeInitialize (EffectSettings &settings, double) override
 
bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, 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
 
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...
 
void InstanceInit (EffectSettings &settings, EffectPhaserState &data, float sampleRate)
 
size_t InstanceProcess (EffectSettings &settings, EffectPhaserState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 
void Coefficients (double hz, double slope, double gain, double samplerate, int type, double &a0, double &a1, double &a2, double &b0, double &b1, double &b2)
 
float DoFilter (EffectPhaserState &data, float in)
 
- 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

EffectPhaserState mState
 
std::vector< PhaserBase::InstancemSlaves
 

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 92 of file PhaserBase.h.

Constructor & Destructor Documentation

◆ Instance()

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

Definition at line 96 of file PhaserBase.h.

Member Function Documentation

◆ Coefficients()

void PhaserBase::Instance::Coefficients ( double  hz,
double  slope,
double  gain,
double  samplerate,
int  type,
double &  a0,
double &  a1,
double &  a2,
double &  b0,
double &  b1,
double &  b2 
)

◆ DoFilter()

float PhaserBase::Instance::DoFilter ( EffectPhaserState data,
float  in 
)

◆ GetAudioInCount()

unsigned PhaserBase::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 89 of file PhaserBase.cpp.

90{
91 return 1;
92}

◆ GetAudioOutCount()

unsigned PhaserBase::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 94 of file PhaserBase.cpp.

95{
96 return 1;
97}

◆ InstanceInit()

void PhaserBase::Instance::InstanceInit ( EffectSettings settings,
EffectPhaserState data,
float  sampleRate 
)

Definition at line 153 of file PhaserBase.cpp.

155{
156 auto& ms = GetSettings(settings);
157
158 data.samplerate = sampleRate;
159
160 for (int j = 0; j < ms.mStages; j++)
161 {
162 data.old[j] = 0;
163 }
164
165 data.skipcount = 0;
166 data.gain = 0;
167 data.fbout = 0;
168 data.laststages = 0;
169 data.outgain = 0;
170
171 return;
172}
static Settings & settings()
Definition: TrackInfo.cpp:51
double old[NUM_STAGES]
Definition: PhaserBase.h:29
sampleCount skipcount
Definition: PhaserBase.h:28
static EffectPhaserSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:166

References EffectPhaserState::fbout, EffectPhaserState::gain, EffectWithSettings< EffectPhaserSettings, PerTrackEffect >::GetSettings(), EffectPhaserState::laststages, EffectPhaserState::old, EffectPhaserState::outgain, EffectPhaserState::samplerate, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), and EffectPhaserState::skipcount.

Here is the call graph for this function:

◆ InstanceProcess()

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

Definition at line 174 of file PhaserBase.cpp.

177{
178 auto& ms = GetSettings(settings);
179
180 const float* ibuf = inBlock[0];
181 float* obuf = outBlock[0];
182
183 for (int j = data.laststages; j < ms.mStages; j++)
184 {
185 data.old[j] = 0;
186 }
187 data.laststages = ms.mStages;
188
189 data.lfoskip = ms.mFreq * 2 * M_PI / data.samplerate;
190 data.phase = ms.mPhase * M_PI / 180;
191 data.outgain = DB_TO_LINEAR(ms.mOutGain);
192
193 for (decltype(blockLen) i = 0; i < blockLen; i++)
194 {
195 double in = ibuf[i];
196
197 double m =
198 in + data.fbout * ms.mFeedback /
199 101; // Feedback must be less than 100% to avoid infinite gain.
200
201 if (((data.skipcount++) % lfoskipsamples) == 0)
202 {
203 // compute sine between 0 and 1
204 data.gain =
205 (1.0 +
206 cos(data.skipcount.as_double() * data.lfoskip + data.phase)) /
207 2.0;
208
209 // change lfo shape
210 data.gain = expm1(data.gain * phaserlfoshape) / expm1(phaserlfoshape);
211
212 // attenuate the lfo
213 data.gain = 1.0 - data.gain / 255.0 * ms.mDepth;
214 }
215
216 // phasing routine
217 for (int j = 0; j < ms.mStages; j++)
218 {
219 double tmp = data.old[j];
220 data.old[j] = data.gain * tmp + m;
221 m = tmp - data.gain * data.old[j];
222 }
223 data.fbout = m;
224
225 obuf[i] =
226 (float)(data.outgain * (m * ms.mDryWet + in * (255 - ms.mDryWet)) / 255);
227 }
228
229 return blockLen;
230}
#define M_PI
Definition: Distortion.cpp:22
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:338
#define phaserlfoshape
Definition: PhaserBase.cpp:35
#define lfoskipsamples
Definition: PhaserBase.cpp:38
double as_double() const
Definition: SampleCount.h:46

References sampleCount::as_double(), DB_TO_LINEAR, EffectPhaserState::fbout, EffectPhaserState::gain, EffectWithSettings< EffectPhaserSettings, PerTrackEffect >::GetSettings(), EffectPhaserState::laststages, EffectPhaserState::lfoskip, lfoskipsamples, M_PI, EffectPhaserState::old, EffectPhaserState::outgain, EffectPhaserState::phase, phaserlfoshape, EffectPhaserState::samplerate, settings(), and EffectPhaserState::skipcount.

Here is the call graph for this function:

◆ ProcessBlock()

size_t PhaserBase::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 108 of file PhaserBase.cpp.

111{
112 return InstanceProcess(settings, mState, inBlock, outBlock, blockLen);
113}
EffectPhaserState mState
Definition: PhaserBase.h:138
size_t InstanceProcess(EffectSettings &settings, EffectPhaserState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
Definition: PhaserBase.cpp:174

References mState, and settings().

Here is the call graph for this function:

◆ ProcessInitialize()

bool PhaserBase::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 99 of file PhaserBase.cpp.

101{
103 if (chanMap[0] == ChannelNameFrontRight)
104 mState.phase += M_PI;
105 return true;
106}
@ ChannelNameFrontRight
void InstanceInit(EffectSettings &settings, EffectPhaserState &data, float sampleRate)
Definition: PhaserBase.cpp:153

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

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool PhaserBase::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 122 of file PhaserBase.cpp.

124{
126
127 InstanceInit(settings, slave.mState, sampleRate);
128
129 mSlaves.push_back(slave);
130
131 return true;
132}
const PerTrackEffect & mProcessor
std::vector< PhaserBase::Instance > mSlaves
Definition: PhaserBase.h:139

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

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 134 of file PhaserBase.cpp.

135{
136 mSlaves.clear();
137
138 return true;
139}

◆ RealtimeInitialize()

bool PhaserBase::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 115 of file PhaserBase.cpp.

116{
117 SetBlockSize(512);
118 mSlaves.clear();
119 return true;
120}
size_t SetBlockSize(size_t maxBlockSize) override

◆ RealtimeProcess()

size_t PhaserBase::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 141 of file PhaserBase.cpp.

144{
145 if (group >= mSlaves.size())
146 return 0;
147 return InstanceProcess(
148 settings, mSlaves[group].mState, inbuf, outbuf, numSamples);
149}

References mState, and settings().

Here is the call graph for this function:

Member Data Documentation

◆ mSlaves

std::vector<PhaserBase::Instance> PhaserBase::Instance::mSlaves

Definition at line 139 of file PhaserBase.h.

◆ mState

EffectPhaserState PhaserBase::Instance::mState

Definition at line 138 of file PhaserBase.h.

Referenced by RealtimeAddProcessor().


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