Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
EffectDistortion::Instance Struct Reference
Inheritance diagram for EffectDistortion::Instance:
[legend]
Collaboration diagram for EffectDistortion::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 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 234 of file Distortion.cpp.

Constructor & Destructor Documentation

◆ Instance()

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

Definition at line 238 of file Distortion.cpp.

Member Function Documentation

◆ CopyHalfTable()

void EffectDistortion::Instance::CopyHalfTable ( )

Definition at line 1490 of file Distortion.cpp.

1491{
1492 // Copy negative half of table from positive half
1493 int count = TABLESIZE - 1;
1494 for (int n = 0; n < STEPS; n++) {
1495 mTable[n] = -mTable[count];
1496 count--;
1497 }
1498}
#define TABLESIZE
Definition: Distortion.h:22
#define STEPS
Definition: Distortion.h:21
double mTable[TABLESIZE]
Definition: Distortion.cpp:302

References STEPS, and TABLESIZE.

◆ Cubic()

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

Definition at line 1359 of file Distortion.cpp.

1360{
1361 if (ms.mParam1 == 0.0)
1362 return x;
1363
1364 return x - (std::pow(x, 3.0) / 3.0);
1365}

References EffectDistortionSettings::mParam1.

◆ CubicTable()

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

Definition at line 1333 of file Distortion.cpp.

1334{
1335 double amount = ms.mParam1 * std::sqrt(3.0) / 100.0;
1336 double gain = 1.0;
1337 if (amount != 0.0)
1338 gain = 1.0 / Cubic(ms, std::min(amount, 1.0));
1339
1340 double stepsize = amount / STEPS;
1341 double x = -amount;
1342
1343 if (amount == 0) {
1344 for (int i = 0; i < TABLESIZE; i++) {
1345 mTable[i] = (i / (double)STEPS) - 1.0;
1346 }
1347 }
1348 else {
1349 for (int i = 0; i < TABLESIZE; i++) {
1350 mTable[i] = gain * Cubic(ms, x);
1351 for (int j = 0; j < ms.mRepeats; j++) {
1352 mTable[i] = gain * Cubic(ms, mTable[i] * amount);
1353 }
1354 x += stepsize;
1355 }
1356 }
1357}
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 EffectDistortion::Instance::DCFilter ( EffectDistortionState data,
float  sample 
)

Definition at line 1531 of file Distortion.cpp.

1532{
1533 // Rolling average gives less offset at the start than an IIR filter.
1534 const unsigned int queueLength = std::floor(data.samplerate / 20.0);
1535
1536 data.queuetotal += sample;
1537 data.queuesamples.push(sample);
1538
1539 if (data.queuesamples.size() > queueLength) {
1540 data.queuetotal -= data.queuesamples.front();
1541 data.queuesamples.pop();
1542 }
1543
1544 return sample - (data.queuetotal / data.queuesamples.size());
1545}
std::queue< float > queuesamples
Definition: Distortion.h:40

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

◆ EvenHarmonicTable()

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

Definition at line 1368 of file Distortion.cpp.

1369{
1370 double amount = ms.mParam1 / -100.0;
1371 // double C = std::sin(std::max(0.001, mParams.mParam2) / 100.0) * 10.0;
1372 double C = std::max(0.001, ms.mParam2) / 10.0;
1373
1374 double step = 1.0 / STEPS;
1375 double xval = -1.0;
1376
1377 for (int i = 0; i < TABLESIZE; i++) {
1378 mTable[i] = ((1 + amount) * xval) -
1379 (xval * (amount / std::tanh(C)) * std::tanh(C * xval));
1380 xval += step;
1381 }
1382}

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

◆ ExponentialTable()

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

Definition at line 1281 of file Distortion.cpp.

1282{
1283 double amount = std::min(0.999, DB_TO_LINEAR(-1 * ms.mParam1)); // avoid divide by zero
1284
1285 for (int n = STEPS; n < TABLESIZE; n++) {
1286 double linVal = n/(float)STEPS;
1287 double scale = -1.0 / (1.0 - amount); // unity gain at 0dB
1288 double curve = std::exp((linVal - 1) * std::log(amount));
1289 mTable[n] = scale * (curve -1);
1290 }
1291 CopyHalfTable();
1292}
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:335

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

Here is the call graph for this function:

◆ GetAudioInCount()

unsigned EffectDistortion::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 361 of file Distortion.cpp.

362{
363 return 1;
364}

◆ GetAudioOutCount()

