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

#include <DistortionBase.h>

Inheritance diagram for DistortionBase::Instance:
[legend]
Collaboration diagram for DistortionBase::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
 
void InstanceInit (EffectDistortionState &data, EffectSettings &settings, float sampleRate)
 
size_t InstanceProcess (EffectSettings &settings, EffectDistortionState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 
void MakeTable (EffectDistortionState &state, const EffectDistortionSettings &ms)
 
void HardClip (EffectDistortionState &, const EffectDistortionSettings &)
 
void SoftClip (EffectDistortionState &, const EffectDistortionSettings &)
 
void ExponentialTable (const EffectDistortionSettings &)
 
void LogarithmicTable (const EffectDistortionSettings &)
 
void HalfSinTable (const EffectDistortionSettings &)
 
void CubicTable (const EffectDistortionSettings &)
 
void EvenHarmonicTable (const EffectDistortionSettings &)
 
void SineTable (const EffectDistortionSettings &)
 
void Leveller (const EffectDistortionSettings &)
 
void Rectifier (const EffectDistortionSettings &)
 
void HardLimiter (EffectDistortionState &state, const EffectDistortionSettings &)
 
void CopyHalfTable ()
 
float LogCurve (double threshold, float value, double ratio)
 
double Cubic (const EffectDistortionSettings &, double x)
 
float WaveShaper (float sample, EffectDistortionSettings &ms)
 
float DCFilter (EffectDistortionState &data, float sample)
 
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
 

Public Attributes

double mTable [TABLESIZE]
 
EffectDistortionState mMaster
 
std::vector< EffectDistortionStatemSlaves
 

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 DistortionBase.h.

Constructor & Destructor Documentation

◆ Instance()

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

Definition at line 96 of file DistortionBase.h.

Member Function Documentation

◆ CopyHalfTable()

void DistortionBase::Instance::CopyHalfTable ( )

Definition at line 669 of file DistortionBase.cpp.

670{
671 // Copy negative half of table from positive half
672 int count = TABLESIZE - 1;
673 for (int n = 0; n < STEPS; n++)
674 {
675 mTable[n] = -mTable[count];
676 count--;
677 }
678}
#define STEPS
#define TABLESIZE
double mTable[TABLESIZE]

References STEPS, and TABLESIZE.

◆ Cubic()

double DistortionBase::Instance::Cubic ( const EffectDistortionSettings ms,
double  x 
)
inline

Definition at line 519 of file DistortionBase.cpp.

520{
521 if (ms.mParam1 == 0.0)
522 return x;
523
524 return x - (std::pow(x, 3.0) / 3.0);
525}

References EffectDistortionSettings::mParam1.

◆ CubicTable()

void DistortionBase::Instance::CubicTable ( const EffectDistortionSettings ms)

Definition at line 487 of file DistortionBase.cpp.

488{
489 double amount = ms.mParam1 * std::sqrt(3.0) / 100.0;
490 double gain = 1.0;
491 if (amount != 0.0)
492 gain = 1.0 / Cubic(ms, std::min(amount, 1.0));
493
494 double stepsize = amount / STEPS;
495 double x = -amount;
496
497 if (amount == 0)
498 {
499 for (int i = 0; i < TABLESIZE; i++)
500 {
501 mTable[i] = (i / (double)STEPS) - 1.0;
502 }
503 }
504 else
505 {
506 for (int i = 0; i < TABLESIZE; i++)
507 {
508 mTable[i] = gain * Cubic(ms, x);
509 for (int j = 0; j < ms.mRepeats; j++)
510 {
511 mTable[i] = gain * Cubic(ms, mTable[i] * amount);
512 }
513 x += stepsize;
514 }
515 }
516}
int min(int a, int b)
__finl float_x4 __vecc sqrt(const float_x4 &a)
double Cubic(const EffectDistortionSettings &, double x)

References min(), EffectDistortionSettings::mParam1, EffectDistortionSettings::mRepeats, staffpad::audio::simd::sqrt(), STEPS, and TABLESIZE.

Here is the call graph for this function:

◆ DCFilter()

float DistortionBase::Instance::DCFilter ( EffectDistortionState data,
float  sample 
)

Definition at line 711 of file DistortionBase.cpp.

713{
714 // Rolling average gives less offset at the start than an IIR filter.
715 const unsigned int queueLength = std::floor(data.samplerate / 20.0);
716
717 data.queuetotal += sample;
718 data.queuesamples.push(sample);
719
720 if (data.queuesamples.size() > queueLength)
721 {
722 data.queuetotal -= data.queuesamples.front();
723 data.queuesamples.pop();
724 }
725
726 return sample - (data.queuetotal / data.queuesamples.size());
727}
std::queue< float > queuesamples

References EffectDistortionState::queuesamples, EffectDistortionState::queuetotal, and EffectDistortionState::samplerate.

◆ EvenHarmonicTable()

void DistortionBase::Instance::EvenHarmonicTable ( const EffectDistortionSettings ms)

Definition at line 527 of file DistortionBase.cpp.

529{
530 double amount = ms.mParam1 / -100.0;
531 // double C = std::sin(std::max(0.001, mParams.mParam2) / 100.0) * 10.0;
532 double C = std::max(0.001, ms.mParam2) / 10.0;
533
534 double step = 1.0 / STEPS;
535 double xval = -1.0;
536
537 for (int i = 0; i < TABLESIZE; i++)
538 {
539 mTable[i] = ((1 + amount) * xval) -
540 (xval * (amount / std::tanh(C)) * std::tanh(C * xval));
541 xval += step;
542 }
543}

References anonymous_namespace{DynamicRangeProcessorEditor.cpp}::C, EffectDistortionSettings::mParam1, EffectDistortionSettings::mParam2, STEPS, and TABLESIZE.

◆ ExponentialTable()

void DistortionBase::Instance::ExponentialTable ( const EffectDistortionSettings ms)

Definition at line 424 of file DistortionBase.cpp.

426{
427 double amount =
428 std::min(0.999, DB_TO_LINEAR(-1 * ms.mParam1)); // avoid divide by zero
429
430 for (int n = STEPS; n < TABLESIZE; n++)
431 {
432 double linVal = n / (float)STEPS;
433 double scale = -1.0 / (1.0 - amount); // unity gain at 0dB
434 double curve = std::exp((linVal - 1) * std::log(amount));
435 mTable[n] = scale * (curve - 1);
436 }
438}
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:338

References DB_TO_LINEAR, min(), EffectDistortionSettings::mParam1, STEPS, and TABLESIZE.

Here is the call graph for this function:

◆ GetAudioInCount()

unsigned DistortionBase::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 127 of file DistortionBase.cpp.

128{
129 return 1;
130}

◆ GetAudioOutCount()

unsigned DistortionBase::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 132 of file DistortionBase.cpp.

133{
134 return 1;
135}

◆ HalfSinTable()

void DistortionBase::Instance::HalfSinTable ( const EffectDistortionSettings ms)

Definition at line 466 of file DistortionBase.cpp.

467{
468 int iter = std::floor(ms.mParam1 / 20.0);
469 double fractionalpart = (ms.mParam1 / 20.0) - iter;
470 double stepsize = 1.0 / STEPS;
471 double linVal = 0;
472
473 for (int n = STEPS; n < TABLESIZE; n++)
474 {
475 mTable[n] = linVal;
476 for (int i = 0; i < iter; i++)
477 {
478 mTable[n] = std::sin(mTable[n] * M_PI_2);
479 }
480 mTable[n] +=
481 ((std::sin(mTable[n] * M_PI_2) - mTable[n]) * fractionalpart);
482 linVal += stepsize;
483 }
485}
#define M_PI_2
Definition: Distortion.cpp:25

References M_PI_2, EffectDistortionSettings::mParam1, STEPS, and TABLESIZE.

◆ HardClip()

void DistortionBase::Instance::HardClip ( EffectDistortionState state,
const EffectDistortionSettings ms 
)

Definition at line 375 of file DistortionBase.cpp.

377{
378 const double threshold = DB_TO_LINEAR(ms.mThreshold_dB);
379
380 double lowThresh = 1 - threshold;
381 double highThresh = 1 + threshold;
382
383 for (int n = 0; n < TABLESIZE; n++)
384 {
385 if (n < (STEPS * lowThresh))
386 mTable[n] = -threshold;
387 else if (n > (STEPS * highThresh))
388 mTable[n] = threshold;
389 else
390 mTable[n] = n / (double)STEPS - 1;
391
392 state.mMakeupGain = 1.0 / threshold;
393 }
394}

References DB_TO_LINEAR, EffectDistortionState::mMakeupGain, EffectDistortionSettings::mThreshold_dB, STEPS, and TABLESIZE.

◆ HardLimiter()

void DistortionBase::Instance::HardLimiter ( EffectDistortionState state,
const EffectDistortionSettings settings 
)

Definition at line 658 of file DistortionBase.cpp.

660{
661 // The LADSPA "hardLimiter 1413" is basically hard clipping,
662 // but with a 'kind of' wet/dry mix:
663 // out = ((wet-residual)*clipped) + (residual*in)
664 HardClip(state, settings);
665}
static Settings & settings()
Definition: TrackInfo.cpp:51
void HardClip(EffectDistortionState &, const EffectDistortionSettings &)

References settings().

Here is the call graph for this function:

◆ InstanceInit()

void DistortionBase::Instance::InstanceInit ( EffectDistortionState data,
EffectSettings settings,
float  sampleRate 
)

Definition at line 218 of file DistortionBase.cpp.

220{
221 auto& ms = GetSettings(settings);
222
223 data.samplerate = sampleRate;
224 data.skipcount = 0;
225 data.tablechoiceindx = ms.mTableChoiceIndx;
226 data.dcblock = ms.mDCBlock;
227 data.threshold = ms.mThreshold_dB;
228 data.noisefloor = ms.mNoiseFloor;
229 data.param1 = ms.mParam1;
230 data.param2 = ms.mParam2;
231 data.repeats = ms.mRepeats;
232
233 // DC block filter variables
234 data.queuetotal = 0.0;
235
236 // std::queue<float>().swap(data.queuesamples);
237 while (!data.queuesamples.empty())
238 data.queuesamples.pop();
239
240 MakeTable(data, ms);
241
242 return;
243}
static EffectDistortionSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:166
void MakeTable(EffectDistortionState &state, const EffectDistortionSettings &ms)

References EffectDistortionState::dcblock, EffectWithSettings< EffectDistortionSettings, PerTrackEffect >::GetSettings(), EffectDistortionState::noisefloor, EffectDistortionState::param1, EffectDistortionState::param2, EffectDistortionState::queuesamples, EffectDistortionState::queuetotal, EffectDistortionState::repeats, EffectDistortionState::samplerate, anonymous_namespace{ClipSegmentTest.cpp}::sampleRate, settings(), EffectDistortionState::skipcount, EffectDistortionState::tablechoiceindx, and EffectDistortionState::threshold.

Here is the call graph for this function:

◆ InstanceProcess()

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

Definition at line 245 of file DistortionBase.cpp.

248{
249 auto& ms = GetSettings(settings);
250
251 const float* ibuf = inBlock[0];
252 float* obuf = outBlock[0];
253
254 bool update =
255 (ms.mTableChoiceIndx == data.tablechoiceindx &&
256 ms.mNoiseFloor == data.noisefloor &&
257 ms.mThreshold_dB == data.threshold && ms.mParam1 == data.param1 &&
258 ms.mParam2 == data.param2 && ms.mRepeats == data.repeats) ?
259 false :
260 true;
261
262 double p1 = ms.mParam1 / 100.0;
263 double p2 = ms.mParam2 / 100.0;
264
265 data.tablechoiceindx = ms.mTableChoiceIndx;
266 data.threshold = ms.mThreshold_dB;
267 data.noisefloor = ms.mNoiseFloor;
268 data.param1 = ms.mParam1;
269 data.repeats = ms.mRepeats;
270
271 for (decltype(blockLen) i = 0; i < blockLen; i++)
272 {
273 if (update && ((data.skipcount++) % skipsamples == 0))
274 {
275 MakeTable(data, ms);
276 }
277
278 switch (ms.mTableChoiceIndx)
279 {
280 case kHardClip:
281 // Param2 = make-up gain.
282 obuf[i] =
283 WaveShaper(ibuf[i], ms) * ((1 - p2) + (data.mMakeupGain * p2));
284 break;
285 case kSoftClip:
286 // Param2 = make-up gain.
287 obuf[i] =
288 WaveShaper(ibuf[i], ms) * ((1 - p2) + (data.mMakeupGain * p2));
289 break;
290 case kHalfSinCurve:
291 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
292 break;
293 case kExpCurve:
294 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
295 break;
296 case kLogCurve:
297 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
298 break;
299 case kCubic:
300 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
301 break;
302 case kEvenHarmonics:
303 obuf[i] = WaveShaper(ibuf[i], ms);
304 break;
305 case kSinCurve:
306 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
307 break;
308 case kLeveller:
309 obuf[i] = WaveShaper(ibuf[i], ms);
310 break;
311 case kRectifier:
312 obuf[i] = WaveShaper(ibuf[i], ms);
313 break;
314 case kHardLimiter:
315 // Mix equivalent to LADSPA effect's "Wet / Residual" mix
316 obuf[i] = (WaveShaper(ibuf[i], ms) * (p1 - p2)) + (ibuf[i] * p2);
317 break;
318 default:
319 obuf[i] = WaveShaper(ibuf[i], ms);
320 }
321 if (ms.mDCBlock)
322 {
323 obuf[i] = DCFilter(data, obuf[i]);
324 }
325 }
326
327 return blockLen;
328}
#define skipsamples
float DCFilter(EffectDistortionState &data, float sample)
float WaveShaper(float sample, EffectDistortionSettings &ms)

References EffectWithSettings< EffectDistortionSettings, PerTrackEffect >::GetSettings(), DistortionBase::kCubic, DistortionBase::kEvenHarmonics, DistortionBase::kExpCurve, DistortionBase::kHalfSinCurve, DistortionBase::kHardClip, DistortionBase::kHardLimiter, DistortionBase::kLeveller, DistortionBase::kLogCurve, DistortionBase::kRectifier, DistortionBase::kSinCurve, DistortionBase::kSoftClip, EffectDistortionState::mMakeupGain, EffectDistortionState::noisefloor, EffectDistortionState::param1, EffectDistortionState::param2, EffectDistortionState::repeats, settings(), EffectDistortionState::skipcount, skipsamples, EffectDistortionState::tablechoiceindx, and EffectDistortionState::threshold.

Here is the call graph for this function:

◆ Leveller()

void DistortionBase::Instance::Leveller ( const EffectDistortionSettings ms)

Definition at line 567 of file DistortionBase.cpp.

568{
569 double noiseFloor = DB_TO_LINEAR(ms.mNoiseFloor);
570 int numPasses = ms.mRepeats;
571 double fractionalPass = ms.mParam1 / 100.0;
572
573 const int numPoints = 6;
574 const double gainFactors[numPoints] = { 0.80, 1.00, 1.20, 1.20, 1.00, 0.80 };
575 double gainLimits[numPoints] = { 0.0001, 0.0, 0.1, 0.3, 0.5, 1.0 };
576 double addOnValues[numPoints];
577
578 gainLimits[1] = noiseFloor;
579 /* In the original Leveller effect, behaviour was undefined for threshold >
580 * 20 dB. If we want to support > 20 dB we need to scale the points to keep
581 * them non-decreasing.
582 *
583 * if (noiseFloor > gainLimits[2]) {
584 * for (int i = 3; i < numPoints; i++) {
585 * gainLimits[i] = noiseFloor + ((1 - noiseFloor)*((gainLimits[i] - 0.1) /
586 * 0.9));
587 * }
588 * gainLimits[2] = noiseFloor;
589 * }
590 */
591
592 // Calculate add-on values
593 addOnValues[0] = 0.0;
594 for (int i = 0; i < numPoints - 1; i++)
595 {
596 addOnValues[i + 1] =
597 addOnValues[i] +
598 (gainLimits[i] * (gainFactors[i] - gainFactors[1 + i]));
599 }
600
601 // Positive half of table.
602 // The original effect increased the 'strength' of the effect by
603 // repeated passes over the audio data.
604 // Here we model that more efficiently by repeated passes over a linear
605 // table.
606 for (int n = STEPS; n < TABLESIZE; n++)
607 {
608 mTable[n] = ((double)(n - STEPS) / (double)STEPS);
609 for (int j = 0; j < numPasses; j++)
610 {
611 // Find the highest index for gain adjustment
612 int index = numPoints - 1;
613 for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--)
614 {
615 index = i;
616 }
617 // the whole number of 'repeats'
618 mTable[n] = (mTable[n] * gainFactors[index]) + addOnValues[index];
619 }
620 // Extrapolate for fine adjustment.
621 // tiny fractions are not worth the processing time
622 if (fractionalPass > 0.001)
623 {
624 int index = numPoints - 1;
625 for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--)
626 {
627 index = i;
628 }
629 mTable[n] += fractionalPass * ((mTable[n] * (gainFactors[index] - 1)) +
630 addOnValues[index]);
631 }
632 }
634}

