Audacity  3.0.3
Distortion.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Distortion.cpp
6 
7  Steve Daulton
8 
9  // TODO: Add a graph display of the waveshaper equation.
10  // TODO: Allow the user to draw the graph.
11 
12 ******************************************************************//*******************************************************************/
18 
19 
20 #include "Distortion.h"
21 #include "LoadEffects.h"
22 
23 #include <cmath>
24 #include <algorithm>
25 #define _USE_MATH_DEFINES
26 
27 // Belt and braces
28 #ifndef M_PI
29 #define M_PI 3.1415926535897932384626433832795
30 #endif
31 #ifndef M_PI_2
32 #define M_PI_2 1.57079632679489661923132169163975
33 #endif
34 
35 #include <wx/checkbox.h>
36 #include <wx/choice.h>
37 #include <wx/intl.h>
38 #include <wx/valgen.h>
39 #include <wx/log.h>
40 #include <wx/slider.h>
41 #include <wx/stattext.h>
42 
43 #include "../Prefs.h"
44 #include "../Shuttle.h"
45 #include "../ShuttleGui.h"
46 #include "../widgets/valnum.h"
47 
49 {
62 };
63 
65 {
66  { XO("Hard Clipping") },
67  { XO("Soft Clipping") },
68  { XO("Soft Overdrive") },
69  { XO("Medium Overdrive") },
70  { XO("Hard Overdrive") },
71  { XO("Cubic Curve (odd harmonics)") },
72  { XO("Even Harmonics") },
73  { XO("Expand and Compress") },
74  { XO("Leveller") },
75  { XO("Rectifier Distortion") },
76  { XO("Hard Limiter 1413") }
77 };
78 
79 // Define keys, defaults, minimums, and maximums for the effect parameters
80 // (Note: 'Repeats' is the total number of times the effect is applied.)
81 //
82 // Name Type Key Def Min Max Scale
83 Param( TableTypeIndx, int, wxT("Type"), 0, 0, nTableTypes-1, 1 );
84 Param( DCBlock, bool, wxT("DC Block"), false, false, true, 1 );
85 Param( Threshold_dB, double, wxT("Threshold dB"), -6.0, -100.0, 0.0, 1000.0f );
86 Param( NoiseFloor, double, wxT("Noise Floor"), -70.0, -80.0, -20.0, 1 );
87 Param( Param1, double, wxT("Parameter 1"), 50.0, 0.0, 100.0, 1 );
88 Param( Param2, double, wxT("Parameter 2"), 50.0, 0.0, 100.0, 1 );
89 Param( Repeats, int, wxT("Repeats"), 1, 0, 5, 1 );
90 
91 // How many samples are processed before recomputing the lookup table again
92 #define skipsamples 1000
93 
94 const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB);
95 
96 static const struct
97 {
100 }
101 FactoryPresets[] =
102 {
103  // Table DCBlock threshold floor Param1 Param2 Repeats
104  // Defaults: 0 false -6.0 -70.0(off) 50.0 50.0 1
105  //
106  // xgettext:no-c-format
107  { XO("Hard clip -12dB, 80% make-up gain"), { 0, 0, -12.0, -70.0, 0.0, 80.0, 0 } },
108  // xgettext:no-c-format
109  { XO("Soft clip -12dB, 80% make-up gain"), { 1, 0, -12.0, -70.0, 50.0, 80.0, 0 } },
110  { XO("Fuzz Box"), { 1, 0, -30.0, -70.0, 80.0, 80.0, 0 } },
111  { XO("Walkie-talkie"), { 1, 0, -50.0, -70.0, 60.0, 80.0, 0 } },
112  { XO("Blues drive sustain"), { 2, 0, -6.0, -70.0, 30.0, 80.0, 0 } },
113  { XO("Light Crunch Overdrive"), { 3, 0, -6.0, -70.0, 20.0, 80.0, 0 } },
114  { XO("Heavy Overdrive"), { 4, 0, -6.0, -70.0, 90.0, 80.0, 0 } },
115  { XO("3rd Harmonic (Perfect Fifth)"), { 5, 0, -6.0, -70.0, 100.0, 60.0, 0 } },
116  { XO("Valve Overdrive"), { 6, 1, -6.0, -70.0, 30.0, 40.0, 0 } },
117  { XO("2nd Harmonic (Octave)"), { 6, 1, -6.0, -70.0, 50.0, 0.0, 0 } },
118  { XO("Gated Expansion Distortion"), { 7, 0, -6.0, -70.0, 30.0, 80.0, 0 } },
119  { XO("Leveller, Light, -70dB noise floor"), { 8, 0, -6.0, -70.0, 0.0, 50.0, 1 } },
120  { XO("Leveller, Moderate, -70dB noise floor"), { 8, 0, -6.0, -70.0, 0.0, 50.0, 2 } },
121  { XO("Leveller, Heavy, -70dB noise floor"), { 8, 0, -6.0, -70.0, 0.0, 50.0, 3 } },
122  { XO("Leveller, Heavier, -70dB noise floor"), { 8, 0, -6.0, -70.0, 0.0, 50.0, 4 } },
123  { XO("Leveller, Heaviest, -70dB noise floor"), { 8, 0, -6.0, -70.0, 0.0, 50.0, 5 } },
124  { XO("Half-wave Rectifier"), { 9, 0, -6.0, -70.0, 50.0, 50.0, 0 } },
125  { XO("Full-wave Rectifier"), { 9, 0, -6.0, -70.0, 100.0, 50.0, 0 } },
126  { XO("Full-wave Rectifier (DC blocked)"), { 9, 1, -6.0, -70.0, 100.0, 50.0, 0 } },
127  { XO("Percussion Limiter"), {10, 0, -12.0, -70.0, 100.0, 30.0, 0 } },
128 };
129 
131 {
132  static const TranslatableString names[] = {
133  XO("Upper Threshold"),
134  XO("Noise Floor"),
135  XO("Parameter 1"),
136  XO("Parameter 2"),
137  XO("Number of repeats"),
138  };
139 
140  return names[ index ];
141 }
142 
143 //
144 // EffectDistortion
145 //
146 
148 { XO("Distortion") };
149 
151 
152 BEGIN_EVENT_TABLE(EffectDistortion, wxEvtHandler)
154  EVT_CHECKBOX(ID_DCBlock, EffectDistortion::OnDCBlockCheckbox)
159  EVT_TEXT(ID_Param1, EffectDistortion::OnParam1Text)
160  EVT_SLIDER(ID_Param1, EffectDistortion::OnParam1Slider)
161  EVT_TEXT(ID_Param2, EffectDistortion::OnParam2Text)
162  EVT_SLIDER(ID_Param2, EffectDistortion::OnParam2Slider)
163  EVT_TEXT(ID_Repeats, EffectDistortion::OnRepeatsText)
164  EVT_SLIDER(ID_Repeats, EffectDistortion::OnRepeatsSlider)
166 
168 {
169  wxASSERT(nTableTypes == WXSIZEOF(kTableTypeStrings));
170 
171  mParams.mTableChoiceIndx = DEF_TableTypeIndx;
172  mParams.mDCBlock = DEF_DCBlock;
173  mParams.mThreshold_dB = DEF_Threshold_dB;
174  mThreshold = DB_TO_LINEAR(mParams.mThreshold_dB);
175  mParams.mNoiseFloor = DEF_NoiseFloor;
176  mParams.mParam1 = DEF_Param1;
177  mParams.mParam2 = DEF_Param2;
178  mParams.mRepeats = DEF_Repeats;
179  mMakeupGain = 1.0;
180  mbSavedFilterState = DEF_DCBlock;
181 
182  SetLinearEffectFlag(false);
183 }
184 
186 {
187 }
188 
189 // ComponentInterface implementation
190 
192 {
193  return Symbol;
194 }
195 
197 {
198  return XO("Waveshaping distortion effect");
199 }
200 
202 {
203  return wxT("Distortion");
204 }
205 
206 // EffectDefinitionInterface implementation
207 
209 {
210  return EffectTypeProcess;
211 }
212 
214 {
215 #if defined(EXPERIMENTAL_REALTIME_AUDACITY_EFFECTS)
216  return true;
217 #else
218  return false;
219 #endif
220 }
221 
222 // EffectClientInterface implementation
223 
225 {
226  return 1;
227 }
228 
230 {
231  return 1;
232 }
233 
234 bool EffectDistortion::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap))
235 {
237  return true;
238 }
239 
240 size_t EffectDistortion::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen)
241 {
242  return InstanceProcess(mMaster, inBlock, outBlock, blockLen);
243 }
244 
246 {
247  SetBlockSize(512);
248 
249  mSlaves.clear();
250 
251  return true;
252 }
253 
254 bool EffectDistortion::RealtimeAddProcessor(unsigned WXUNUSED(numChannels), float sampleRate)
255 {
256  EffectDistortionState slave;
257 
258  InstanceInit(slave, sampleRate);
259 
260  mSlaves.push_back(slave);
261 
262  return true;
263 }
264 
266 {
267  mSlaves.clear();
268 
269  return true;
270 }
271 
273  float **inbuf,
274  float **outbuf,
275  size_t numSamples)
276 {
277 
278  return InstanceProcess(mSlaves[group], inbuf, outbuf, numSamples);
279 }
281  S.SHUTTLE_ENUM_PARAM( mParams.mTableChoiceIndx, TableTypeIndx,
283  S.SHUTTLE_PARAM( mParams.mDCBlock, DCBlock );
284  S.SHUTTLE_PARAM( mParams.mThreshold_dB, Threshold_dB );
285  S.SHUTTLE_PARAM( mParams.mNoiseFloor, NoiseFloor );
286  S.SHUTTLE_PARAM( mParams.mParam1, Param1 );
287  S.SHUTTLE_PARAM( mParams.mParam2, Param2 );
288  S.SHUTTLE_PARAM( mParams.mRepeats, Repeats );
289  return true;
290 }
291 
293 {
294  parms.Write(KEY_TableTypeIndx,
296  parms.Write(KEY_DCBlock, mParams.mDCBlock);
297  parms.Write(KEY_Threshold_dB, mParams.mThreshold_dB);
298  parms.Write(KEY_NoiseFloor, mParams.mNoiseFloor);
299  parms.Write(KEY_Param1, mParams.mParam1);
300  parms.Write(KEY_Param2, mParams.mParam2);
301  parms.Write(KEY_Repeats, mParams.mRepeats);
302 
303  return true;
304 }
305 
307 {
309  ReadAndVerifyBool(DCBlock);
310  ReadAndVerifyDouble(Threshold_dB);
311  ReadAndVerifyDouble(NoiseFloor);
312  ReadAndVerifyDouble(Param1);
313  ReadAndVerifyDouble(Param2);
314  ReadAndVerifyInt(Repeats);
315 
316  mParams.mTableChoiceIndx = TableTypeIndx;
317  mParams.mDCBlock = DCBlock;
318  mParams.mThreshold_dB = Threshold_dB;
319  mParams.mNoiseFloor = NoiseFloor;
320  mParams.mParam1 = Param1;
321  mParams.mParam2 = Param2;
322  mParams.mRepeats = Repeats;
323 
324  return true;
325 }
326 
328 {
330 
331  for (size_t i = 0; i < WXSIZEOF(FactoryPresets); i++)
332  {
333  names.push_back( FactoryPresets[i].name.Translation() );
334  }
335 
336  return names;
337 }
338 
340 {
341  if (id < 0 || id >= (int) WXSIZEOF(FactoryPresets))
342  {
343  return false;
344  }
345 
346  mParams = FactoryPresets[id].params;
348 
349  if (mUIDialog)
350  {
352  }
353 
354  return true;
355 }
356 
357 
358 // Effect implementation
359 
361 {
362  S.AddSpace(0, 5);
363  S.StartVerticalLay();
364  {
365  S.StartMultiColumn(4, wxCENTER);
366  {
368  .MinSize( { -1, -1 } )
370  .AddChoice(XXO("Distortion type:"),
372 
373  mDCBlockCheckBox = S.Id(ID_DCBlock).AddCheckBox(XXO("DC blocking filter"),
374  DEF_DCBlock);
375  }
376  S.EndMultiColumn();
377  S.AddSpace(0, 10);
378 
379 
380  S.StartStatic(XO("Threshold controls"));
381  {
382  S.StartMultiColumn(4, wxEXPAND);
383  S.SetStretchyCol(2);
384  {
385  // Allow space for first Column
386  S.AddSpace(250,0); S.AddSpace(0,0); S.AddSpace(0,0); S.AddSpace(0,0);
387 
388  // Upper threshold control
390  false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
392  .Name(defaultLabel(0))
393  .Validator<FloatingPointValidator<double>>(
394  2, &mParams.mThreshold_dB, NumValidatorStyle::DEFAULT,
395  MIN_Threshold_dB, MAX_Threshold_dB)
396  .AddTextBox( {}, wxT(""), 10);
397 
399  .Name(defaultLabel(0))
400  .Style(wxSL_HORIZONTAL)
401  .AddSlider( {}, 0,
402  DB_TO_LINEAR(MAX_Threshold_dB) * SCL_Threshold_dB,
403  DB_TO_LINEAR(MIN_Threshold_dB) * SCL_Threshold_dB);
404  S.AddSpace(20, 0);
405 
406  // Noise floor control
408  false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
410  .Name(defaultLabel(1))
411  .Validator<FloatingPointValidator<double>>(
412  2, &mParams.mNoiseFloor, NumValidatorStyle::DEFAULT,
413  MIN_NoiseFloor, MAX_NoiseFloor
414  )
415  .AddTextBox( {}, wxT(""), 10);
416 
418  .Name(defaultLabel(1))
419  .Style(wxSL_HORIZONTAL)
420  .AddSlider( {}, 0, MAX_NoiseFloor, MIN_NoiseFloor);
421  S.AddSpace(20, 0);
422  }
423  S.EndMultiColumn();
424  }
425  S.EndStatic();
426 
427  S.StartStatic(XO("Parameter controls"));
428  {
429  S.StartMultiColumn(4, wxEXPAND);
430  S.SetStretchyCol(2);
431  {
432  // Allow space for first Column
433  S.AddSpace(250,0); S.AddSpace(0,0); S.AddSpace(0,0); S.AddSpace(0,0);
434 
435  // Parameter1 control
437  false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
438  mParam1T = S.Id(ID_Param1)
439  .Name(defaultLabel(2))
440  .Validator<FloatingPointValidator<double>>(
441  2, &mParams.mParam1, NumValidatorStyle::DEFAULT,
442  MIN_Param1, MAX_Param1
443  )
444  .AddTextBox( {}, wxT(""), 10);
445 
446  mParam1S = S.Id(ID_Param1)
447  .Name(defaultLabel(2))
448  .Style(wxSL_HORIZONTAL)
449  .AddSlider( {}, 0, MAX_Param1, MIN_Param1);
450  S.AddSpace(20, 0);
451 
452  // Parameter2 control
454  false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
455  mParam2T = S.Id(ID_Param2)
456  .Name(defaultLabel(3))
457  .Validator<FloatingPointValidator<double>>(
458  2, &mParams.mParam2, NumValidatorStyle::DEFAULT,
459  MIN_Param2, MAX_Param2
460  )
461  .AddTextBox( {}, wxT(""), 10);
462 
463  mParam2S = S.Id(ID_Param2)
464  .Name(defaultLabel(3))
465  .Style(wxSL_HORIZONTAL)
466  .AddSlider( {}, 0, MAX_Param2, MIN_Param2);
467  S.AddSpace(20, 0);
468 
469  // Repeats control
471  false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
472  mRepeatsT = S.Id(ID_Repeats)
473  .Name(defaultLabel(4))
474  .Validator<IntegerValidator<int>>(
475  &mParams.mRepeats, NumValidatorStyle::DEFAULT,
476  MIN_Repeats, MAX_Repeats
477  )
478  .AddTextBox( {}, wxT(""), 10);
479 
480  mRepeatsS = S.Id(ID_Repeats)
481  .Name(defaultLabel(4))
482  .Style(wxSL_HORIZONTAL)
483  .AddSlider( {}, DEF_Repeats, MAX_Repeats, MIN_Repeats);
484  S.AddSpace(20, 0);
485  }
486  S.EndMultiColumn();
487  }
488  S.EndStatic();
489  }
490  S.EndVerticalLay();
491 
492  return;
493 }
494 
496 {
497  if (!mUIParent->TransferDataToWindow())
498  {
499  return false;
500  }
501 
502  mThresholdS->SetValue((int) (mThreshold * SCL_Threshold_dB + 0.5));
503  mDCBlockCheckBox->SetValue(mParams.mDCBlock);
504  mNoiseFloorS->SetValue((int) mParams.mNoiseFloor + 0.5);
505  mParam1S->SetValue((int) mParams.mParam1 + 0.5);
506  mParam2S->SetValue((int) mParams.mParam2 + 0.5);
507  mRepeatsS->SetValue(mParams.mRepeats);
508 
510 
511  UpdateUI();
512 
513  return true;
514 }
515 
517 {
518  if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
519  {
520  return false;
521  }
522 
524 
525  return true;
526 }
527 
529 {
530  data.samplerate = sampleRate;
531  data.skipcount = 0;
533  data.dcblock = mParams.mDCBlock;
536  data.param1 = mParams.mParam1;
537  data.param2 = mParams.mParam2;
538  data.repeats = mParams.mRepeats;
539 
540  // DC block filter variables
541  data.queuetotal = 0.0;
542 
543  //std::queue<float>().swap(data.queuesamples);
544  while (!data.queuesamples.empty())
545  data.queuesamples.pop();
546 
547  MakeTable();
548 
549  return;
550 }
551 
552 size_t EffectDistortion::InstanceProcess(EffectDistortionState& data, float** inBlock, float** outBlock, size_t blockLen)
553 {
554  float *ibuf = inBlock[0];
555  float *obuf = outBlock[0];
556 
557  bool update = (mParams.mTableChoiceIndx == data.tablechoiceindx &&
558  mParams.mNoiseFloor == data.noisefloor &&
559  mParams.mThreshold_dB == data.threshold &&
560  mParams.mParam1 == data.param1 &&
561  mParams.mParam2 == data.param2 &&
562  mParams.mRepeats == data.repeats)? false : true;
563 
564  double p1 = mParams.mParam1 / 100.0;
565  double p2 = mParams.mParam2 / 100.0;
566 
570  data.param1 = mParams.mParam1;
571  data.repeats = mParams.mRepeats;
572 
573  for (decltype(blockLen) i = 0; i < blockLen; i++) {
574  if (update && ((data.skipcount++) % skipsamples == 0)) {
575  MakeTable();
576  }
577 
578  switch (mParams.mTableChoiceIndx)
579  {
580  case kHardClip:
581  // Param2 = make-up gain.
582  obuf[i] = WaveShaper(ibuf[i]) * ((1 - p2) + (mMakeupGain * p2));
583  break;
584  case kSoftClip:
585  // Param2 = make-up gain.
586  obuf[i] = WaveShaper(ibuf[i]) * ((1 - p2) + (mMakeupGain * p2));
587  break;
588  case kHalfSinCurve:
589  obuf[i] = WaveShaper(ibuf[i]) * p2;
590  break;
591  case kExpCurve:
592  obuf[i] = WaveShaper(ibuf[i]) * p2;
593  break;
594  case kLogCurve:
595  obuf[i] = WaveShaper(ibuf[i]) * p2;
596  break;
597  case kCubic:
598  obuf[i] = WaveShaper(ibuf[i]) * p2;
599  break;
600  case kEvenHarmonics:
601  obuf[i] = WaveShaper(ibuf[i]);
602  break;
603  case kSinCurve:
604  obuf[i] = WaveShaper(ibuf[i]) * p2;
605  break;
606  case kLeveller:
607  obuf[i] = WaveShaper(ibuf[i]);
608  break;
609  case kRectifier:
610  obuf[i] = WaveShaper(ibuf[i]);
611  break;
612  case kHardLimiter:
613  // Mix equivalent to LADSPA effect's "Wet / Residual" mix
614  obuf[i] = (WaveShaper(ibuf[i]) * (p1 - p2)) + (ibuf[i] * p2);
615  break;
616  default:
617  obuf[i] = WaveShaper(ibuf[i]);
618  }
619  if (mParams.mDCBlock) {
620  obuf[i] = DCFilter(data, obuf[i]);
621  }
622  }
623 
624  return blockLen;
625 }
626 
627 void EffectDistortion::OnTypeChoice(wxCommandEvent& /*evt*/)
628 {
629  mTypeChoiceCtrl->GetValidator()->TransferFromWindow();
630 
631  UpdateUI();
632 }
633 
634 void EffectDistortion::OnDCBlockCheckbox(wxCommandEvent& /*evt*/)
635 {
636  mParams.mDCBlock = mDCBlockCheckBox->GetValue();
638 }
639 
640 
641 void EffectDistortion::OnThresholdText(wxCommandEvent& /*evt*/)
642 {
643  mThresholdT->GetValidator()->TransferFromWindow();
645  mThresholdS->SetValue((int) (mThreshold * SCL_Threshold_dB + 0.5));
646 }
647 
648 void EffectDistortion::OnThresholdSlider(wxCommandEvent& evt)
649 {
650  mThreshold = (double) evt.GetInt() / SCL_Threshold_dB;
651  mParams.mThreshold_dB = wxMax(LINEAR_TO_DB(mThreshold), MIN_Threshold_dB);
652  mThreshold = std::max(MIN_Threshold_Linear, mThreshold);
653  mThresholdT->GetValidator()->TransferToWindow();
654 }
655 
656 void EffectDistortion::OnNoiseFloorText(wxCommandEvent& /*evt*/)
657 {
658  mNoiseFloorT->GetValidator()->TransferFromWindow();
659  mNoiseFloorS->SetValue((int) floor(mParams.mNoiseFloor + 0.5));
660 }
661 
662 void EffectDistortion::OnNoiseFloorSlider(wxCommandEvent& evt)
663 {
664  mParams.mNoiseFloor = (double) evt.GetInt();
665  mNoiseFloorT->GetValidator()->TransferToWindow();
666 }
667 
668 
669 void EffectDistortion::OnParam1Text(wxCommandEvent& /*evt*/)
670 {
671  mParam1T->GetValidator()->TransferFromWindow();
672  mParam1S->SetValue((int) floor(mParams.mParam1 + 0.5));
673 }
674 
675 void EffectDistortion::OnParam1Slider(wxCommandEvent& evt)
676 {
677  mParams.mParam1 = (double) evt.GetInt();
678  mParam1T->GetValidator()->TransferToWindow();
679 }
680 
681 void EffectDistortion::OnParam2Text(wxCommandEvent& /*evt*/)
682 {
683  mParam2T->GetValidator()->TransferFromWindow();
684  mParam2S->SetValue((int) floor(mParams.mParam2 + 0.5));
685 }
686 
687 void EffectDistortion::OnParam2Slider(wxCommandEvent& evt)
688 {
689  mParams.mParam2 = (double) evt.GetInt();
690  mParam2T->GetValidator()->TransferToWindow();
691 }
692 
693 void EffectDistortion::OnRepeatsText(wxCommandEvent& /*evt*/)
694 {
695  mRepeatsT->GetValidator()->TransferFromWindow();
696  mRepeatsS->SetValue(mParams.mRepeats);
697 }
698 
699 void EffectDistortion::OnRepeatsSlider(wxCommandEvent& evt)
700 {
701  mParams.mRepeats = evt.GetInt();
702  mRepeatsT->GetValidator()->TransferToWindow();
703 
704 }
705 
707 {
708  // set control text and names to match distortion type
709  switch (mParams.mTableChoiceIndx)
710  {
711  case kHardClip:
717 
718  UpdateControl(ID_Threshold, true, XO("Clipping level"));
720  UpdateControl(ID_Param1, true, XO("Drive"));
721  UpdateControl(ID_Param2, true, XO("Make-up Gain"));
723  UpdateControl(ID_DCBlock, false, {});
724  break;
725  case kSoftClip:
731 
732  UpdateControl(ID_Threshold, true, XO("Clipping threshold"));
734  UpdateControl(ID_Param1, true, XO("Hardness"));
735  UpdateControl(ID_Param2, true, XO("Make-up Gain"));
737  UpdateControl(ID_DCBlock, false, {});
738  break;
739  case kHalfSinCurve:
745 
748  UpdateControl(ID_Param1, true, XO("Distortion amount"));
749  UpdateControl(ID_Param2, true, XO("Output level"));
751  UpdateControl(ID_DCBlock, false, {});
752  break;
753  case kExpCurve:
759 
762  UpdateControl(ID_Param1, true, XO("Distortion amount"));
763  UpdateControl(ID_Param2, true, XO("Output level"));
765  UpdateControl(ID_DCBlock, false, {});
766  break;
767  case kLogCurve:
773 
776  UpdateControl(ID_Param1, true, XO("Distortion amount"));
777  UpdateControl(ID_Param2, true, XO("Output level"));
779  UpdateControl(ID_DCBlock, false, {});
780  break;
781  case kCubic:
787 
790  UpdateControl(ID_Param1, true, XO("Distortion amount"));
791  UpdateControl(ID_Param2, true, XO("Output level"));
792  UpdateControl(ID_Repeats, true, XO("Repeat processing"));
793  UpdateControl(ID_DCBlock, false, {});
794  break;
795  case kEvenHarmonics:
801 
804  UpdateControl(ID_Param1, true, XO("Distortion amount"));
805  UpdateControl(ID_Param2, true, XO("Harmonic brightness"));
807  UpdateControl(ID_DCBlock, true, {});
808  break;
809  case kSinCurve:
815 
818  UpdateControl(ID_Param1, true, XO("Distortion amount"));
819  UpdateControl(ID_Param2, true, XO("Output level"));
821  UpdateControl(ID_DCBlock, false, {});
822  break;
823  case kLeveller:
829 
832  UpdateControl(ID_Param1, true, XO("Levelling fine adjustment"));
834  UpdateControl(ID_Repeats, true, XO("Degree of Levelling"));
835  UpdateControl(ID_DCBlock, false, {});
836  break;
837  case kRectifier:
843 
846  UpdateControl(ID_Param1, true, XO("Distortion amount"));
849  UpdateControl(ID_DCBlock, true, {});
850  break;
851  case kHardLimiter:
857 
858  UpdateControl(ID_Threshold, true, XO("dB Limit"));
860  UpdateControl(ID_Param1, true, XO("Wet level"));
861  UpdateControl(ID_Param2, true, XO("Residual level"));
863  UpdateControl(ID_DCBlock, false, {});
864  break;
865  default:
871  UpdateControl(ID_DCBlock, false, {});
872  }
873 }
874 
876  control id, bool enabled, TranslatableString name)
877 {
878  auto suffix = XO("(Not Used):");
879  switch (id)
880  {
881  case ID_Threshold: {
882  /* i18n-hint: Control range. */
883  if (enabled) suffix = XO("(-100 to 0 dB):");
884  name.Join( suffix, wxT(" ") );
885 
886  // Logarithmic slider is set indirectly
888  mThresholdS->SetValue((int) (mThreshold * SCL_Threshold_dB + 0.5));
889 
890  auto translated = name.Translation();
891  mThresholdTxt->SetLabel(translated);
892  mThresholdS->SetName(translated);
893  mThresholdT->SetName(translated);
894  mThresholdS->Enable(enabled);
895  mThresholdT->Enable(enabled);
896  break;
897  }
898  case ID_NoiseFloor: {
899  /* i18n-hint: Control range. */
900  if (enabled) suffix = XO("(-80 to -20 dB):");
901  name.Join( suffix, wxT(" ") );
902 
903  auto translated = name.Translation();
904  mNoiseFloorTxt->SetLabel(translated);
905  mNoiseFloorS->SetName(translated);
906  mNoiseFloorT->SetName(translated);
907  mNoiseFloorS->Enable(enabled);
908  mNoiseFloorT->Enable(enabled);
909  break;
910  }
911  case ID_Param1: {
912  /* i18n-hint: Control range. */
913  if (enabled) suffix = XO("(0 to 100):");
914  name.Join( suffix, wxT(" ") );
915 
916  auto translated = name.Translation();
917  mParam1Txt->SetLabel(translated);
918  mParam1S->SetName(translated);
919  mParam1T->SetName(translated);
920  mParam1S->Enable(enabled);
921  mParam1T->Enable(enabled);
922  break;
923  }
924  case ID_Param2: {
925  /* i18n-hint: Control range. */
926  if (enabled) suffix = XO("(0 to 100):");
927  name.Join( suffix, wxT(" ") );
928 
929  auto translated = name.Translation();
930  mParam2Txt->SetLabel(translated);
931  mParam2S->SetName(translated);
932  mParam2T->SetName(translated);
933  mParam2S->Enable(enabled);
934  mParam2T->Enable(enabled);
935  break;
936  }
937  case ID_Repeats: {
938  /* i18n-hint: Control range. */
939  if (enabled) suffix = XO("(0 to 5):");
940  name.Join( suffix, wxT(" ") );
941 
942  auto translated = name.Translation();
943  mRepeatsTxt->SetLabel(translated);
944  mRepeatsS->SetName(translated);
945  mRepeatsT->SetName(translated);
946  mRepeatsS->Enable(enabled);
947  mRepeatsT->Enable(enabled);
948  break;
949  }
950  case ID_DCBlock: {
951  if (enabled) {
954  }
955  else {
956  mDCBlockCheckBox->SetValue(false);
957  mParams.mDCBlock = false;
958  }
959 
960  mDCBlockCheckBox->Enable(enabled);
961  break;
962  }
963  default:
964  break;
965  }
966 }
967 
968 void EffectDistortion::UpdateControlText(wxTextCtrl* textCtrl, wxString& string, bool enabled)
969 {
970  if (enabled) {
971  if (textCtrl->GetValue().empty())
972  textCtrl->SetValue(string);
973  else
974  string = textCtrl->GetValue();
975  }
976  else {
977  if (!textCtrl->GetValue().empty())
978  string = textCtrl->GetValue();
979  textCtrl->SetValue(wxT(""));
980  }
981 }
982 
984 {
985  switch (mParams.mTableChoiceIndx)
986  {
987  case kHardClip:
988  HardClip();
989  break;
990  case kSoftClip:
991  SoftClip();
992  break;
993  case kHalfSinCurve:
994  HalfSinTable();
995  break;
996  case kExpCurve:
998  break;
999  case kLogCurve:
1000  LogarithmicTable();
1001  break;
1002  case kCubic:
1003  CubicTable();
1004  break;
1005  case kEvenHarmonics:
1007  break;
1008  case kSinCurve:
1009  SineTable();
1010  break;
1011  case kLeveller:
1012  Leveller();
1013  break;
1014  case kRectifier:
1015  Rectifier();
1016  break;
1017  case kHardLimiter:
1018  HardLimiter();
1019  break;
1020  }
1021 }
1022 
1023 
1024 //
1025 // Preset tables for gain lookup
1026 //
1027 
1029 {
1030  double lowThresh = 1 - mThreshold;
1031  double highThresh = 1 + mThreshold;
1032 
1033  for (int n = 0; n < TABLESIZE; n++) {
1034  if (n < (STEPS * lowThresh))
1035  mTable[n] = - mThreshold;
1036  else if (n > (STEPS * highThresh))
1037  mTable[n] = mThreshold;
1038  else
1039  mTable[n] = n/(double)STEPS - 1;
1040 
1041  mMakeupGain = 1.0 / mThreshold;
1042  }
1043 }
1044 
1046 {
1047  double threshold = 1 + mThreshold;
1048  double amount = std::pow(2.0, 7.0 * mParams.mParam1 / 100.0); // range 1 to 128
1049  double peak = LogCurve(mThreshold, 1.0, amount);
1050  mMakeupGain = 1.0 / peak;
1051  mTable[STEPS] = 0.0; // origin
1052 
1053  // positive half of table
1054  for (int n = STEPS; n < TABLESIZE; n++) {
1055  if (n < (STEPS * threshold)) // origin to threshold
1056  mTable[n] = n/(float)STEPS - 1;
1057  else
1058  mTable[n] = LogCurve(mThreshold, n/(double)STEPS - 1, amount);
1059  }
1060  CopyHalfTable();
1061 }
1062 
1063 float EffectDistortion::LogCurve(double threshold, float value, double ratio)
1064 {
1065  return threshold + ((std::exp(ratio * (threshold - value)) - 1) / -ratio);
1066 }
1067 
1069 {
1070  double amount = std::min(0.999, DB_TO_LINEAR(-1 * mParams.mParam1)); // avoid divide by zero
1071 
1072  for (int n = STEPS; n < TABLESIZE; n++) {
1073  double linVal = n/(float)STEPS;
1074  double scale = -1.0 / (1.0 - amount); // unity gain at 0dB
1075  double curve = std::exp((linVal - 1) * std::log(amount));
1076  mTable[n] = scale * (curve -1);
1077  }
1078  CopyHalfTable();
1079 }
1080 
1082 {
1083  double amount = mParams.mParam1;
1084  double stepsize = 1.0 / STEPS;
1085  double linVal = 0;
1086 
1087  if (amount == 0){
1088  for (int n = STEPS; n < TABLESIZE; n++) {
1089  mTable[n] = linVal;
1090  linVal += stepsize;
1091  }
1092  }
1093  else {
1094  for (int n = STEPS; n < TABLESIZE; n++) {
1095  mTable[n] = std::log(1 + (amount * linVal)) / std::log(1 + amount);
1096  linVal += stepsize;
1097  }
1098  }
1099  CopyHalfTable();
1100 }
1101 
1103 {
1104  int iter = std::floor(mParams.mParam1 / 20.0);
1105  double fractionalpart = (mParams.mParam1 / 20.0) - iter;
1106  double stepsize = 1.0 / STEPS;
1107  double linVal = 0;
1108 
1109  for (int n = STEPS; n < TABLESIZE; n++) {
1110  mTable[n] = linVal;
1111  for (int i = 0; i < iter; i++) {
1112  mTable[n] = std::sin(mTable[n] * M_PI_2);
1113  }
1114  mTable[n] += ((std::sin(mTable[n] * M_PI_2) - mTable[n]) * fractionalpart);
1115  linVal += stepsize;
1116  }
1117  CopyHalfTable();
1118 }
1119 
1121 {
1122  double amount = mParams.mParam1 * std::sqrt(3.0) / 100.0;
1123  double gain = 1.0;
1124  if (amount != 0.0)
1125  gain = 1.0 / Cubic(std::min(amount, 1.0));
1126 
1127  double stepsize = amount / STEPS;
1128  double x = -amount;
1129 
1130  if (amount == 0) {
1131  for (int i = 0; i < TABLESIZE; i++) {
1132  mTable[i] = (i / (double)STEPS) - 1.0;
1133  }
1134  }
1135  else {
1136  for (int i = 0; i < TABLESIZE; i++) {
1137  mTable[i] = gain * Cubic(x);
1138  for (int j = 0; j < mParams.mRepeats; j++) {
1139  mTable[i] = gain * Cubic(mTable[i] * amount);
1140  }
1141  x += stepsize;
1142  }
1143  }
1144 }
1145 
1146 double EffectDistortion::Cubic(double x)
1147 {
1148  if (mParams.mParam1 == 0.0)
1149  return x;
1150 
1151  return x - (std::pow(x, 3.0) / 3.0);
1152 }
1153 
1154 
1156 {
1157  double amount = mParams.mParam1 / -100.0;
1158  // double C = std::sin(std::max(0.001, mParams.mParam2) / 100.0) * 10.0;
1159  double C = std::max(0.001, mParams.mParam2) / 10.0;
1160 
1161  double step = 1.0 / STEPS;
1162  double xval = -1.0;
1163 
1164  for (int i = 0; i < TABLESIZE; i++) {
1165  mTable[i] = ((1 + amount) * xval) -
1166  (xval * (amount / std::tanh(C)) * std::tanh(C * xval));
1167  xval += step;
1168  }
1169 }
1170 
1172 {
1173  int iter = std::floor(mParams.mParam1 / 20.0);
1174  double fractionalpart = (mParams.mParam1 / 20.0) - iter;
1175  double stepsize = 1.0 / STEPS;
1176  double linVal = 0.0;
1177 
1178  for (int n = STEPS; n < TABLESIZE; n++) {
1179  mTable[n] = linVal;
1180  for (int i = 0; i < iter; i++) {
1181  mTable[n] = (1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0;
1182  }
1183  mTable[n] += (((1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0) - mTable[n]) * fractionalpart;
1184  linVal += stepsize;
1185  }
1186  CopyHalfTable();
1187 }
1188 
1190 {
1191  double noiseFloor = DB_TO_LINEAR(mParams.mNoiseFloor);
1192  int numPasses = mParams.mRepeats;
1193  double fractionalPass = mParams.mParam1 / 100.0;
1194 
1195  const int numPoints = 6;
1196  const double gainFactors[numPoints] = { 0.80, 1.00, 1.20, 1.20, 1.00, 0.80 };
1197  double gainLimits[numPoints] = { 0.0001, 0.0, 0.1, 0.3, 0.5, 1.0 };
1198  double addOnValues[numPoints];
1199 
1200  gainLimits[1] = noiseFloor;
1201  /* In the original Leveller effect, behaviour was undefined for threshold > 20 dB.
1202  * If we want to support > 20 dB we need to scale the points to keep them non-decreasing.
1203  *
1204  * if (noiseFloor > gainLimits[2]) {
1205  * for (int i = 3; i < numPoints; i++) {
1206  * gainLimits[i] = noiseFloor + ((1 - noiseFloor)*((gainLimits[i] - 0.1) / 0.9));
1207  * }
1208  * gainLimits[2] = noiseFloor;
1209  * }
1210  */
1211 
1212  // Calculate add-on values
1213  addOnValues[0] = 0.0;
1214  for (int i = 0; i < numPoints-1; i++) {
1215  addOnValues[i+1] = addOnValues[i] + (gainLimits[i] * (gainFactors[i] - gainFactors[1 + i]));
1216  }
1217 
1218  // Positive half of table.
1219  // The original effect increased the 'strength' of the effect by
1220  // repeated passes over the audio data.
1221  // Here we model that more efficiently by repeated passes over a linear table.
1222  for (int n = STEPS; n < TABLESIZE; n++) {
1223  mTable[n] = ((double) (n - STEPS) / (double) STEPS);
1224  for (int j = 0; j < numPasses; j++) {
1225  // Find the highest index for gain adjustment
1226  int index = numPoints - 1;
1227  for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--) {
1228  index = i;
1229  }
1230  // the whole number of 'repeats'
1231  mTable[n] = (mTable[n] * gainFactors[index]) + addOnValues[index];
1232  }
1233  // Extrapolate for fine adjustment.
1234  // tiny fractions are not worth the processing time
1235  if (fractionalPass > 0.001) {
1236  int index = numPoints - 1;
1237  for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--) {
1238  index = i;
1239  }
1240  mTable[n] += fractionalPass * ((mTable[n] * (gainFactors[index] - 1)) + addOnValues[index]);
1241  }
1242  }
1243  CopyHalfTable();
1244 }
1245 
1247 {
1248  double amount = (mParams.mParam1 / 50.0) - 1;
1249  double stepsize = 1.0 / STEPS;
1250  int index = STEPS;
1251 
1252  // positive half of waveform is passed unaltered.
1253  for (int n = 0; n <= STEPS; n++) {
1254  mTable[index] = n * stepsize;
1255  index += 1;
1256  }
1257 
1258  // negative half of table
1259  index = STEPS - 1;
1260  for (int n = 1; n <= STEPS; n++) {
1261  mTable[index] = n * stepsize * amount;
1262  index--;
1263  }
1264 }
1265 
1267 {
1268  // The LADSPA "hardLimiter 1413" is basically hard clipping,
1269  // but with a 'kind of' wet/dry mix:
1270  // out = ((wet-residual)*clipped) + (residual*in)
1271  HardClip();
1272 }
1273 
1274 
1275 // Helper functions for lookup tables
1276 
1278 {
1279  // Copy negative half of table from positive half
1280  int count = TABLESIZE - 1;
1281  for (int n = 0; n < STEPS; n++) {
1282  mTable[n] = -mTable[count];
1283  count--;
1284  }
1285 }
1286 
1287 
1288 float EffectDistortion::WaveShaper(float sample)
1289 {
1290  float out;
1291  int index;
1292  double xOffset;
1293  double amount = 1;
1294 
1295  switch (mParams.mTableChoiceIndx)
1296  {
1297  // Do any pre-processing here
1298  case kHardClip:
1299  // Pre-gain
1300  amount = mParams.mParam1 / 100.0;
1301  sample *= 1+amount;
1302  break;
1303  default: break;
1304  }
1305 
1306  index = std::floor(sample * STEPS) + STEPS;
1307  index = wxMax<int>(wxMin<int>(index, 2 * STEPS - 1), 0);
1308  xOffset = ((1 + sample) * STEPS) - index;
1309  xOffset = wxMin<double>(wxMax<double>(xOffset, 0.0), 1.0); // Clip at 0dB
1310 
1311  // linear interpolation: y = y0 + (y1-y0)*(x-x0)
1312  out = mTable[index] + (mTable[index + 1] - mTable[index]) * xOffset;
1313 
1314  return out;
1315 }
1316 
1317 
1319 {
1320  // Rolling average gives less offset at the start than an IIR filter.
1321  const unsigned int queueLength = std::floor(data.samplerate / 20.0);
1322 
1323  data.queuetotal += sample;
1324  data.queuesamples.push(sample);
1325 
1326  if (data.queuesamples.size() > queueLength) {
1327  data.queuetotal -= data.queuesamples.front();
1328  data.queuesamples.pop();
1329  }
1330 
1331  return sample - (data.queuetotal / data.queuesamples.size());
1332 }
RegistryPaths
std::vector< RegistryPath > RegistryPaths
Definition: Types.h:262
EffectDistortion::ProcessBlock
size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override
Definition: Distortion.cpp:240
ID_Type
@ ID_Type
Definition: ScienFilter.cpp:81
TranslatableString
Definition: Types.h:290
EffectDistortion::SetAutomationParameters
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Distortion.cpp:306
CommandParameters
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
Definition: EffectAutomationParameters.h:67
EffectDistortion::mThresholdS
wxSlider * mThresholdS
Definition: Distortion.h:191
EffectDistortion::Params::mParam1
double mParam1
Definition: Distortion.h:59
EffectDistortion::mParam2S
wxSlider * mParam2S
Definition: Distortion.h:194
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1177
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
EffectDistortion::mMaster
EffectDistortionState mMaster
Definition: Distortion.h:171
DB_TO_LINEAR
const double MIN_Threshold_Linear DB_TO_LINEAR(MIN_Threshold_dB)
ShuttleGuiBase::AddCheckBox
wxCheckBox * AddCheckBox(const TranslatableString &Prompt, bool Selected)
Definition: ShuttleGui.cpp:302
Effect::mUIDialog
wxDialog * mUIDialog
Definition: Effect.h:476
EffectDistortion::mParam1Txt
wxStaticText * mParam1Txt
Definition: Distortion.h:201
EffectDistortion::Params::mDCBlock
bool mDCBlock
Definition: Distortion.h:56
EffectDistortion::OnParam1Text
void OnParam1Text(wxCommandEvent &evt)
Definition: Distortion.cpp:669
EffectDistortion::CubicTable
void CubicTable()
Definition: Distortion.cpp:1120
kRectifier
@ kRectifier
Definition: Distortion.cpp:59
EffectDistortion::mDCBlockCheckBox
wxCheckBox * mDCBlockCheckBox
Definition: Distortion.h:197
kCubic
@ kCubic
Definition: Distortion.cpp:55
EffectDistortion::LogCurve
float LogCurve(double threshold, float value, double ratio)
Definition: Distortion.cpp:1063
EffectDistortion::UpdateUI
void UpdateUI()
Definition: Distortion.cpp:706
Distortion.h
EffectDistortion::Rectifier
void Rectifier()
Definition: Distortion.cpp:1246
EffectDistortionState::samplerate
float samplerate
Definition: Distortion.h:30
EffectDistortion::Params::mNoiseFloor
double mNoiseFloor
Definition: Distortion.h:58
EffectDistortionState::param2
double param2
Definition: Distortion.h:37
EffectDistortion::mThresholdTxt
wxStaticText * mThresholdTxt
Definition: Distortion.h:199
EffectDistortion::GetFactoryPresets
RegistryPaths GetFactoryPresets() override
Definition: Distortion.cpp:327
EffectDistortionState::queuetotal
double queuetotal
Definition: Distortion.h:42
EffectDistortion::mRepeatsTxt
wxStaticText * mRepeatsTxt
Definition: Distortion.h:203
EffectDistortion::mTable
double mTable[TABLESIZE]
Definition: Distortion.h:174
EffectDistortion::OnRepeatsText
void OnRepeatsText(wxCommandEvent &evt)
Definition: Distortion.cpp:693
Validator
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2421
EffectDistortion::ID_Repeats
@ ID_Repeats
Definition: Distortion.h:110
EffectDistortion::RealtimeInitialize
bool RealtimeInitialize() override
Definition: Distortion.cpp:245
ShuttleGui::MinSize
ShuttleGui & MinSize()
Definition: ShuttleGui.h:740
XO
#define XO(s)
Definition: Internat.h:32
EffectDistortion::CopyHalfTable
void CopyHalfTable()
Definition: Distortion.cpp:1277
EffectDistortion::HalfSinTable
void HalfSinTable()
Definition: Distortion.cpp:1102
EffectDistortion::mbSavedFilterState
bool mbSavedFilterState
Definition: Distortion.h:176
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:61
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
EffectDistortion::InstanceInit
void InstanceInit(EffectDistortionState &data, float sampleRate)
Definition: Distortion.cpp:528
kSinCurve
@ kSinCurve
Definition: Distortion.cpp:57
kHalfSinCurve
@ kHalfSinCurve
Definition: Distortion.cpp:52
kHardClip
@ kHardClip
Definition: Distortion.cpp:50
EffectDistortion::ManualPage
wxString ManualPage() override
Definition: Distortion.cpp:201
EffectDistortion::mNoiseFloorS
wxSlider * mNoiseFloorS
Definition: Distortion.h:192
STEPS
#define STEPS
Definition: Distortion.h:24
EffectDistortion::ID_Type
@ ID_Type
Definition: Distortion.h:104
nTableTypes
@ nTableTypes
Definition: Distortion.cpp:61
Param
Param(TableTypeIndx, int, wxT("Type"), 0, 0, nTableTypes-1, 1)
EffectDistortion::mThresholdT
wxTextCtrl * mThresholdT
Definition: Distortion.h:185
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
EffectDistortion::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: Distortion.cpp:360
kLeveller
@ kLeveller
Definition: Distortion.cpp:58
EffectDistortionState::param1
double param1
Definition: Distortion.h:36
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2248
EffectDistortion::RealtimeAddProcessor
bool RealtimeAddProcessor(unsigned numChannels, float sampleRate) override
Definition: Distortion.cpp:254
EffectDistortion::mSlaves
std::vector< EffectDistortionState > mSlaves
Definition: Distortion.h:172
ID_NoiseFloor
@ ID_NoiseFloor
Definition: Compressor.cpp:54
kEvenHarmonics
@ kEvenHarmonics
Definition: Distortion.cpp:56
EffectDistortion::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: Distortion.cpp:191
EffectDistortion::control
control
Definition: Distortion.h:103
EffectDistortion::mOldRepeatsTxt
wxString mOldRepeatsTxt
Definition: Distortion.h:209
EffectDistortion::OnRepeatsSlider
void OnRepeatsSlider(wxCommandEvent &evt)
Definition: Distortion.cpp:699
EffectDistortion::mRepeatsS
wxSlider * mRepeatsS
Definition: Distortion.h:195
EffectDistortion::mThreshold
double mThreshold
Definition: Distortion.h:175
EffectDistortion::LoadFactoryPreset
bool LoadFactoryPreset(int id) override
Definition: Distortion.cpp:339
EffectDistortionState
Definition: Distortion.h:28
ReadAndVerifyEnum
#define ReadAndVerifyEnum(name, list, listSize)
Definition: Effect.h:620
ReadAndVerifyInt
#define ReadAndVerifyInt(name)
Definition: Effect.h:631
EffectDistortion::ID_NoiseFloor
@ ID_NoiseFloor
Definition: Distortion.h:107
EffectDistortion::GetDescription
TranslatableString GetDescription() override
Definition: Distortion.cpp:196
XXO
#define XXO(s)
Definition: Internat.h:45
EffectDistortion::Cubic
double Cubic(double x)
Definition: Distortion.cpp:1146
EffectDistortion::mParams
Params mParams
Definition: Distortion.h:211
EffectDistortion::~EffectDistortion
virtual ~EffectDistortion()
Definition: Distortion.cpp:185
EffectDistortion::Params::mTableChoiceIndx
int mTableChoiceIndx
Definition: Distortion.h:55
EffectDistortion::SineTable
void SineTable()
Definition: Distortion.cpp:1171
EffectDistortion::Params
Definition: Distortion.h:54
EffectDistortion::ExponentialTable
void ExponentialTable()
Definition: Distortion.cpp:1068
EffectDistortion::mOldThresholdTxt
wxString mOldThresholdTxt
Definition: Distortion.h:205
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1196
ChannelNames
enum ChannelName * ChannelNames
EffectDistortion::TransferDataToWindow
bool TransferDataToWindow() override
Definition: Distortion.cpp:495
EffectDistortion::GetType
EffectType GetType() override
Definition: Distortion.cpp:208
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Definition: Internat.cpp:267
name
const TranslatableString name
Definition: Distortion.cpp:98
EffectDistortion::MakeTable
void MakeTable()
Definition: Distortion.cpp:983
EffectDistortion::OnParam2Text
void OnParam2Text(wxCommandEvent &evt)
Definition: Distortion.cpp:681
EffectDistortion::ID_Threshold
@ ID_Threshold
Definition: Distortion.h:106
EffectDistortion::mMakeupGain
double mMakeupGain
Definition: Distortion.h:180
EffectDistortion::Params::mThreshold_dB
double mThreshold_dB
Definition: Distortion.h:57
EffectDistortion::LogarithmicTable
void LogarithmicTable()
Definition: Distortion.cpp:1081
EffectDistortion::mOldParam2Txt
wxString mOldParam2Txt
Definition: Distortion.h:208
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:685
EffectDistortion::OnNoiseFloorText
void OnNoiseFloorText(wxCommandEvent &evt)
Definition: Distortion.cpp:656
EffectDistortion::HardClip
void HardClip()
Definition: Distortion.cpp:1028
EffectDistortion::OnDCBlockCheckbox
void OnDCBlockCheckbox(wxCommandEvent &evt)
Definition: Distortion.cpp:634
kSoftClip
@ kSoftClip
Definition: Distortion.cpp:51
defaultLabel
TranslatableString defaultLabel(int index)
Definition: Distortion.cpp:130
EffectDistortion::RealtimeFinalize
bool RealtimeFinalize() override
Definition: Distortion.cpp:265
EffectDistortion::OnParam2Slider
void OnParam2Slider(wxCommandEvent &evt)
Definition: Distortion.cpp:687
kExpCurve
@ kExpCurve
Definition: Distortion.cpp:53
EffectDistortion::mNoiseFloorT
wxTextCtrl * mNoiseFloorT
Definition: Distortion.h:186
ReadAndVerifyDouble
#define ReadAndVerifyDouble(name)
Definition: Effect.h:632
EffectDistortionState::noisefloor
double noisefloor
Definition: Distortion.h:35
EffectDistortion::UpdateControl
void UpdateControl(control id, bool enable, TranslatableString name)
Definition: Distortion.cpp:875
ShuttleGuiBase::AddSlider
wxSlider * AddSlider(const TranslatableString &Prompt, int pos, int Max, int Min=0)
Definition: ShuttleGui.cpp:582
EffectDistortion::InstanceProcess
size_t InstanceProcess(EffectDistortionState &data, float **inBlock, float **outBlock, size_t blockLen)
Definition: Distortion.cpp:552
EffectDistortion::OnParam1Slider
void OnParam1Slider(wxCommandEvent &evt)
Definition: Distortion.cpp:675
EffectDistortionState::tablechoiceindx
int tablechoiceindx
Definition: Distortion.h:32
LoadEffects.h
EffectDistortion::DCFilter
float DCFilter(EffectDistortionState &data, float sample)
Definition: Distortion.cpp:1318
EffectDistortionState::skipcount
sampleCount skipcount
Definition: Distortion.h:31
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:886
EffectDistortion::OnThresholdText
void OnThresholdText(wxCommandEvent &evt)
Definition: Distortion.cpp:641
TABLESIZE
#define TABLESIZE
Definition: Distortion.h:25
id
int id
Definition: WaveTrackControls.cpp:589
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
EffectDistortion::GetAudioInCount
unsigned GetAudioInCount() override
Definition: Distortion.cpp:224
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:670
EffectDistortion::mRepeatsT
wxTextCtrl * mRepeatsT
Definition: Distortion.h:189
EffectDistortion::mOldmNoiseFloorTxt
wxString mOldmNoiseFloorTxt
Definition: Distortion.h:206
Effect::mSampleRate
double mSampleRate
Definition: Effect.h:459
EffectDistortion::SoftClip
void SoftClip()
Definition: Distortion.cpp:1045
EffectDistortionState::queuesamples
std::queue< float > queuesamples
Definition: Distortion.h:41
kHardLimiter
@ kHardLimiter
Definition: Distortion.cpp:60
EffectDistortion::GetAudioOutCount
unsigned GetAudioOutCount() override
Definition: Distortion.cpp:229
BuiltinEffectsModule::Registration
Definition: LoadEffects.h:40
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:477
EffectDistortion::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: Distortion.cpp:280
EffectDistortion::ProcessInitialize
bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap=NULL) override
Definition: Distortion.cpp:234
names
static TranslatableStrings names
Definition: Tags.cpp:743
M_PI_2
#define M_PI_2
Definition: Distortion.cpp:32
EffectDistortion::OnTypeChoice
void OnTypeChoice(wxCommandEvent &evt)
Definition: Distortion.cpp:627
sampleCount
Definition: Types.h:589
EffectDistortion::UpdateControlText
void UpdateControlText(wxTextCtrl *textCtrl, wxString &string, bool enabled)
Definition: Distortion.cpp:968
EffectDistortion::mParam2Txt
wxStaticText * mParam2Txt
Definition: Distortion.h:202
EffectDistortion::GetAutomationParameters
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Distortion.cpp:292
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterface.h:88
FactoryPresets
static const struct @0 FactoryPresets[]
EffectDistortionState::dcblock
bool dcblock
Definition: Distortion.h:33
EffectDistortion::ID_DCBlock
@ ID_DCBlock
Definition: Distortion.h:105
LINEAR_TO_DB
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:721
kTableTypeStrings
static const EnumValueSymbol kTableTypeStrings[nTableTypes]
Definition: Distortion.cpp:64
EffectDistortion::Leveller
void Leveller()
Definition: Distortion.cpp:1189
M_PI
#define M_PI
Definition: Distortion.cpp:29
EffectDistortion::HardLimiter
void HardLimiter()
Definition: Distortion.cpp:1266
EffectDistortion::mTypeChoiceCtrl
wxChoice * mTypeChoiceCtrl
Definition: Distortion.h:184
EffectDistortion::ID_Param2
@ ID_Param2
Definition: Distortion.h:109
EffectDistortion::mOldParam1Txt
wxString mOldParam1Txt
Definition: Distortion.h:207
EffectDistortion::mNoiseFloorTxt
wxStaticText * mNoiseFloorTxt
Definition: Distortion.h:200
params
EffectDistortion::Params params
Definition: Distortion.cpp:99
EffectDistortion
A WaveShaper distortion effect.
Definition: Distortion.h:46
TranslatableString::Translation
wxString Translation() const
Definition: Types.h:337
kTableType
kTableType
Definition: Distortion.cpp:49
ShuttleGuiBase::AddVariableText
wxStaticText * AddVariableText(const TranslatableString &Str, bool bCenter=false, int PositionFlags=0, int wrapWidth=0)
Definition: ShuttleGui.cpp:456
TranslatableString::Join
TranslatableString & Join(TranslatableString arg, const wxString &separator={}) &
Definition: Internat.cpp:393
EffectDistortion::OnNoiseFloorSlider
void OnNoiseFloorSlider(wxCommandEvent &evt)
Definition: Distortion.cpp:662
EffectDistortionState::repeats
int repeats
Definition: Distortion.h:38
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:915
EffectType
EffectType
Definition: EffectInterface.h:55
kLogCurve
@ kLogCurve
Definition: Distortion.cpp:54
EffectDistortion::Params::mParam2
double mParam2
Definition: Distortion.h:60
EffectDistortion::mParam1S
wxSlider * mParam1S
Definition: Distortion.h:193
EffectDistortion::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: Distortion.h:48
EffectDistortion::mParam1T
wxTextCtrl * mParam1T
Definition: Distortion.h:187
skipsamples
#define skipsamples
Definition: Distortion.cpp:92
EffectDistortion::mParam2T
wxTextCtrl * mParam2T
Definition: Distortion.h:188
ShuttleGuiBase::SetStretchyCol
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:195
ID_Threshold
@ ID_Threshold
Definition: Compressor.cpp:53
EffectDistortion::RealtimeProcess
size_t RealtimeProcess(int group, float **inbuf, float **outbuf, size_t numSamples) override
Definition: Distortion.cpp:272
Effect::SetBlockSize
size_t SetBlockSize(size_t maxBlockSize) override
Definition: Effect.cpp:316
EffectDistortion::SupportsRealtime
bool SupportsRealtime() override
Definition: Distortion.cpp:213
END_EVENT_TABLE
END_EVENT_TABLE()
EffectDistortion::OnThresholdSlider
void OnThresholdSlider(wxCommandEvent &evt)
Definition: Distortion.cpp:648
EffectDistortion::Params::mRepeats
int mRepeats
Definition: Distortion.h:61
EffectDistortion::WaveShaper
float WaveShaper(float sample)
Definition: Distortion.cpp:1288
EffectDistortionState::threshold
double threshold
Definition: Distortion.h:34
ReadAndVerifyBool
#define ReadAndVerifyBool(name)
Definition: Effect.h:634
anonymous_namespace{Distortion.cpp}::reg
BuiltinEffectsModule::Registration< EffectDistortion > reg
Definition: Distortion.cpp:150
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
EffectDistortion::ID_Param1
@ ID_Param1
Definition: Distortion.h:108
EffectDistortion::TransferDataFromWindow
bool TransferDataFromWindow() override
Definition: Distortion.cpp:516
EffectDistortion::EvenHarmonicTable
void EvenHarmonicTable()
Definition: Distortion.cpp:1155