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

#include <BassTrebleBase.h>

Inheritance diagram for BassTrebleBase::Instance:
[legend]
Collaboration diagram for BassTrebleBase::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...
 
- 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
 

Static Public Member Functions

static void InstanceInit (EffectSettings &settings, BassTrebleState &data, float sampleRate)
 
static size_t InstanceProcess (EffectSettings &settings, BassTrebleState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 
static void Coefficients (double hz, double slope, double gain, double samplerate, int type, double &a0, double &a1, double &a2, double &b0, double &b1, double &b2)
 
static float DoFilter (BassTrebleState &data, float in)
 

Public Attributes

BassTrebleState mState
 
std::vector< BassTrebleBase::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 74 of file BassTrebleBase.h.

Constructor & Destructor Documentation

◆ Instance()

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

Definition at line 78 of file BassTrebleBase.h.

Member Function Documentation

◆ Coefficients()

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

Definition at line 158 of file BassTrebleBase.cpp.

161{
162 double w = 2 * M_PI * hz / samplerate;
163 double a = exp(log(10.0) * gain / 40);
164 double b = sqrt((a * a + 1) / slope - (pow((a - 1), 2)));
165
166 if (type == kBass)
167 {
168 b0 = a * ((a + 1) - (a - 1) * cos(w) + b * sin(w));
169 b1 = 2 * a * ((a - 1) - (a + 1) * cos(w));
170 b2 = a * ((a + 1) - (a - 1) * cos(w) - b * sin(w));
171 a0 = ((a + 1) + (a - 1) * cos(w) + b * sin(w));
172 a1 = -2 * ((a - 1) + (a + 1) * cos(w));
173 a2 = (a + 1) + (a - 1) * cos(w) - b * sin(w);
174 }
175 else // assumed kTreble
176 {
177 b0 = a * ((a + 1) + (a - 1) * cos(w) + b * sin(w));
178 b1 = -2 * a * ((a - 1) + (a + 1) * cos(w));
179 b2 = a * ((a + 1) + (a - 1) * cos(w) - b * sin(w));
180 a0 = ((a + 1) - (a - 1) * cos(w) + b * sin(w));
181 a1 = 2 * ((a - 1) - (a + 1) * cos(w));
182 a2 = (a + 1) - (a - 1) * cos(w) - b * sin(w);
183 }
184}
@ kBass
#define M_PI
Definition: Distortion.cpp:22
__finl float_x4 __vecc sqrt(const float_x4 &a)

References kBass, M_PI, and staffpad::audio::simd::sqrt().

Here is the call graph for this function:

◆ DoFilter()

float BassTrebleBase::Instance::DoFilter ( BassTrebleState data,
float  in 
)
static

Definition at line 186 of file BassTrebleBase.cpp.

187{
188 // Bass filter
189 float out = (data.b0Bass * in + data.b1Bass * data.xn1Bass +
190 data.b2Bass * data.xn2Bass - data.a1Bass * data.yn1Bass -
191 data.a2Bass * data.yn2Bass) /
192 data.a0Bass;
193 data.xn2Bass = data.xn1Bass;
194 data.xn1Bass = in;
195 data.yn2Bass = data.yn1Bass;
196 data.yn1Bass = out;
197
198 // Treble filter
199 in = out;
200 out = (data.b0Treble * in + data.b1Treble * data.xn1Treble +
201 data.b2Treble * data.xn2Treble - data.a1Treble * data.yn1Treble -
202 data.a2Treble * data.yn2Treble) /
203 data.a0Treble;
204 data.xn2Treble = data.xn1Treble;
205 data.xn1Treble = in;
206 data.yn2Treble = data.yn1Treble;
207 data.yn1Treble = out;
208
209 return out;
210}

References BassTrebleState::a0Bass, BassTrebleState::a0Treble, BassTrebleState::a1Bass, BassTrebleState::a1Treble, BassTrebleState::a2Bass, BassTrebleState::a2Treble, BassTrebleState::b0Bass, BassTrebleState::b0Treble, BassTrebleState::b1Bass, BassTrebleState::b1Treble, BassTrebleState::b2Bass, BassTrebleState::b2Treble, BassTrebleState::xn1Bass, BassTrebleState::xn1Treble, BassTrebleState::xn2Bass, BassTrebleState::xn2Treble, BassTrebleState::yn1Bass, BassTrebleState::yn1Treble, BassTrebleState::yn2Bass, and BassTrebleState::yn2Treble.

◆ GetAudioInCount()

unsigned BassTrebleBase::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 61 of file BassTrebleBase.cpp.

62{
63 return 1;
64}

◆ GetAudioOutCount()

unsigned BassTrebleBase::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 66 of file BassTrebleBase.cpp.

67{
68 return 1;
69}

◆ InstanceInit()

void BassTrebleBase::Instance::InstanceInit ( EffectSettings settings,
BassTrebleState data,
float  sampleRate 
)
static

Definition at line 212 of file BassTrebleBase.cpp.

214{
215 auto& ms = GetSettings(settings);
216
217 data.samplerate = sampleRate;
218 data.slope = 0.4f; // same slope for both filters
219 data.hzBass = 250.0f; // could be tunable in a more advanced version
220 data.hzTreble = 4000.0f; // could be tunable in a more advanced version
221
222 data.a0Bass = 1;
223 data.a1Bass = 0;
224 data.a2Bass = 0;
225 data.b0Bass = 0;
226 data.b1Bass = 0;
227 data.b2Bass = 0;
228
229 data.a0Treble = 1;
230 data.a1Treble = 0;
231 data.a2Treble = 0;
232 data.b0Treble = 0;
233 data.b1Treble = 0;
234 data.b2Treble = 0;
235
236 data.xn1Bass = 0;
237 data.xn2Bass = 0;
238 data.yn1Bass = 0;
239 data.yn2Bass = 0;
240
241 data.xn1Treble = 0;
242 data.xn2Treble = 0;
243 data.yn1Treble = 0;
244 data.yn2Treble = 0;
245
246 data.bass = -1;
247 data.treble = -1;
248 data.gain = DB_TO_LINEAR(ms.mGain);
249}
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:338
static Settings & settings()
Definition: TrackInfo.cpp:51
static BassTrebleSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:166

References BassTrebleState::a0Bass, BassTrebleState::a0Treble, BassTrebleState::a1Bass, BassTrebleState::a1Treble, BassTrebleState::a2Bass, BassTrebleState::a2Treble, BassTrebleState::b0Bass, BassTrebleState::b0Treble, BassTrebleState::b1Bass, BassTrebleState::b1Treble, BassTrebleState::b2Bass, BassTrebleState::b2Treble, BassTrebleState::bass, DB_TO_LINEAR, BassTrebleState::gain, EffectWithSettings< BassTrebleSettings, PerTrackEffect >::GetSettings(), BassTrebleState::hzBass, BassTrebleState::hzTreble, BassTrebleState::samplerate, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), BassTrebleState::slope, BassTrebleState::treble, BassTrebleState::xn1Bass, BassTrebleState::xn1Treble, BassTrebleState::xn2Bass, BassTrebleState::xn2Treble, BassTrebleState::yn1Bass, BassTrebleState::yn1Treble, BassTrebleState::yn2Bass, and BassTrebleState::yn2Treble.