References DB_TO_LINEAR, EffectDistortionSettings::mNoiseFloor, EffectDistortionSettings::mParam1, EffectDistortionSettings::mRepeats, STEPS, and TABLESIZE.

◆ LogarithmicTable()

void DistortionBase::Instance::LogarithmicTable ( const EffectDistortionSettings ms)

Definition at line 440 of file DistortionBase.cpp.

442{
443 double amount = ms.mParam1;
444 double stepsize = 1.0 / STEPS;
445 double linVal = 0;
446
447 if (amount == 0)
448 {
449 for (int n = STEPS; n < TABLESIZE; n++)
450 {
451 mTable[n] = linVal;
452 linVal += stepsize;
453 }
454 }
455 else
456 {
457 for (int n = STEPS; n < TABLESIZE; n++)
458 {
459 mTable[n] = std::log(1 + (amount * linVal)) / std::log(1 + amount);
460 linVal += stepsize;
461 }
462 }
464}

References EffectDistortionSettings::mParam1, STEPS, and TABLESIZE.

◆ LogCurve()

float DistortionBase::Instance::LogCurve ( double  threshold,
float  value,
double  ratio 
)
inline

Definition at line 418 of file DistortionBase.cpp.

420{
421 return threshold + ((std::exp(ratio * (threshold - value)) - 1) / -ratio);
422}