unsigned EffectDistortion::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 366 of file Distortion.cpp.

367{
368 return 1;
369}

◆ HalfSinTable()

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

Definition at line 1315 of file Distortion.cpp.

1316{
1317 int iter = std::floor(ms.mParam1 / 20.0);
1318 double fractionalpart = (ms.mParam1 / 20.0) - iter;
1319 double stepsize = 1.0 / STEPS;
1320 double linVal = 0;
1321
1322 for (int n = STEPS; n < TABLESIZE; n++) {
1323 mTable[n] = linVal;
1324 for (int i = 0; i < iter; i++) {
1325 mTable[n] = std::sin(mTable[n] * M_PI_2);
1326 }
1327 mTable[n] += ((std::sin(mTable[n] * M_PI_2) - mTable[n]) * fractionalpart);
1328 linVal += stepsize;
1329 }
1330 CopyHalfTable();
1331}
#define M_PI_2
Definition: Distortion.cpp:33

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

◆ HardClip()

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

Definition at line 1230 of file Distortion.cpp.

1235{
1236 const double threshold = DB_TO_LINEAR(ms.mThreshold_dB);
1237
1238 double lowThresh = 1 - threshold;
1239 double highThresh = 1 + threshold;
1240
1241 for (int n = 0; n < TABLESIZE; n++) {
1242 if (n < (STEPS * lowThresh))
1243 mTable[n] = - threshold;
1244 else if (n > (STEPS * highThresh))
1245 mTable[n] = threshold;
1246 else
1247 mTable[n] = n/(double)STEPS - 1;
1248
1249 state.mMakeupGain = 1.0 / threshold;
1250 }
1251}

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

◆ HardLimiter()

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

Definition at line 1479 of file Distortion.cpp.

1480{
1481 // The LADSPA "hardLimiter 1413" is basically hard clipping,
1482 // but with a 'kind of' wet/dry mix:
1483 // out = ((wet-residual)*clipped) + (residual*in)
1484 HardClip(state, settings);
1485}
static Settings & settings()
Definition: TrackInfo.cpp:69
void HardClip(EffectDistortionState &, const EffectDistortionSettings &)

References settings().

Here is the call graph for this function:

◆ InstanceInit()

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

Definition at line 655 of file Distortion.cpp.

656{
657 auto& ms = GetSettings(settings);
658
659 data.samplerate = sampleRate;
660 data.skipcount = 0;
661 data.tablechoiceindx = ms.mTableChoiceIndx;
662 data.dcblock = ms.mDCBlock;
663 data.threshold = ms.mThreshold_dB;
664 data.noisefloor = ms.mNoiseFloor;
665 data.param1 = ms.mParam1;
666 data.param2 = ms.mParam2;
667 data.repeats = ms.mRepeats;
668
669 // DC block filter variables
670 data.queuetotal = 0.0;
671
672 //std::queue<float>().swap(data.queuesamples);
673 while (!data.queuesamples.empty())
674 data.queuesamples.pop();
675
676 MakeTable(data, ms);
677
678 return;
679}
sampleCount skipcount
Definition: Distortion.h:30
static EffectDistortionSettings & GetSettings(EffectSettings &settings)
Assume settings originated from MakeSettings() and copies thereof.
Definition: Effect.h:169
void MakeTable(EffectDistortionState &state, const EffectDistortionSettings &ms)

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

Here is the call graph for this function:

◆ InstanceProcess()

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

Definition at line 681 of file Distortion.cpp.