Here is the call graph for this function:

◆ InstanceProcess()

size_t BassTrebleBase::Instance::InstanceProcess ( EffectSettings settings,
BassTrebleState data,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)
static

Definition at line 122 of file BassTrebleBase.cpp.

125{
126 auto& ms = GetSettings(settings);
127
128 const float* ibuf = inBlock[0];
129 float* obuf = outBlock[0];
130
131 // Set value to ensure correct rounding
132 double oldBass = DB_TO_LINEAR(ms.mBass);
133 double oldTreble = DB_TO_LINEAR(ms.mTreble);
134
135 data.gain = DB_TO_LINEAR(ms.mGain);
136
137 // Compute coefficients of the low shelf biquand IIR filter
138 if (data.bass != oldBass)
140 data.hzBass, data.slope, ms.mBass, data.samplerate, kBass, data.a0Bass,
141 data.a1Bass, data.a2Bass, data.b0Bass, data.b1Bass, data.b2Bass);
142
143 // Compute coefficients of the high shelf biquand IIR filter
144 if (data.treble != oldTreble)
146 data.hzTreble, data.slope, ms.mTreble, data.samplerate, kTreble,
147 data.a0Treble, data.a1Treble, data.a2Treble, data.b0Treble,
148 data.b1Treble, data.b2Treble);
149
150 for (decltype(blockLen) i = 0; i < blockLen; i++)
151 {
152 obuf[i] = DoFilter(data, ibuf[i]) * data.gain;
153 }
154
155 return blockLen;
156}
@ kTreble
static void Coefficients(double hz, double slope, double gain, double samplerate, int type, double &a0, double &a1, double &a2, double &b0, double &b1, double &b2)
static float DoFilter(BassTrebleState &data, float in)