◆ MakeTable()

void DistortionBase::Instance::MakeTable ( EffectDistortionState state,
const EffectDistortionSettings ms 
)

Definition at line 330 of file DistortionBase.cpp.

332{
333 switch (ms.mTableChoiceIndx)
334 {
335 case kHardClip:
336 HardClip(state, ms);
337 break;
338 case kSoftClip:
339 SoftClip(state, ms);
340 break;
341 case kHalfSinCurve:
342 HalfSinTable(ms);
343 break;
344 case kExpCurve:
346 break;
347 case kLogCurve:
349 break;
350 case kCubic:
351 CubicTable(ms);
352 break;
353 case kEvenHarmonics:
355 break;
356 case kSinCurve:
357 SineTable(ms);
358 break;
359 case kLeveller:
360 Leveller(ms);
361 break;
362 case kRectifier:
363 Rectifier(ms);
364 break;
365 case kHardLimiter:
366 HardLimiter(state, ms);
367 break;
368 }
369}
void Rectifier(const EffectDistortionSettings &)
void SineTable(const EffectDistortionSettings &)
void EvenHarmonicTable(const EffectDistortionSettings &)
void LogarithmicTable(const EffectDistortionSettings &)
void HardLimiter(EffectDistortionState &state, const EffectDistortionSettings &)
void HalfSinTable(const EffectDistortionSettings &)
void ExponentialTable(const EffectDistortionSettings &)
void Leveller(const EffectDistortionSettings &)
void CubicTable(const EffectDistortionSettings &)
void SoftClip(EffectDistortionState &, const EffectDistortionSettings &)