684{
685 auto& ms = GetSettings(settings);
686
687 const float *ibuf = inBlock[0];
688 float *obuf = outBlock[0];
689
690 bool update = (ms.mTableChoiceIndx == data.tablechoiceindx &&
691 ms.mNoiseFloor == data.noisefloor &&
692 ms.mThreshold_dB == data.threshold &&
693 ms.mParam1 == data.param1 &&
694 ms.mParam2 == data.param2 &&
695 ms.mRepeats == data.repeats)? false : true;
696
697 double p1 = ms.mParam1 / 100.0;
698 double p2 = ms.mParam2 / 100.0;
699
700 data.tablechoiceindx = ms.mTableChoiceIndx;
701 data.threshold = ms.mThreshold_dB;
702 data.noisefloor = ms.mNoiseFloor;
703 data.param1 = ms.mParam1;
704 data.repeats = ms.mRepeats;
705
706 for (decltype(blockLen) i = 0; i < blockLen; i++) {
707 if (update && ((data.skipcount++) % skipsamples == 0)) {
708 MakeTable(data, ms);
709 }
710
711 switch (ms.mTableChoiceIndx)
712 {
713 case kHardClip:
714 // Param2 = make-up gain.
715 obuf[i] = WaveShaper(ibuf[i], ms) * ((1 - p2) + (data.mMakeupGain * p2));
716 break;
717 case kSoftClip:
718 // Param2 = make-up gain.
719 obuf[i] = WaveShaper(ibuf[i], ms) * ((1 - p2) + (data.mMakeupGain * p2));
720 break;
721 case kHalfSinCurve:
722 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
723 break;
724 case kExpCurve:
725 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
726 break;
727 case kLogCurve:
728 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
729 break;
730 case kCubic:
731 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
732 break;
733 case kEvenHarmonics:
734 obuf[i] = WaveShaper(ibuf[i], ms);
735 break;
736 case kSinCurve:
737 obuf[i] = WaveShaper(ibuf[i], ms) * p2;
738 break;
739 case kLeveller:
740 obuf[i] = WaveShaper(ibuf[i], ms);
741 break;
742 case kRectifier:
743 obuf[i] = WaveShaper(ibuf[i], ms);
744 break;
745 case kHardLimiter:
746 // Mix equivalent to LADSPA effect's "Wet / Residual" mix
747 obuf[i] = (WaveShaper(ibuf[i], ms) * (p1 - p2)) + (ibuf[i] * p2);
748 break;
749 default:
750 obuf[i] = WaveShaper(ibuf[i], ms);
751 }
752 if (ms.mDCBlock) {
753 obuf[i] = DCFilter(data, obuf[i]);
754 }
755 }
756
757 return blockLen;
758}
#define skipsamples
Definition: Distortion.cpp:72
float DCFilter(EffectDistortionState &data, float sample)
float WaveShaper(float sample, EffectDistortionSettings &ms)

References EffectWithSettings< EffectDistortionSettings, StatelessPerTrackEffect >::GetSettings(), EffectDistortion::kCubic, EffectDistortion::kEvenHarmonics, EffectDistortion::kExpCurve, EffectDistortion::kHalfSinCurve, EffectDistortion::kHardClip, EffectDistortion::kHardLimiter, EffectDistortion::kLeveller, EffectDistortion::kLogCurve, EffectDistortion::kRectifier, EffectDistortion::kSinCurve, EffectDistortion::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 EffectDistortion::Instance::Leveller ( const EffectDistortionSettings ms)

Definition at line 1402 of file Distortion.cpp.

1403{
1404 double noiseFloor = DB_TO_LINEAR(ms.mNoiseFloor);
1405 int numPasses = ms.mRepeats;
1406 double fractionalPass = ms.mParam1 / 100.0;
1407
1408 const int numPoints = 6;
1409 const double gainFactors[numPoints] = { 0.80, 1.00, 1.20, 1.20, 1.00, 0.80 };
1410 double gainLimits[numPoints] = { 0.0001, 0.0, 0.1, 0.3, 0.5, 1.0 };
1411 double addOnValues[numPoints];
1412
1413 gainLimits[1] = noiseFloor;
1414 /* In the original Leveller effect, behaviour was undefined for threshold > 20 dB.
1415 * If we want to support > 20 dB we need to scale the points to keep them non-decreasing.
1416 *
1417 * if (noiseFloor > gainLimits[2]) {
1418 * for (int i = 3; i < numPoints; i++) {
1419 * gainLimits[i] = noiseFloor + ((1 - noiseFloor)*((gainLimits[i] - 0.1) / 0.9));
1420 * }
1421 * gainLimits[2] = noiseFloor;
1422 * }
1423 */
1424
1425 // Calculate add-on values
1426 addOnValues[0] = 0.0;
1427 for (int i = 0; i < numPoints-1; i++) {
1428 addOnValues[i+1] = addOnValues[i] + (gainLimits[i] * (gainFactors[i] - gainFactors[1 + i]));
1429 }
1430
1431 // Positive half of table.
1432 // The original effect increased the 'strength' of the effect by
1433 // repeated passes over the audio data.
1434 // Here we model that more efficiently by repeated passes over a linear table.
1435 for (int n = STEPS; n < TABLESIZE; n++) {
1436 mTable[n] = ((double) (n - STEPS) / (double) STEPS);
1437 for (int j = 0; j < numPasses; j++) {
1438 // Find the highest index for gain adjustment
1439 int index = numPoints - 1;
1440 for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--) {
1441 index = i;
1442 }
1443 // the whole number of 'repeats'
1444 mTable[n] = (mTable[n] * gainFactors[index]) + addOnValues[index];
1445 }
1446 // Extrapolate for fine adjustment.
1447 // tiny fractions are not worth the processing time
1448 if (fractionalPass > 0.001) {
1449 int index = numPoints - 1;
1450 for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--) {
1451 index = i;
1452 }
1453 mTable[n] += fractionalPass * ((mTable[n] * (gainFactors[index] - 1)) + addOnValues[index]);
1454 }
1455 }
1456 CopyHalfTable();
1457}

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