References BassTrebleState::a0Bass, BassTrebleState::a0Treble, BassTrebleState::a1Bass, BassTrebleState::a1Treble, BassTrebleState::a2Bass, BassTrebleState::a2Treble, BassTrebleState::b0Bass, BassTrebleState::b0Treble, BassTrebleState::b1Bass, BassTrebleState::b1Treble, BassTrebleState::b2Bass, BassTrebleState::b2Treble, BassTrebleState::bass, DB_TO_LINEAR, BassTrebleState::gain, EffectWithSettings< BassTrebleSettings, PerTrackEffect >::GetSettings(), BassTrebleState::hzBass, BassTrebleState::hzTreble, kBass, kTreble, BassTrebleState::samplerate, settings(), BassTrebleState::slope, and BassTrebleState::treble.

Here is the call graph for this function:

◆ ProcessBlock()

size_t BassTrebleBase::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 78 of file BassTrebleBase.cpp.

81{
82 return InstanceProcess(settings, mState, inBlock, outBlock, blockLen);
83}
static size_t InstanceProcess(EffectSettings &settings, BassTrebleState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)

References mState, and settings().

Here is the call graph for this function:

◆ ProcessInitialize()

bool BassTrebleBase::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 71 of file BassTrebleBase.cpp.

73{
75 return true;
76}
static void InstanceInit(EffectSettings &settings, BassTrebleState &data, float sampleRate)

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

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool BassTrebleBase::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 92 of file BassTrebleBase.cpp.

95{
97
98 InstanceInit(settings, slave.mState, sampleRate);
99
100 mSlaves.push_back(slave);
101
102 return true;
103}
const PerTrackEffect & mProcessor
std::vector< BassTrebleBase::Instance > mSlaves

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

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 105 of file BassTrebleBase.cpp.

106{
107 mSlaves.clear();
108
109 return true;
110}

◆ RealtimeInitialize()

bool BassTrebleBase::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 85 of file BassTrebleBase.cpp.

86{
87 SetBlockSize(512);
88 mSlaves.clear();
89 return true;
90}
size_t SetBlockSize(size_t maxBlockSize) override

◆ RealtimeProcess()

size_t BassTrebleBase::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 112 of file BassTrebleBase.cpp.

115{
116 if (group >= mSlaves.size())
117 return 0;
118 return InstanceProcess(
119 settings, mSlaves[group].mState, inbuf, outbuf, numSamples);
120}

References mState, and settings().

Here is the call graph for this function:

Member Data Documentation

◆ mSlaves

std::vector<BassTrebleBase::Instance> BassTrebleBase::Instance::mSlaves

Definition at line 121 of file BassTrebleBase.h.

◆ mState

BassTrebleState BassTrebleBase::Instance::mState

Definition at line 120 of file BassTrebleBase.h.

Referenced by RealtimeAddProcessor().


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