References DistortionBase::kCubic, DistortionBase::kEvenHarmonics, DistortionBase::kExpCurve, DistortionBase::kHalfSinCurve, DistortionBase::kHardClip, DistortionBase::kHardLimiter, DistortionBase::kLeveller, DistortionBase::kLogCurve, DistortionBase::kRectifier, DistortionBase::kSinCurve, DistortionBase::kSoftClip, and EffectDistortionSettings::mTableChoiceIndx.

◆ ProcessBlock()

size_t DistortionBase::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 144 of file DistortionBase.cpp.

147{
148 return InstanceProcess(settings, mMaster, inBlock, outBlock, blockLen);
149}
size_t InstanceProcess(EffectSettings &settings, EffectDistortionState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
EffectDistortionState mMaster

References settings().

Here is the call graph for this function:

◆ ProcessInitialize()

bool DistortionBase::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 137 of file DistortionBase.cpp.

139{
141 return true;
142}
void InstanceInit(EffectDistortionState &data, EffectSettings &settings, float sampleRate)

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

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool DistortionBase::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 158 of file DistortionBase.cpp.

160{
162
164
165 mSlaves.push_back(slave);
166
167 return true;
168}
std::vector< EffectDistortionState > mSlaves

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

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 170 of file DistortionBase.cpp.

171{
172 mSlaves.clear();
173
174 return true;
175}

◆ RealtimeInitialize()

bool DistortionBase::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 151 of file DistortionBase.cpp.

152{
153 SetBlockSize(512);
154 mSlaves.clear();
155 return true;
156}
size_t SetBlockSize(size_t maxBlockSize) override

◆ RealtimeProcess()

size_t DistortionBase::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 177 of file DistortionBase.cpp.

180{
181 if (group >= mSlaves.size())
182 return 0;
183 return InstanceProcess(settings, mSlaves[group], inbuf, outbuf, numSamples);
184}

References settings().

Here is the call graph for this function:

◆ Rectifier()

void DistortionBase::Instance::Rectifier ( const EffectDistortionSettings ms)

Definition at line 636 of file DistortionBase.cpp.

637{
638 double amount = (ms.mParam1 / 50.0) - 1;
639 double stepsize = 1.0 / STEPS;
640 int index = STEPS;
641
642 // positive half of waveform is passed unaltered.
643 for (int n = 0; n <= STEPS; n++)
644 {
645 mTable[index] = n * stepsize;
646 index += 1;
647 }
648
649 // negative half of table
650 index = STEPS - 1;
651 for (int n = 1; n <= STEPS; n++)
652 {
653 mTable[index] = n * stepsize * amount;
654 index--;
655 }
656}

References EffectDistortionSettings::mParam1, and STEPS.

◆ SineTable()

void DistortionBase::Instance::SineTable ( const EffectDistortionSettings ms)

Definition at line 545 of file DistortionBase.cpp.

546{
547 int iter = std::floor(ms.mParam1 / 20.0);
548 double fractionalpart = (ms.mParam1 / 20.0) - iter;
549 double stepsize = 1.0 / STEPS;
550 double linVal = 0.0;
551
552 for (int n = STEPS; n < TABLESIZE; n++)
553 {
554 mTable[n] = linVal;
555 for (int i = 0; i < iter; i++)
556 {
557 mTable[n] = (1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0;
558 }
559 mTable[n] +=
560 (((1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0) - mTable[n]) *
561 fractionalpart;
562 linVal += stepsize;
563 }
565}
#define M_PI
Definition: Distortion.cpp:22

References M_PI, M_PI_2, EffectDistortionSettings::mParam1, STEPS, and TABLESIZE.

◆ SoftClip()

void DistortionBase::Instance::SoftClip ( EffectDistortionState state,
const EffectDistortionSettings ms 
)

Definition at line 396 of file DistortionBase.cpp.

398{
399 const double thresholdLinear = DB_TO_LINEAR(ms.mThreshold_dB);
400
401 double threshold = 1 + thresholdLinear;
402 double amount = std::pow(2.0, 7.0 * ms.mParam1 / 100.0); // range 1 to 128
403 double peak = LogCurve(thresholdLinear, 1.0, amount);
404 state.mMakeupGain = 1.0 / peak;
405 mTable[STEPS] = 0.0; // origin
406
407 // positive half of table
408 for (int n = STEPS; n < TABLESIZE; n++)
409 {
410 if (n < (STEPS * threshold)) // origin to threshold
411 mTable[n] = n / (float)STEPS - 1;
412 else
413 mTable[n] = LogCurve(thresholdLinear, n / (double)STEPS - 1, amount);
414 }
416}
float LogCurve(double threshold, float value, double ratio)

References DB_TO_LINEAR, EffectDistortionState::mMakeupGain, EffectDistortionSettings::mParam1, EffectDistortionSettings::mThreshold_dB, STEPS, and TABLESIZE.

◆ WaveShaper()

float DistortionBase::Instance::WaveShaper ( float  sample,
EffectDistortionSettings ms 
)

Definition at line 680 of file DistortionBase.cpp.

682{
683 float out;
684 int index;
685 double xOffset;
686 double amount = 1;
687
688 switch (ms.mTableChoiceIndx)
689 {
690 // Do any pre-processing here
691 case kHardClip:
692 // Pre-gain
693 amount = ms.mParam1 / 100.0;
694 sample *= 1 + amount;
695 break;
696 default:
697 break;
698 }
699
700 index = std::floor(sample * STEPS) + STEPS;
701 index = std::max<int>(std::min<int>(index, 2 * STEPS - 1), 0);
702 xOffset = ((1 + sample) * STEPS) - index;
703 xOffset = std::min<double>(std::max<double>(xOffset, 0.0), 1.0); // Clip at 0dB
704
705 // linear interpolation: y = y0 + (y1-y0)*(x-x0)
706 out = mTable[index] + (mTable[index + 1] - mTable[index]) * xOffset;
707
708 return out;
709}

References DistortionBase::kHardClip, EffectDistortionSettings::mParam1, EffectDistortionSettings::mTableChoiceIndx, and STEPS.

Member Data Documentation

◆ mMaster

EffectDistortionState DistortionBase::Instance::mMaster

Definition at line 180 of file DistortionBase.h.

◆ mSlaves

std::vector<EffectDistortionState> DistortionBase::Instance::mSlaves

Definition at line 181 of file DistortionBase.h.

◆ mTable

double DistortionBase::Instance::mTable[TABLESIZE]

Definition at line 178 of file DistortionBase.h.


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