◆ LogarithmicTable()

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

Definition at line 1294 of file Distortion.cpp.

1295{
1296 double amount = ms.mParam1;
1297 double stepsize = 1.0 / STEPS;
1298 double linVal = 0;
1299
1300 if (amount == 0){
1301 for (int n = STEPS; n < TABLESIZE; n++) {
1302 mTable[n] = linVal;
1303 linVal += stepsize;
1304 }
1305 }
1306 else {
1307 for (int n = STEPS; n < TABLESIZE; n++) {
1308 mTable[n] = std::log(1 + (amount * linVal)) / std::log(1 + amount);
1309 linVal += stepsize;
1310 }
1311 }
1312 CopyHalfTable();
1313}

References EffectDistortionSettings::mParam1, STEPS, and TABLESIZE.

◆ LogCurve()

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

Definition at line 1276 of file Distortion.cpp.

1277{
1278 return threshold + ((std::exp(ratio * (threshold - value)) - 1) / -ratio);
1279}

◆ MakeTable()

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

Definition at line 1181 of file Distortion.cpp.

1186{
1187 switch (ms.mTableChoiceIndx)
1188 {
1189 case kHardClip:
1190 HardClip(state, ms);
1191 break;
1192 case kSoftClip:
1193 SoftClip(state, ms);
1194 break;
1195 case kHalfSinCurve:
1196 HalfSinTable(ms);
1197 break;
1198 case kExpCurve:
1199 ExponentialTable(ms);
1200 break;
1201 case kLogCurve:
1202 LogarithmicTable(ms);
1203 break;
1204 case kCubic:
1205 CubicTable(ms);
1206 break;
1207 case kEvenHarmonics:
1209 break;
1210 case kSinCurve:
1211 SineTable(ms);
1212 break;
1213 case kLeveller:
1214 Leveller(ms);
1215 break;
1216 case kRectifier:
1217 Rectifier(ms);
1218 break;
1219 case kHardLimiter:
1220 HardLimiter(state, ms);
1221 break;
1222 }
1223}
void Leveller(const EffectDistortionSettings &)
void LogarithmicTable(const EffectDistortionSettings &)
void CubicTable(const EffectDistortionSettings &)
void HalfSinTable(const EffectDistortionSettings &)
void EvenHarmonicTable(const EffectDistortionSettings &)
void SineTable(const EffectDistortionSettings &)
void Rectifier(const EffectDistortionSettings &)
void SoftClip(EffectDistortionState &, const EffectDistortionSettings &)
void ExponentialTable(const EffectDistortionSettings &)
void HardLimiter(EffectDistortionState &state, const EffectDistortionSettings &)

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

◆ ProcessBlock()

size_t EffectDistortion::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 378 of file Distortion.cpp.

380{
381 return InstanceProcess(settings, mMaster, inBlock, outBlock, blockLen);
382}
size_t InstanceProcess(EffectSettings &settings, EffectDistortionState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
Definition: Distortion.cpp:681
EffectDistortionState mMaster
Definition: Distortion.cpp:304

References settings().

Here is the call graph for this function:

◆ ProcessInitialize()

bool EffectDistortion::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 371 of file Distortion.cpp.

373{
375 return true;
376}
void InstanceInit(EffectDistortionState &data, EffectSettings &settings, float sampleRate)
Definition: Distortion.cpp:655

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

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool EffectDistortion::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 391 of file Distortion.cpp.

393{
395
397
398 mSlaves.push_back(slave);
399
400 return true;
401}
std::vector< EffectDistortionState > mSlaves
Definition: Distortion.cpp:305

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

Here is the call graph for this function:

◆ RealtimeFinalize()

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

Reimplemented from EffectInstance.

Definition at line 403 of file Distortion.cpp.

404{
405 mSlaves.clear();
406
407 return true;
408}

◆ RealtimeInitialize()

bool EffectDistortion::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 384 of file Distortion.cpp.

385{
386 SetBlockSize(512);
387 mSlaves.clear();
388 return true;
389}
size_t SetBlockSize(size_t maxBlockSize) override

◆ RealtimeProcess()

size_t EffectDistortion::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 410 of file Distortion.cpp.

412{
413 if (group >= mSlaves.size())
414 return 0;
415 return InstanceProcess(settings, mSlaves[group], inbuf, outbuf, numSamples);
416}

References settings().

Here is the call graph for this function:

◆ Rectifier()

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

Definition at line 1459 of file Distortion.cpp.

1460{
1461 double amount = (ms.mParam1 / 50.0) - 1;
1462 double stepsize = 1.0 / STEPS;
1463 int index = STEPS;
1464
1465 // positive half of waveform is passed unaltered.
1466 for (int n = 0; n <= STEPS; n++) {
1467 mTable[index] = n * stepsize;
1468 index += 1;
1469 }
1470
1471 // negative half of table
1472 index = STEPS - 1;
1473 for (int n = 1; n <= STEPS; n++) {
1474 mTable[index] = n * stepsize * amount;
1475 index--;
1476 }
1477}

References EffectDistortionSettings::mParam1, and STEPS.

◆ SineTable()

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

Definition at line 1384 of file Distortion.cpp.

1385{
1386 int iter = std::floor(ms.mParam1 / 20.0);
1387 double fractionalpart = (ms.mParam1 / 20.0) - iter;
1388 double stepsize = 1.0 / STEPS;
1389 double linVal = 0.0;
1390
1391 for (int n = STEPS; n < TABLESIZE; n++) {
1392 mTable[n] = linVal;
1393 for (int i = 0; i < iter; i++) {
1394 mTable[n] = (1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0;
1395 }
1396 mTable[n] += (((1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0) - mTable[n]) * fractionalpart;
1397 linVal += stepsize;
1398 }
1399 CopyHalfTable();
1400}
#define M_PI
Definition: Distortion.cpp:30

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

◆ SoftClip()

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

Definition at line 1253 of file Distortion.cpp.

1257{
1258 const double thresholdLinear = DB_TO_LINEAR(ms.mThreshold_dB);
1259
1260 double threshold = 1 + thresholdLinear;
1261 double amount = std::pow(2.0, 7.0 * ms.mParam1 / 100.0); // range 1 to 128
1262 double peak = LogCurve(thresholdLinear, 1.0, amount);
1263 state.mMakeupGain = 1.0 / peak;
1264 mTable[STEPS] = 0.0; // origin
1265
1266 // positive half of table
1267 for (int n = STEPS; n < TABLESIZE; n++) {
1268 if (n < (STEPS * threshold)) // origin to threshold
1269 mTable[n] = n/(float)STEPS - 1;
1270 else
1271 mTable[n] = LogCurve(thresholdLinear, n/(double)STEPS - 1, amount);
1272 }
1273 CopyHalfTable();
1274}
float LogCurve(double threshold, float value, double ratio)

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

◆ WaveShaper()

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

Definition at line 1501 of file Distortion.cpp.

1502{
1503 float out;
1504 int index;
1505 double xOffset;
1506 double amount = 1;
1507
1508 switch (ms.mTableChoiceIndx)
1509 {
1510 // Do any pre-processing here
1511 case kHardClip:
1512 // Pre-gain
1513 amount = ms.mParam1 / 100.0;
1514 sample *= 1+amount;
1515 break;
1516 default: break;
1517 }
1518
1519 index = std::floor(sample * STEPS) + STEPS;
1520 index = wxMax<int>(wxMin<int>(index, 2 * STEPS - 1), 0);
1521 xOffset = ((1 + sample) * STEPS) - index;
1522 xOffset = wxMin<double>(wxMax<double>(xOffset, 0.0), 1.0); // Clip at 0dB
1523
1524 // linear interpolation: y = y0 + (y1-y0)*(x-x0)
1525 out = mTable[index] + (mTable[index + 1] - mTable[index]) * xOffset;
1526
1527 return out;
1528}

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

Member Data Documentation

◆ mMaster

EffectDistortionState EffectDistortion::Instance::mMaster

Definition at line 304 of file Distortion.cpp.

◆ mSlaves

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

Definition at line 305 of file Distortion.cpp.

◆ mTable

double EffectDistortion::Instance::mTable[TABLESIZE]

Definition at line 302 of file Distortion.cpp.


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