Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
EffectDistortion Class Referencefinal

A WaveShaper distortion effect. More...

#include <Distortion.h>

Inheritance diagram for EffectDistortion:
[legend]
Collaboration diagram for EffectDistortion:
[legend]

Classes

struct  Params
 

Public Member Functions

 EffectDistortion ()
 
virtual ~EffectDistortion ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
ManualPageID ManualPage () const override
 Name of a page in the Audacity alpha manual, default is empty. More...
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool DoLoadFactoryPreset (int id)
 
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...
 
bool ProcessInitialize (EffectSettings &settings, double sampleRate, sampleCount totalLen, 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 sampleRate) override
 
bool RealtimeAddProcessor (EffectSettings &settings, 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
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Add controls to effect panel; always succeeds. More...
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
- Public Member Functions inherited from StatefulPerTrackEffect
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
virtual sampleCount GetLatency ()
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, sampleCount totalLen, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize ()
 
virtual size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 Called for destructive effect computation. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (EffectSettings &settings)
 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 SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
- Public Member Functions inherited from PerTrackEffect
 ~PerTrackEffect () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
bool LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 Change settings to a user-named preset. More...
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
bool LoadFactoryPreset (int id, EffectSettings &settings) const override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults (EffectSettings &settings) const override
 Change settings back to "factory default". More...
 
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...
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
void ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
bool LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual void ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual bool LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
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 int GetMidiInCount () const
 Function that has not yet found a use. More...
 
virtual int GetMidiOutCount () const
 Function that has not yet found a use. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Member Functions

static ParamsFetchParameters (EffectDistortion &e, EffectSettings &)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
static void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Distortion") }
 
- Static Public Attributes inherited from EffectPlugin
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 

Private Types

enum  control {
  ID_Type = 10000 , ID_DCBlock , ID_Threshold , ID_NoiseFloor ,
  ID_Param1 , ID_Param2 , ID_Repeats
}
 
enum  kTableType {
  kHardClip , kSoftClip , kHalfSinCurve , kExpCurve ,
  kLogCurve , kCubic , kEvenHarmonics , kSinCurve ,
  kLeveller , kRectifier , kHardLimiter , nTableTypes
}
 

Private Member Functions

void InstanceInit (EffectDistortionState &data, float sampleRate)
 
size_t InstanceProcess (EffectSettings &settings, EffectDistortionState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
 
void OnTypeChoice (wxCommandEvent &evt)
 
void OnDCBlockCheckbox (wxCommandEvent &evt)
 
void OnThresholdText (wxCommandEvent &evt)
 
void OnThresholdSlider (wxCommandEvent &evt)
 
void OnNoiseFloorText (wxCommandEvent &evt)
 
void OnNoiseFloorSlider (wxCommandEvent &evt)
 
void OnParam1Text (wxCommandEvent &evt)
 
void OnParam1Slider (wxCommandEvent &evt)
 
void OnParam2Text (wxCommandEvent &evt)
 
void OnParam2Slider (wxCommandEvent &evt)
 
void OnRepeatsText (wxCommandEvent &evt)
 
void OnRepeatsSlider (wxCommandEvent &evt)
 
void UpdateUI ()
 
void UpdateControl (control id, bool enable, TranslatableString name)
 
void UpdateControlText (wxTextCtrl *textCtrl, wxString &string, bool enabled)
 
void MakeTable ()
 
float WaveShaper (float sample)
 
float DCFilter (EffectDistortionState &data, float sample)
 
void HardClip ()
 
void SoftClip ()
 
void ExponentialTable ()
 
void LogarithmicTable ()
 
void HalfSinTable ()
 
void CubicTable ()
 
void EvenHarmonicTable ()
 
void SineTable ()
 
void Leveller ()
 
void Rectifier ()
 
void HardLimiter ()
 
void CopyHalfTable ()
 
float LogCurve (double threshold, float value, double ratio)
 
double Cubic (double x)
 
const EffectParameterMethodsParameters () const override
 

Private Attributes

EffectDistortionState mMaster
 
std::vector< EffectDistortionStatemSlaves
 
double mTable [TABLESIZE]
 
double mThreshold
 
bool mbSavedFilterState
 
double mMakeupGain
 
int mTypChoiceIndex
 
wxChoice * mTypeChoiceCtrl
 
wxTextCtrl * mThresholdT
 
wxTextCtrl * mNoiseFloorT
 
wxTextCtrl * mParam1T
 
wxTextCtrl * mParam2T
 
wxTextCtrl * mRepeatsT
 
wxSlider * mThresholdS
 
wxSlider * mNoiseFloorS
 
wxSlider * mParam1S
 
wxSlider * mParam2S
 
wxSlider * mRepeatsS
 
wxCheckBox * mDCBlockCheckBox
 
wxStaticText * mThresholdTxt
 
wxStaticText * mNoiseFloorTxt
 
wxStaticText * mParam1Txt
 
wxStaticText * mParam2Txt
 
wxStaticText * mRepeatsTxt
 
wxString mOldThresholdTxt
 
wxString mOldmNoiseFloorTxt
 
wxString mOldParam1Txt
 
wxString mOldParam2Txt
 
wxString mOldRepeatsTxt
 
Params mParams
 

Static Private Attributes

static const EnumValueSymbol kTableTypeStrings [nTableTypes]
 
static constexpr EnumParameter TableTypeIndx
 
static constexpr EffectParameter DCBlock
 
static constexpr EffectParameter Threshold_dB
 
static constexpr EffectParameter NoiseFloor
 
static constexpr EffectParameter Param1
 
static constexpr EffectParameter Param2
 
static constexpr EffectParameter Repeats
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Protected Member Functions inherited from PerTrackEffect
bool DoPass1 () const
 
bool DoPass2 () const
 
bool Process (EffectInstance &instance, EffectSettings &settings) const
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access)
 Add controls to effect panel; always succeeds. More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Protected Attributes inherited from PerTrackEffect
sampleCount mSampleCnt {}
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Protected Attributes inherited from EffectUIClientInterface
friend EffectUIValidator
 
friend DefaultEffectUIValidator
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

A WaveShaper distortion effect.

Definition at line 47 of file Distortion.h.

Member Enumeration Documentation

◆ control

Enumerator
ID_Type 
ID_DCBlock 
ID_Threshold 
ID_NoiseFloor 
ID_Param1 
ID_Param2 
ID_Repeats 

Definition at line 109 of file Distortion.h.

◆ kTableType

Enumerator
kHardClip 
kSoftClip 
kHalfSinCurve 
kExpCurve 
kLogCurve 
kCubic 
kEvenHarmonics 
kSinCurve 
kLeveller 
kRectifier 
kHardLimiter 
nTableTypes 

Definition at line 222 of file Distortion.h.

Constructor & Destructor Documentation

◆ EffectDistortion()

EffectDistortion::EffectDistortion ( )

Definition at line 151 of file Distortion.cpp.

152{
153 Parameters().Reset(*this);
154 wxASSERT(nTableTypes == WXSIZEOF(kTableTypeStrings));
155 mMakeupGain = 1.0;
157
158 SetLinearEffectFlag(false);
159}
void SetLinearEffectFlag(bool linearEffectFlag)
Definition: EffectBase.cpp:218
bool mbSavedFilterState
Definition: Distortion.h:182
double mMakeupGain
Definition: Distortion.h:186
static const EnumValueSymbol kTableTypeStrings[nTableTypes]
Definition: Distortion.h:238
static constexpr EffectParameter DCBlock
Definition: Distortion.h:243
const EffectParameterMethods & Parameters() const override
Definition: Distortion.cpp:62
virtual void Reset(Effect &effect) const =0
const Type def
Default value.
Definition: Shuttle.h:29

Referenced by Parameters().

Here is the caller graph for this function:

◆ ~EffectDistortion()

EffectDistortion::~EffectDistortion ( )
virtual

Definition at line 161 of file Distortion.cpp.

162{
163}

Member Function Documentation

◆ CopyHalfTable()

void EffectDistortion::CopyHalfTable ( )
private

Definition at line 1198 of file Distortion.cpp.

1199{
1200 // Copy negative half of table from positive half
1201 int count = TABLESIZE - 1;
1202 for (int n = 0; n < STEPS; n++) {
1203 mTable[n] = -mTable[count];
1204 count--;
1205 }
1206}
#define TABLESIZE
Definition: Distortion.h:27
#define STEPS
Definition: Distortion.h:26
double mTable[TABLESIZE]
Definition: Distortion.h:180

References mTable, STEPS, and TABLESIZE.

Referenced by ExponentialTable(), HalfSinTable(), Leveller(), LogarithmicTable(), SineTable(), and SoftClip().

Here is the caller graph for this function:

◆ Cubic()

double EffectDistortion::Cubic ( double  x)
inlineprivate

Definition at line 1067 of file Distortion.cpp.

1068{
1069 if (mParams.mParam1 == 0.0)
1070 return x;
1071
1072 return x - (std::pow(x, 3.0) / 3.0);
1073}

References EffectDistortion::Params::mParam1, and mParams.

Referenced by CubicTable().

Here is the caller graph for this function:

◆ CubicTable()

void EffectDistortion::CubicTable ( )
private

Definition at line 1041 of file Distortion.cpp.

1042{
1043 double amount = mParams.mParam1 * std::sqrt(3.0) / 100.0;
1044 double gain = 1.0;
1045 if (amount != 0.0)
1046 gain = 1.0 / Cubic(std::min(amount, 1.0));
1047
1048 double stepsize = amount / STEPS;
1049 double x = -amount;
1050
1051 if (amount == 0) {
1052 for (int i = 0; i < TABLESIZE; i++) {
1053 mTable[i] = (i / (double)STEPS) - 1.0;
1054 }
1055 }
1056 else {
1057 for (int i = 0; i < TABLESIZE; i++) {
1058 mTable[i] = gain * Cubic(x);
1059 for (int j = 0; j < mParams.mRepeats; j++) {
1060 mTable[i] = gain * Cubic(mTable[i] * amount);
1061 }
1062 x += stepsize;
1063 }
1064 }
1065}
int min(int a, int b)
double Cubic(double x)

References Cubic(), min(), EffectDistortion::Params::mParam1, mParams, EffectDistortion::Params::mRepeats, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DCFilter()

float EffectDistortion::DCFilter ( EffectDistortionState data,
float  sample 
)
private

Definition at line 1239 of file Distortion.cpp.

1240{
1241 // Rolling average gives less offset at the start than an IIR filter.
1242 const unsigned int queueLength = std::floor(data.samplerate / 20.0);
1243
1244 data.queuetotal += sample;
1245 data.queuesamples.push(sample);
1246
1247 if (data.queuesamples.size() > queueLength) {
1248 data.queuetotal -= data.queuesamples.front();
1249 data.queuesamples.pop();
1250 }
1251
1252 return sample - (data.queuetotal / data.queuesamples.size());
1253}
std::queue< float > queuesamples
Definition: Distortion.h:43

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

Referenced by InstanceProcess().

Here is the caller graph for this function:

◆ DoLoadFactoryPreset()

bool EffectDistortion::DoLoadFactoryPreset ( int  id)

Definition at line 271 of file Distortion.cpp.

272{
273 if (id < 0 || id >= (int) WXSIZEOF(FactoryPresets))
274 {
275 return false;
276 }
277
278 mParams = FactoryPresets[id].params;
280
281 return true;
282}
static const struct @20 FactoryPresets[]
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:535
int id

References DB_TO_LINEAR, FactoryPresets, id, mParams, mThreshold, and EffectDistortion::Params::mThreshold_dB.

Referenced by LoadFactoryPreset().

Here is the caller graph for this function:

◆ EvenHarmonicTable()

void EffectDistortion::EvenHarmonicTable ( )
private

Definition at line 1076 of file Distortion.cpp.

1077{
1078 double amount = mParams.mParam1 / -100.0;
1079 // double C = std::sin(std::max(0.001, mParams.mParam2) / 100.0) * 10.0;
1080 double C = std::max(0.001, mParams.mParam2) / 10.0;
1081
1082 double step = 1.0 / STEPS;
1083 double xval = -1.0;
1084
1085 for (int i = 0; i < TABLESIZE; i++) {
1086 mTable[i] = ((1 + amount) * xval) -
1087 (xval * (amount / std::tanh(C)) * std::tanh(C * xval));
1088 xval += step;
1089 }
1090}

References EffectDistortion::Params::mParam1, EffectDistortion::Params::mParam2, mParams, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the caller graph for this function:

◆ ExponentialTable()

void EffectDistortion::ExponentialTable ( )
private

Definition at line 989 of file Distortion.cpp.

990{
991 double amount = std::min(0.999, DB_TO_LINEAR(-1 * mParams.mParam1)); // avoid divide by zero
992
993 for (int n = STEPS; n < TABLESIZE; n++) {
994 double linVal = n/(float)STEPS;
995 double scale = -1.0 / (1.0 - amount); // unity gain at 0dB
996 double curve = std::exp((linVal - 1) * std::log(amount));
997 mTable[n] = scale * (curve -1);
998 }
1000}

References CopyHalfTable(), DB_TO_LINEAR, min(), EffectDistortion::Params::mParam1, mParams, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FetchParameters()

static Params * EffectDistortion::FetchParameters ( EffectDistortion e,
EffectSettings  
)
inlinestatic

Definition at line 52 of file Distortion.h.

52{ return &e.mParams; }

References mParams.

◆ GetAudioInCount()

unsigned EffectDistortion::GetAudioInCount ( ) const
overridevirtual

How many input buffers to allocate at once.

If the effect ALWAYS processes channels independently, this can return 1

Implements EffectInstanceFactory.

Definition at line 196 of file Distortion.cpp.

197{
198 return 1;
199}

◆ GetAudioOutCount()

unsigned EffectDistortion::GetAudioOutCount ( ) const
overridevirtual

How many output buffers to allocate at once.

Implements EffectInstanceFactory.

Definition at line 201 of file Distortion.cpp.

202{
203 return 1;
204}

◆ GetDescription()

TranslatableString EffectDistortion::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 172 of file Distortion.cpp.

173{
174 return XO("Waveshaping distortion effect");
175}
#define XO(s)
Definition: Internat.h:31

References XO.

◆ GetFactoryPresets()

RegistryPaths EffectDistortion::GetFactoryPresets ( ) const
overridevirtual

Report names of factory presets.

Implements EffectSettingsManager.

Definition at line 253 of file Distortion.cpp.

254{
256
257 for (size_t i = 0; i < WXSIZEOF(FactoryPresets); i++)
258 {
259 names.push_back( FactoryPresets[i].name.Translation() );
260 }
261
262 return names;
263}
const TranslatableString name
Definition: Distortion.cpp:82
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
static TranslatableStrings names
Definition: TagsEditor.cpp:151
wxString Translation() const

References FactoryPresets, name, names, and TranslatableString::Translation().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectDistortion::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 167 of file Distortion.cpp.

168{
169 return Symbol;
170}
static const ComponentInterfaceSymbol Symbol
Definition: Distortion.h:53

References Symbol.

◆ GetType()

EffectType EffectDistortion::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 184 of file Distortion.cpp.

185{
186 return EffectTypeProcess;
187}
@ EffectTypeProcess

References EffectTypeProcess.

◆ HalfSinTable()

void EffectDistortion::HalfSinTable ( )
private

Definition at line 1023 of file Distortion.cpp.

1024{
1025 int iter = std::floor(mParams.mParam1 / 20.0);
1026 double fractionalpart = (mParams.mParam1 / 20.0) - iter;
1027 double stepsize = 1.0 / STEPS;
1028 double linVal = 0;
1029
1030 for (int n = STEPS; n < TABLESIZE; n++) {
1031 mTable[n] = linVal;
1032 for (int i = 0; i < iter; i++) {
1033 mTable[n] = std::sin(mTable[n] * M_PI_2);
1034 }
1035 mTable[n] += ((std::sin(mTable[n] * M_PI_2) - mTable[n]) * fractionalpart);
1036 linVal += stepsize;
1037 }
1038 CopyHalfTable();
1039}
#define M_PI_2
Definition: Distortion.cpp:32

References CopyHalfTable(), M_PI_2, EffectDistortion::Params::mParam1, mParams, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HardClip()

void EffectDistortion::HardClip ( )
private

Definition at line 949 of file Distortion.cpp.

950{
951 double lowThresh = 1 - mThreshold;
952 double highThresh = 1 + mThreshold;
953
954 for (int n = 0; n < TABLESIZE; n++) {
955 if (n < (STEPS * lowThresh))
956 mTable[n] = - mThreshold;
957 else if (n > (STEPS * highThresh))
958 mTable[n] = mThreshold;
959 else
960 mTable[n] = n/(double)STEPS - 1;
961
962 mMakeupGain = 1.0 / mThreshold;
963 }
964}

References mMakeupGain, mTable, mThreshold, STEPS, and TABLESIZE.

Referenced by HardLimiter(), and MakeTable().

Here is the caller graph for this function:

◆ HardLimiter()

void EffectDistortion::HardLimiter ( )
private

Definition at line 1187 of file Distortion.cpp.

1188{
1189 // The LADSPA "hardLimiter 1413" is basically hard clipping,
1190 // but with a 'kind of' wet/dry mix:
1191 // out = ((wet-residual)*clipped) + (residual*in)
1192 HardClip();
1193}

References HardClip().

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InstanceInit()

void EffectDistortion::InstanceInit ( EffectDistortionState data,
float  sampleRate 
)
private

Definition at line 445 of file Distortion.cpp.

446{
447 data.samplerate = sampleRate;
448 data.skipcount = 0;
450 data.dcblock = mParams.mDCBlock;
453 data.param1 = mParams.mParam1;
454 data.param2 = mParams.mParam2;
455 data.repeats = mParams.mRepeats;
456
457 // DC block filter variables
458 data.queuetotal = 0.0;
459
460 //std::queue<float>().swap(data.queuesamples);
461 while (!data.queuesamples.empty())
462 data.queuesamples.pop();
463
464 MakeTable();
465
466 return;
467}
sampleCount skipcount
Definition: Distortion.h:33

References EffectDistortionState::dcblock, MakeTable(), EffectDistortion::Params::mDCBlock, EffectDistortion::Params::mNoiseFloor, EffectDistortion::Params::mParam1, EffectDistortion::Params::mParam2, mParams, EffectDistortion::Params::mRepeats, EffectDistortion::Params::mTableChoiceIndx, EffectDistortion::Params::mThreshold_dB, EffectDistortionState::noisefloor, EffectDistortionState::param1, EffectDistortionState::param2, EffectDistortionState::queuesamples, EffectDistortionState::queuetotal, EffectDistortionState::repeats, EffectDistortionState::samplerate, EffectDistortionState::skipcount, EffectDistortionState::tablechoiceindx, and EffectDistortionState::threshold.

Referenced by ProcessInitialize(), and RealtimeAddProcessor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InstanceProcess()

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

Definition at line 469 of file Distortion.cpp.

472{
473 const float *ibuf = inBlock[0];
474 float *obuf = outBlock[0];
475
476 bool update = (mParams.mTableChoiceIndx == data.tablechoiceindx &&
479 mParams.mParam1 == data.param1 &&
480 mParams.mParam2 == data.param2 &&
481 mParams.mRepeats == data.repeats)? false : true;
482
483 double p1 = mParams.mParam1 / 100.0;
484 double p2 = mParams.mParam2 / 100.0;
485
489 data.param1 = mParams.mParam1;
490 data.repeats = mParams.mRepeats;
491
492 for (decltype(blockLen) i = 0; i < blockLen; i++) {
493 if (update && ((data.skipcount++) % skipsamples == 0)) {
494 MakeTable();
495 }
496
498 {
499 case kHardClip:
500 // Param2 = make-up gain.
501 obuf[i] = WaveShaper(ibuf[i]) * ((1 - p2) + (mMakeupGain * p2));
502 break;
503 case kSoftClip:
504 // Param2 = make-up gain.
505 obuf[i] = WaveShaper(ibuf[i]) * ((1 - p2) + (mMakeupGain * p2));
506 break;
507 case kHalfSinCurve:
508 obuf[i] = WaveShaper(ibuf[i]) * p2;
509 break;
510 case kExpCurve:
511 obuf[i] = WaveShaper(ibuf[i]) * p2;
512 break;
513 case kLogCurve:
514 obuf[i] = WaveShaper(ibuf[i]) * p2;
515 break;
516 case kCubic:
517 obuf[i] = WaveShaper(ibuf[i]) * p2;
518 break;
519 case kEvenHarmonics:
520 obuf[i] = WaveShaper(ibuf[i]);
521 break;
522 case kSinCurve:
523 obuf[i] = WaveShaper(ibuf[i]) * p2;
524 break;
525 case kLeveller:
526 obuf[i] = WaveShaper(ibuf[i]);
527 break;
528 case kRectifier:
529 obuf[i] = WaveShaper(ibuf[i]);
530 break;
531 case kHardLimiter:
532 // Mix equivalent to LADSPA effect's "Wet / Residual" mix
533 obuf[i] = (WaveShaper(ibuf[i]) * (p1 - p2)) + (ibuf[i] * p2);
534 break;
535 default:
536 obuf[i] = WaveShaper(ibuf[i]);
537 }
538 if (mParams.mDCBlock) {
539 obuf[i] = DCFilter(data, obuf[i]);
540 }
541 }
542
543 return blockLen;
544}
#define skipsamples
Definition: Distortion.cpp:78
float WaveShaper(float sample)
float DCFilter(EffectDistortionState &data, float sample)

References DCFilter(), kCubic, kEvenHarmonics, kExpCurve, kHalfSinCurve, kHardClip, kHardLimiter, kLeveller, kLogCurve, kRectifier, kSinCurve, kSoftClip, MakeTable(), EffectDistortion::Params::mDCBlock, mMakeupGain, EffectDistortion::Params::mNoiseFloor, EffectDistortion::Params::mParam1, EffectDistortion::Params::mParam2, mParams, EffectDistortion::Params::mRepeats, EffectDistortion::Params::mTableChoiceIndx, EffectDistortion::Params::mThreshold_dB, EffectDistortionState::noisefloor, EffectDistortionState::param1, EffectDistortionState::param2, EffectDistortionState::repeats, EffectDistortionState::skipcount, skipsamples, EffectDistortionState::tablechoiceindx, EffectDistortionState::threshold, and WaveShaper().

Referenced by ProcessBlock(), and RealtimeProcess().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Leveller()

void EffectDistortion::Leveller ( )
private

Definition at line 1110 of file Distortion.cpp.

1111{
1112 double noiseFloor = DB_TO_LINEAR(mParams.mNoiseFloor);
1113 int numPasses = mParams.mRepeats;
1114 double fractionalPass = mParams.mParam1 / 100.0;
1115
1116 const int numPoints = 6;
1117 const double gainFactors[numPoints] = { 0.80, 1.00, 1.20, 1.20, 1.00, 0.80 };
1118 double gainLimits[numPoints] = { 0.0001, 0.0, 0.1, 0.3, 0.5, 1.0 };
1119 double addOnValues[numPoints];
1120
1121 gainLimits[1] = noiseFloor;
1122 /* In the original Leveller effect, behaviour was undefined for threshold > 20 dB.
1123 * If we want to support > 20 dB we need to scale the points to keep them non-decreasing.
1124 *
1125 * if (noiseFloor > gainLimits[2]) {
1126 * for (int i = 3; i < numPoints; i++) {
1127 * gainLimits[i] = noiseFloor + ((1 - noiseFloor)*((gainLimits[i] - 0.1) / 0.9));
1128 * }
1129 * gainLimits[2] = noiseFloor;
1130 * }
1131 */
1132
1133 // Calculate add-on values
1134 addOnValues[0] = 0.0;
1135 for (int i = 0; i < numPoints-1; i++) {
1136 addOnValues[i+1] = addOnValues[i] + (gainLimits[i] * (gainFactors[i] - gainFactors[1 + i]));
1137 }
1138
1139 // Positive half of table.
1140 // The original effect increased the 'strength' of the effect by
1141 // repeated passes over the audio data.
1142 // Here we model that more efficiently by repeated passes over a linear table.
1143 for (int n = STEPS; n < TABLESIZE; n++) {
1144 mTable[n] = ((double) (n - STEPS) / (double) STEPS);
1145 for (int j = 0; j < numPasses; j++) {
1146 // Find the highest index for gain adjustment
1147 int index = numPoints - 1;
1148 for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--) {
1149 index = i;
1150 }
1151 // the whole number of 'repeats'
1152 mTable[n] = (mTable[n] * gainFactors[index]) + addOnValues[index];
1153 }
1154 // Extrapolate for fine adjustment.
1155 // tiny fractions are not worth the processing time
1156 if (fractionalPass > 0.001) {
1157 int index = numPoints - 1;
1158 for (int i = index; i >= 0 && mTable[n] < gainLimits[i]; i--) {
1159 index = i;
1160 }
1161 mTable[n] += fractionalPass * ((mTable[n] * (gainFactors[index] - 1)) + addOnValues[index]);
1162 }
1163 }
1164 CopyHalfTable();
1165}

References CopyHalfTable(), DB_TO_LINEAR, EffectDistortion::Params::mNoiseFloor, EffectDistortion::Params::mParam1, mParams, EffectDistortion::Params::mRepeats, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadFactoryPreset()

bool EffectDistortion::LoadFactoryPreset ( int  id,
EffectSettings settings 
) const
overridevirtual

Change settings to the preset whose name is GetFactoryPresets()[id]

Implements EffectSettingsManager.

Definition at line 265 of file Distortion.cpp.

266{
267 // To do: externalize state so const_cast isn't needed
268 return const_cast<EffectDistortion*>(this)->DoLoadFactoryPreset(id);
269}
A WaveShaper distortion effect.
Definition: Distortion.h:48
bool DoLoadFactoryPreset(int id)
Definition: Distortion.cpp:271

References DoLoadFactoryPreset().

Here is the call graph for this function:

◆ LogarithmicTable()

void EffectDistortion::LogarithmicTable ( )
private

Definition at line 1002 of file Distortion.cpp.

1003{
1004 double amount = mParams.mParam1;
1005 double stepsize = 1.0 / STEPS;
1006 double linVal = 0;
1007
1008 if (amount == 0){
1009 for (int n = STEPS; n < TABLESIZE; n++) {
1010 mTable[n] = linVal;
1011 linVal += stepsize;
1012 }
1013 }
1014 else {
1015 for (int n = STEPS; n < TABLESIZE; n++) {
1016 mTable[n] = std::log(1 + (amount * linVal)) / std::log(1 + amount);
1017 linVal += stepsize;
1018 }
1019 }
1020 CopyHalfTable();
1021}

References CopyHalfTable(), EffectDistortion::Params::mParam1, mParams, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogCurve()

float EffectDistortion::LogCurve ( double  threshold,
float  value,
double  ratio 
)
inlineprivate

Definition at line 984 of file Distortion.cpp.

985{
986 return threshold + ((std::exp(ratio * (threshold - value)) - 1) / -ratio);
987}

Referenced by SoftClip().

Here is the caller graph for this function:

◆ MakeTable()

void EffectDistortion::MakeTable ( )
private

Definition at line 904 of file Distortion.cpp.

905{
907 {
908 case kHardClip:
909 HardClip();
910 break;
911 case kSoftClip:
912 SoftClip();
913 break;
914 case kHalfSinCurve:
915 HalfSinTable();
916 break;
917 case kExpCurve:
919 break;
920 case kLogCurve:
922 break;
923 case kCubic:
924 CubicTable();
925 break;
926 case kEvenHarmonics:
928 break;
929 case kSinCurve:
930 SineTable();
931 break;
932 case kLeveller:
933 Leveller();
934 break;
935 case kRectifier:
936 Rectifier();
937 break;
938 case kHardLimiter:
939 HardLimiter();
940 break;
941 }
942}
void ExponentialTable()
Definition: Distortion.cpp:989
void EvenHarmonicTable()

References CubicTable(), EvenHarmonicTable(), ExponentialTable(), HalfSinTable(), HardClip(), HardLimiter(), kCubic, kEvenHarmonics, kExpCurve, kHalfSinCurve, kHardClip, kHardLimiter, kLeveller, kLogCurve, kRectifier, kSinCurve, kSoftClip, Leveller(), LogarithmicTable(), mParams, EffectDistortion::Params::mTableChoiceIndx, Rectifier(), SineTable(), and SoftClip().

Referenced by InstanceInit(), and InstanceProcess().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ManualPage()

ManualPageID EffectDistortion::ManualPage ( ) const
overridevirtual

Name of a page in the Audacity alpha manual, default is empty.

Reimplemented from EffectDefinitionInterface.

Definition at line 177 of file Distortion.cpp.

178{
179 return L"Distortion";
180}

◆ OnDCBlockCheckbox()

void EffectDistortion::OnDCBlockCheckbox ( wxCommandEvent &  evt)
private

Definition at line 553 of file Distortion.cpp.

554{
555 mParams.mDCBlock = mDCBlockCheckBox->GetValue();
557}
wxCheckBox * mDCBlockCheckBox
Definition: Distortion.h:203

References mbSavedFilterState, EffectDistortion::Params::mDCBlock, mDCBlockCheckBox, and mParams.

◆ OnNoiseFloorSlider()

void EffectDistortion::OnNoiseFloorSlider ( wxCommandEvent &  evt)
private

Definition at line 583 of file Distortion.cpp.

584{
585 mParams.mNoiseFloor = (double) evt.GetInt();
586 mNoiseFloorT->GetValidator()->TransferToWindow();
587}
wxTextCtrl * mNoiseFloorT
Definition: Distortion.h:192

References EffectDistortion::Params::mNoiseFloor, mNoiseFloorT, and mParams.

◆ OnNoiseFloorText()

void EffectDistortion::OnNoiseFloorText ( wxCommandEvent &  evt)
private

Definition at line 577 of file Distortion.cpp.

578{
579 mNoiseFloorT->GetValidator()->TransferFromWindow();
580 mNoiseFloorS->SetValue((int) floor(mParams.mNoiseFloor + 0.5));
581}
wxSlider * mNoiseFloorS
Definition: Distortion.h:198

References EffectDistortion::Params::mNoiseFloor, mNoiseFloorS, mNoiseFloorT, and mParams.

◆ OnParam1Slider()

void EffectDistortion::OnParam1Slider ( wxCommandEvent &  evt)
private

Definition at line 596 of file Distortion.cpp.

597{
598 mParams.mParam1 = (double) evt.GetInt();
599 mParam1T->GetValidator()->TransferToWindow();
600}
wxTextCtrl * mParam1T
Definition: Distortion.h:193

References EffectDistortion::Params::mParam1, mParam1T, and mParams.

◆ OnParam1Text()

void EffectDistortion::OnParam1Text ( wxCommandEvent &  evt)
private

Definition at line 590 of file Distortion.cpp.

591{
592 mParam1T->GetValidator()->TransferFromWindow();
593 mParam1S->SetValue((int) floor(mParams.mParam1 + 0.5));
594}
wxSlider * mParam1S
Definition: Distortion.h:199

References EffectDistortion::Params::mParam1, mParam1S, mParam1T, and mParams.

◆ OnParam2Slider()

void EffectDistortion::OnParam2Slider ( wxCommandEvent &  evt)
private

Definition at line 608 of file Distortion.cpp.

609{
610 mParams.mParam2 = (double) evt.GetInt();
611 mParam2T->GetValidator()->TransferToWindow();
612}
wxTextCtrl * mParam2T
Definition: Distortion.h:194

References EffectDistortion::Params::mParam2, mParam2T, and mParams.

◆ OnParam2Text()

void EffectDistortion::OnParam2Text ( wxCommandEvent &  evt)
private

Definition at line 602 of file Distortion.cpp.

603{
604 mParam2T->GetValidator()->TransferFromWindow();
605 mParam2S->SetValue((int) floor(mParams.mParam2 + 0.5));
606}
wxSlider * mParam2S
Definition: Distortion.h:200

References EffectDistortion::Params::mParam2, mParam2S, mParam2T, and mParams.

◆ OnRepeatsSlider()

void EffectDistortion::OnRepeatsSlider ( wxCommandEvent &  evt)
private

Definition at line 620 of file Distortion.cpp.

621{
622 mParams.mRepeats = evt.GetInt();
623 mRepeatsT->GetValidator()->TransferToWindow();
624
625}
wxTextCtrl * mRepeatsT
Definition: Distortion.h:195

References mParams, EffectDistortion::Params::mRepeats, and mRepeatsT.

◆ OnRepeatsText()

void EffectDistortion::OnRepeatsText ( wxCommandEvent &  evt)
private

Definition at line 614 of file Distortion.cpp.

615{
616 mRepeatsT->GetValidator()->TransferFromWindow();
617 mRepeatsS->SetValue(mParams.mRepeats);
618}
wxSlider * mRepeatsS
Definition: Distortion.h:201

References mParams, EffectDistortion::Params::mRepeats, mRepeatsS, and mRepeatsT.

◆ OnThresholdSlider()

void EffectDistortion::OnThresholdSlider ( wxCommandEvent &  evt)
private

Definition at line 567 of file Distortion.cpp.

568{
569 static const double MIN_Threshold_Linear = DB_TO_LINEAR(Threshold_dB.min);
570
571 mThreshold = (double) evt.GetInt() / Threshold_dB.scale;
573 mThreshold = std::max(MIN_Threshold_Linear, mThreshold);
574 mThresholdT->GetValidator()->TransferToWindow();
575}
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:536
static constexpr EffectParameter Threshold_dB
Definition: Distortion.h:245
wxTextCtrl * mThresholdT
Definition: Distortion.h:191
const Type scale
Scaling factor, for slider control.
Definition: Shuttle.h:32
const Type min
Minimum value.
Definition: Shuttle.h:30

References DB_TO_LINEAR, LINEAR_TO_DB, EffectParameter< Structure, Member, Type, Value >::min, mParams, mThreshold, EffectDistortion::Params::mThreshold_dB, mThresholdT, EffectParameter< Structure, Member, Type, Value >::scale, and Threshold_dB.

◆ OnThresholdText()

void EffectDistortion::OnThresholdText ( wxCommandEvent &  evt)
private

◆ OnTypeChoice()

void EffectDistortion::OnTypeChoice ( wxCommandEvent &  evt)
private

Definition at line 546 of file Distortion.cpp.

547{
548 mTypeChoiceCtrl->GetValidator()->TransferFromWindow();
549
550 UpdateUI();
551}
wxChoice * mTypeChoiceCtrl
Definition: Distortion.h:190

References mTypeChoiceCtrl, and UpdateUI().

Here is the call graph for this function:

◆ Parameters()

const EffectParameterMethods & EffectDistortion::Parameters ( ) const
overrideprivatevirtual

Reimplemented from Effect.

Definition at line 62 of file Distortion.cpp.

63{
66 > parameters{
67 [](EffectDistortion &e, EffectSettings &settings, Params &p,
68 bool updating) {
69 if (!updating)
70 e.mThreshold = DB_TO_LINEAR(p.mThreshold_dB);
71 return true;
72 }
73 };
74 return parameters;
75}
static Settings & settings()
Definition: TrackInfo.cpp:87
Generates EffectParameterMethods overrides from variadic template arguments.
static constexpr EffectParameter Param2
Definition: Distortion.h:251
static constexpr EffectParameter Param1
Definition: Distortion.h:249
static constexpr EffectParameter Repeats
Definition: Distortion.h:253
static constexpr EnumParameter TableTypeIndx
Definition: Distortion.h:241
static constexpr EffectParameter NoiseFloor
Definition: Distortion.h:247
Externalized state of a plug-in.

References DB_TO_LINEAR, DCBlock, EffectDistortion(), mThreshold, NoiseFloor, Param1, Param2, Repeats, settings(), TableTypeIndx, and Threshold_dB.

Here is the call graph for this function:

◆ PopulateOrExchange()

std::unique_ptr< EffectUIValidator > EffectDistortion::PopulateOrExchange ( ShuttleGui S,
EffectInstance instance,
EffectSettingsAccess access 
)
overridevirtual

Add controls to effect panel; always succeeds.

Returns
if not null, then return it from Effect::PopulateUI instead of a DefaultEffectUIValidator; default implementation returns null

Reimplemented from Effect.

Definition at line 287 of file Distortion.cpp.

289{
290 S.AddSpace(0, 5);
291 S.StartVerticalLay();
292 {
293 S.StartMultiColumn(4, wxCENTER);
294 {
296 .MinSize( { -1, -1 } )
298 .AddChoice(XXO("Distortion type:"),
300
301 mDCBlockCheckBox = S.Id(ID_DCBlock).AddCheckBox(XXO("DC blocking filter"),
302 DCBlock.def);
303 }
304 S.EndMultiColumn();
305 S.AddSpace(0, 10);
306
307
308 S.StartStatic(XO("Threshold controls"));
309 {
310 S.StartMultiColumn(4, wxEXPAND);
311 S.SetStretchyCol(2);
312 {
313 // Allow space for first Column
314 S.AddSpace(250,0); S.AddSpace(0,0); S.AddSpace(0,0); S.AddSpace(0,0);
315
316 // Upper threshold control
317 mThresholdTxt = S.AddVariableText(defaultLabel(0),
318 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
320 .Name(defaultLabel(0))
321 .Validator<FloatingPointValidator<double>>(
322 2, &mParams.mThreshold_dB, NumValidatorStyle::DEFAULT,
324 .AddTextBox( {}, wxT(""), 10);
325
327 .Name(defaultLabel(0))
328 .Style(wxSL_HORIZONTAL)
329 .AddSlider( {}, 0,
332 S.AddSpace(20, 0);
333
334 // Noise floor control
335 mNoiseFloorTxt = S.AddVariableText(defaultLabel(1),
336 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
338 .Name(defaultLabel(1))
339 .Validator<FloatingPointValidator<double>>(
340 2, &mParams.mNoiseFloor, NumValidatorStyle::DEFAULT,
342 )
343 .AddTextBox( {}, wxT(""), 10);
344
346 .Name(defaultLabel(1))
347 .Style(wxSL_HORIZONTAL)
348 .AddSlider( {}, 0, NoiseFloor.max, NoiseFloor.min);
349 S.AddSpace(20, 0);
350 }
351 S.EndMultiColumn();
352 }
353 S.EndStatic();
354
355 S.StartStatic(XO("Parameter controls"));
356 {
357 S.StartMultiColumn(4, wxEXPAND);
358 S.SetStretchyCol(2);
359 {
360 // Allow space for first Column
361 S.AddSpace(250,0); S.AddSpace(0,0); S.AddSpace(0,0); S.AddSpace(0,0);
362
363 // Parameter1 control
364 mParam1Txt = S.AddVariableText(defaultLabel(2),
365 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
366 mParam1T = S.Id(ID_Param1)
367 .Name(defaultLabel(2))
368 .Validator<FloatingPointValidator<double>>(
369 2, &mParams.mParam1, NumValidatorStyle::DEFAULT,
371 )
372 .AddTextBox( {}, wxT(""), 10);
373
374 mParam1S = S.Id(ID_Param1)
375 .Name(defaultLabel(2))
376 .Style(wxSL_HORIZONTAL)
377 .AddSlider( {}, 0, Param1.max, Param1.min);
378 S.AddSpace(20, 0);
379
380 // Parameter2 control
381 mParam2Txt = S.AddVariableText(defaultLabel(3),
382 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
383 mParam2T = S.Id(ID_Param2)
384 .Name(defaultLabel(3))
385 .Validator<FloatingPointValidator<double>>(
386 2, &mParams.mParam2, NumValidatorStyle::DEFAULT,
388 )
389 .AddTextBox( {}, wxT(""), 10);
390
391 mParam2S = S.Id(ID_Param2)
392 .Name(defaultLabel(3))
393 .Style(wxSL_HORIZONTAL)
394 .AddSlider( {}, 0, Param2.max, Param2.min);
395 S.AddSpace(20, 0);
396
397 // Repeats control
398 mRepeatsTxt = S.AddVariableText(defaultLabel(4),
399 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
401 .Name(defaultLabel(4))
402 .Validator<IntegerValidator<int>>(
403 &mParams.mRepeats, NumValidatorStyle::DEFAULT,
405 )
406 .AddTextBox( {}, wxT(""), 10);
407
409 .Name(defaultLabel(4))
410 .Style(wxSL_HORIZONTAL)
411 .AddSlider( {}, Repeats.def, Repeats.max, Repeats.min);
412 S.AddSpace(20, 0);
413 }
414 S.EndMultiColumn();
415 }
416 S.EndStatic();
417 }
418 S.EndVerticalLay();
419
420 return nullptr;
421}
TranslatableString defaultLabel(int index)
Definition: Distortion.cpp:114
#define XXO(s)
Definition: Internat.h:44
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
#define S(N)
Definition: ToChars.cpp:64
wxStaticText * mRepeatsTxt
Definition: Distortion.h:209
wxStaticText * mParam1Txt
Definition: Distortion.h:207
wxStaticText * mParam2Txt
Definition: Distortion.h:208
wxStaticText * mNoiseFloorTxt
Definition: Distortion.h:206
wxStaticText * mThresholdTxt
Definition: Distortion.h:205
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:53
const Type max
Maximum value.
Definition: Shuttle.h:31

References DB_TO_LINEAR, DCBlock, EffectParameter< Structure, Member, Type, Value >::def, defaultLabel(), ID_DCBlock, ID_NoiseFloor, ID_Param1, ID_Param2, ID_Repeats, ID_Threshold, ID_Type, kTableTypeStrings, EffectParameter< Structure, Member, Type, Value >::max, mDCBlockCheckBox, EffectParameter< Structure, Member, Type, Value >::min, EffectDistortion::Params::mNoiseFloor, mNoiseFloorS, mNoiseFloorT, mNoiseFloorTxt, EffectDistortion::Params::mParam1, mParam1S, mParam1T, mParam1Txt, EffectDistortion::Params::mParam2, mParam2S, mParam2T, mParam2Txt, mParams, EffectDistortion::Params::mRepeats, mRepeatsS, mRepeatsT, mRepeatsTxt, Msgids(), EffectDistortion::Params::mTableChoiceIndx, EffectDistortion::Params::mThreshold_dB, mThresholdS, mThresholdT, mThresholdTxt, mTypeChoiceCtrl, NoiseFloor, nTableTypes, Param1, Param2, Repeats, S, EffectParameter< Structure, Member, Type, Value >::scale, Threshold_dB, XO, and XXO.

Here is the call graph for this function:

◆ ProcessBlock()

size_t EffectDistortion::ProcessBlock ( EffectSettings settings,
const float *const *  inBlock,
float *const *  outBlock,
size_t  blockLen 
)
overridevirtual

Called for destructive effect computation.

Reimplemented from StatefulPerTrackEffect.

Definition at line 213 of file Distortion.cpp.

215{
216 return InstanceProcess(settings, mMaster, inBlock, outBlock, blockLen);
217}
size_t InstanceProcess(EffectSettings &settings, EffectDistortionState &data, const float *const *inBlock, float *const *outBlock, size_t blockLen)
Definition: Distortion.cpp:469
EffectDistortionState mMaster
Definition: Distortion.h:177

References InstanceProcess(), mMaster, and settings().

Here is the call graph for this function:

◆ ProcessInitialize()

bool EffectDistortion::ProcessInitialize ( EffectSettings settings,
double  sampleRate,
sampleCount  totalLen,
ChannelNames  chanMap 
)
overridevirtual

Called at start of destructive processing, for each (mono/stereo) track Default implementation does nothing, returns true

Reimplemented from StatefulPerTrackEffect.

Definition at line 206 of file Distortion.cpp.

208{
209 InstanceInit(mMaster, sampleRate);
210 return true;
211}
void InstanceInit(EffectDistortionState &data, float sampleRate)
Definition: Distortion.cpp:445

References InstanceInit(), and mMaster.

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool EffectDistortion::RealtimeAddProcessor ( EffectSettings settings,
unsigned  numChannels,
float  sampleRate 
)
overridevirtual

Returns
success Default implementation does nothing, returns true Default implementation does nothing, returns true

Reimplemented from StatefulEffectBase.

Definition at line 226 of file Distortion.cpp.

228{
230
231 InstanceInit(slave, sampleRate);
232
233 mSlaves.push_back(slave);
234
235 return true;
236}
std::vector< EffectDistortionState > mSlaves
Definition: Distortion.h:178

References InstanceInit(), and mSlaves.

Here is the call graph for this function:

◆ RealtimeFinalize()

bool EffectDistortion::RealtimeFinalize ( EffectSettings settings)
overridevirtualnoexcept

Returns
success Default implementation does nothing, returns true Default implementation does nothing, returns false

Reimplemented from StatefulEffectBase.

Definition at line 238 of file Distortion.cpp.

239{
240 mSlaves.clear();
241
242 return true;
243}

◆ RealtimeInitialize()

bool EffectDistortion::RealtimeInitialize ( EffectSettings settings,
double  sampleRate 
)
overridevirtual

Returns
success 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. Default implementation does nothing, returns false

Reimplemented from StatefulEffectBase.

Definition at line 219 of file Distortion.cpp.

220{
221 SetBlockSize(512);
222 mSlaves.clear();
223 return true;
224}
size_t SetBlockSize(size_t maxBlockSize) override

References mSlaves, and StatefulPerTrackEffect::SetBlockSize().

Here is the call graph for this function:

◆ RealtimeProcess()

size_t EffectDistortion::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 Default implementation does nothing, returns 0

Reimplemented from StatefulEffectBase.

Definition at line 245 of file Distortion.cpp.

247{
248 if (group >= mSlaves.size())
249 return 0;
250 return InstanceProcess(settings, mSlaves[group], inbuf, outbuf, numSamples);
251}

References InstanceProcess(), mSlaves, and settings().

Here is the call graph for this function:

◆ RealtimeSupport()

auto EffectDistortion::RealtimeSupport ( ) const
overridevirtual

Since which version of Audacity has the effect supported realtime?

Implements EffectDefinitionInterface.

Definition at line 189 of file Distortion.cpp.

190{
191 // TODO reenable after achieving statelessness
193// return RealtimeSince::Always;
194}

References EffectDefinitionInterface::Never.

◆ Rectifier()

void EffectDistortion::Rectifier ( )
private

Definition at line 1167 of file Distortion.cpp.

1168{
1169 double amount = (mParams.mParam1 / 50.0) - 1;
1170 double stepsize = 1.0 / STEPS;
1171 int index = STEPS;
1172
1173 // positive half of waveform is passed unaltered.
1174 for (int n = 0; n <= STEPS; n++) {
1175 mTable[index] = n * stepsize;
1176 index += 1;
1177 }
1178
1179 // negative half of table
1180 index = STEPS - 1;
1181 for (int n = 1; n <= STEPS; n++) {
1182 mTable[index] = n * stepsize * amount;
1183 index--;
1184 }
1185}

References EffectDistortion::Params::mParam1, mParams, mTable, and STEPS.

Referenced by MakeTable().

Here is the caller graph for this function:

◆ SineTable()

void EffectDistortion::SineTable ( )
private

Definition at line 1092 of file Distortion.cpp.

1093{
1094 int iter = std::floor(mParams.mParam1 / 20.0);
1095 double fractionalpart = (mParams.mParam1 / 20.0) - iter;
1096 double stepsize = 1.0 / STEPS;
1097 double linVal = 0.0;
1098
1099 for (int n = STEPS; n < TABLESIZE; n++) {
1100 mTable[n] = linVal;
1101 for (int i = 0; i < iter; i++) {
1102 mTable[n] = (1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0;
1103 }
1104 mTable[n] += (((1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0) - mTable[n]) * fractionalpart;
1105 linVal += stepsize;
1106 }
1107 CopyHalfTable();
1108}
#define M_PI
Definition: Distortion.cpp:29

References CopyHalfTable(), M_PI, M_PI_2, EffectDistortion::Params::mParam1, mParams, mTable, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SoftClip()

void EffectDistortion::SoftClip ( )
private

Definition at line 966 of file Distortion.cpp.

967{
968 double threshold = 1 + mThreshold;
969 double amount = std::pow(2.0, 7.0 * mParams.mParam1 / 100.0); // range 1 to 128
970 double peak = LogCurve(mThreshold, 1.0, amount);
971 mMakeupGain = 1.0 / peak;
972 mTable[STEPS] = 0.0; // origin
973
974 // positive half of table
975 for (int n = STEPS; n < TABLESIZE; n++) {
976 if (n < (STEPS * threshold)) // origin to threshold
977 mTable[n] = n/(float)STEPS - 1;
978 else
979 mTable[n] = LogCurve(mThreshold, n/(double)STEPS - 1, amount);
980 }
982}
float LogCurve(double threshold, float value, double ratio)
Definition: Distortion.cpp:984

References CopyHalfTable(), LogCurve(), mMakeupGain, EffectDistortion::Params::mParam1, mParams, mTable, mThreshold, STEPS, and TABLESIZE.

Referenced by MakeTable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TransferDataFromWindow()

bool EffectDistortion::TransferDataFromWindow ( EffectSettings settings)
overridevirtual

Update the given settings from controls.

Implements EffectPlugin.

Definition at line 439 of file Distortion.cpp.

440{
442 return true;
443}

References DB_TO_LINEAR, mParams, mThreshold, and EffectDistortion::Params::mThreshold_dB.

◆ TransferDataToWindow()

bool EffectDistortion::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Implements EffectPlugin.

Definition at line 423 of file Distortion.cpp.

424{
425 mThresholdS->SetValue((int) (mThreshold * Threshold_dB.scale + 0.5));
427 mNoiseFloorS->SetValue((int) mParams.mNoiseFloor + 0.5);
428 mParam1S->SetValue((int) mParams.mParam1 + 0.5);
429 mParam2S->SetValue((int) mParams.mParam2 + 0.5);
430 mRepeatsS->SetValue(mParams.mRepeats);
431
433
434 UpdateUI();
435
436 return true;
437}

References mbSavedFilterState, EffectDistortion::Params::mDCBlock, mDCBlockCheckBox, EffectDistortion::Params::mNoiseFloor, mNoiseFloorS, EffectDistortion::Params::mParam1, mParam1S, EffectDistortion::Params::mParam2, mParam2S, mParams, EffectDistortion::Params::mRepeats, mRepeatsS, mThreshold, mThresholdS, EffectParameter< Structure, Member, Type, Value >::scale, Threshold_dB, and UpdateUI().

Here is the call graph for this function:

◆ UpdateControl()

void EffectDistortion::UpdateControl ( control  id,
bool  enable,
TranslatableString  name 
)
private

Definition at line 796 of file Distortion.cpp.

798{
799 auto suffix = XO("(Not Used):");
800 switch (id)
801 {
802 case ID_Threshold: {
803 /* i18n-hint: Control range. */
804 if (enabled) suffix = XO("(-100 to 0 dB):");
805 name.Join( suffix, wxT(" ") );
806
807 // Logarithmic slider is set indirectly
809 mThresholdS->SetValue((int) (mThreshold * Threshold_dB.scale + 0.5));
810
811 auto translated = name.Translation();
812 mThresholdTxt->SetLabel(translated);
813 mThresholdS->SetName(translated);
814 mThresholdT->SetName(translated);
815 mThresholdS->Enable(enabled);
816 mThresholdT->Enable(enabled);
817 break;
818 }
819 case ID_NoiseFloor: {
820 /* i18n-hint: Control range. */
821 if (enabled) suffix = XO("(-80 to -20 dB):");
822 name.Join( suffix, wxT(" ") );
823
824 auto translated = name.Translation();
825 mNoiseFloorTxt->SetLabel(translated);
826 mNoiseFloorS->SetName(translated);
827 mNoiseFloorT->SetName(translated);
828 mNoiseFloorS->Enable(enabled);
829 mNoiseFloorT->Enable(enabled);
830 break;
831 }
832 case ID_Param1: {
833 /* i18n-hint: Control range. */
834 if (enabled) suffix = XO("(0 to 100):");
835 name.Join( suffix, wxT(" ") );
836
837 auto translated = name.Translation();
838 mParam1Txt->SetLabel(translated);
839 mParam1S->SetName(translated);
840 mParam1T->SetName(translated);
841 mParam1S->Enable(enabled);
842 mParam1T->Enable(enabled);
843 break;
844 }
845 case ID_Param2: {
846 /* i18n-hint: Control range. */
847 if (enabled) suffix = XO("(0 to 100):");
848 name.Join( suffix, wxT(" ") );
849
850 auto translated = name.Translation();
851 mParam2Txt->SetLabel(translated);
852 mParam2S->SetName(translated);
853 mParam2T->SetName(translated);
854 mParam2S->Enable(enabled);
855 mParam2T->Enable(enabled);
856 break;
857 }
858 case ID_Repeats: {
859 /* i18n-hint: Control range. */
860 if (enabled) suffix = XO("(0 to 5):");
861 name.Join( suffix, wxT(" ") );
862
863 auto translated = name.Translation();
864 mRepeatsTxt->SetLabel(translated);
865 mRepeatsS->SetName(translated);
866 mRepeatsT->SetName(translated);
867 mRepeatsS->Enable(enabled);
868 mRepeatsT->Enable(enabled);
869 break;
870 }
871 case ID_DCBlock: {
872 if (enabled) {
875 }
876 else {
877 mDCBlockCheckBox->SetValue(false);
878 mParams.mDCBlock = false;
879 }
880
881 mDCBlockCheckBox->Enable(enabled);
882 break;
883 }
884 default:
885 break;
886 }
887}
TranslatableString & Join(TranslatableString arg, const wxString &separator={}) &
Append another translatable string.

References DB_TO_LINEAR, ID_DCBlock, ID_NoiseFloor, ID_Param1, ID_Param2, ID_Repeats, ID_Threshold, TranslatableString::Join(), mbSavedFilterState, EffectDistortion::Params::mDCBlock, mDCBlockCheckBox, mNoiseFloorS, mNoiseFloorT, mNoiseFloorTxt, mParam1S, mParam1T, mParam1Txt, mParam2S, mParam2T, mParam2Txt, mParams, mRepeatsS, mRepeatsT, mRepeatsTxt, mThreshold, EffectDistortion::Params::mThreshold_dB, mThresholdS, mThresholdT, mThresholdTxt, name, EffectParameter< Structure, Member, Type, Value >::scale, Threshold_dB, TranslatableString::Translation(), and XO.

Referenced by UpdateUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateControlText()

void EffectDistortion::UpdateControlText ( wxTextCtrl *  textCtrl,
wxString &  string,
bool  enabled 
)
private

Definition at line 889 of file Distortion.cpp.

890{
891 if (enabled) {
892 if (textCtrl->GetValue().empty())
893 textCtrl->SetValue(string);
894 else
895 string = textCtrl->GetValue();
896 }
897 else {
898 if (!textCtrl->GetValue().empty())
899 string = textCtrl->GetValue();
900 textCtrl->SetValue(wxT(""));
901 }
902}

Referenced by UpdateUI().

Here is the caller graph for this function:

◆ UpdateUI()

void EffectDistortion::UpdateUI ( )
private

Definition at line 627 of file Distortion.cpp.

628{
629 // set control text and names to match distortion type
631 {
632 case kHardClip:
638
639 UpdateControl(ID_Threshold, true, XO("Clipping level"));
641 UpdateControl(ID_Param1, true, XO("Drive"));
642 UpdateControl(ID_Param2, true, XO("Make-up Gain"));
644 UpdateControl(ID_DCBlock, false, {});
645 break;
646 case kSoftClip:
652
653 UpdateControl(ID_Threshold, true, XO("Clipping threshold"));
655 UpdateControl(ID_Param1, true, XO("Hardness"));
656 UpdateControl(ID_Param2, true, XO("Make-up Gain"));
658 UpdateControl(ID_DCBlock, false, {});
659 break;
660 case kHalfSinCurve:
666
669 UpdateControl(ID_Param1, true, XO("Distortion amount"));
670 UpdateControl(ID_Param2, true, XO("Output level"));
672 UpdateControl(ID_DCBlock, false, {});
673 break;
674 case kExpCurve:
680
683 UpdateControl(ID_Param1, true, XO("Distortion amount"));
684 UpdateControl(ID_Param2, true, XO("Output level"));
686 UpdateControl(ID_DCBlock, false, {});
687 break;
688 case kLogCurve:
694
697 UpdateControl(ID_Param1, true, XO("Distortion amount"));
698 UpdateControl(ID_Param2, true, XO("Output level"));
700 UpdateControl(ID_DCBlock, false, {});
701 break;
702 case kCubic:
708
711 UpdateControl(ID_Param1, true, XO("Distortion amount"));
712 UpdateControl(ID_Param2, true, XO("Output level"));
713 UpdateControl(ID_Repeats, true, XO("Repeat processing"));
714 UpdateControl(ID_DCBlock, false, {});
715 break;
716 case kEvenHarmonics:
722
725 UpdateControl(ID_Param1, true, XO("Distortion amount"));
726 UpdateControl(ID_Param2, true, XO("Harmonic brightness"));
728 UpdateControl(ID_DCBlock, true, {});
729 break;
730 case kSinCurve:
736
739 UpdateControl(ID_Param1, true, XO("Distortion amount"));
740 UpdateControl(ID_Param2, true, XO("Output level"));
742 UpdateControl(ID_DCBlock, false, {});
743 break;
744 case kLeveller:
750
753 UpdateControl(ID_Param1, true, XO("Levelling fine adjustment"));
755 UpdateControl(ID_Repeats, true, XO("Degree of Levelling"));
756 UpdateControl(ID_DCBlock, false, {});
757 break;
758 case kRectifier:
764
767 UpdateControl(ID_Param1, true, XO("Distortion amount"));
770 UpdateControl(ID_DCBlock, true, {});
771 break;
772 case kHardLimiter:
778
779 UpdateControl(ID_Threshold, true, XO("dB Limit"));
781 UpdateControl(ID_Param1, true, XO("Wet level"));
782 UpdateControl(ID_Param2, true, XO("Residual level"));
784 UpdateControl(ID_DCBlock, false, {});
785 break;
786 default:
792 UpdateControl(ID_DCBlock, false, {});
793 }
794}
wxString mOldRepeatsTxt
Definition: Distortion.h:215
wxString mOldParam2Txt
Definition: Distortion.h:214
wxString mOldmNoiseFloorTxt
Definition: Distortion.h:212
wxString mOldThresholdTxt
Definition: Distortion.h:211
wxString mOldParam1Txt
Definition: Distortion.h:213
void UpdateControlText(wxTextCtrl *textCtrl, wxString &string, bool enabled)
Definition: Distortion.cpp:889
void UpdateControl(control id, bool enable, TranslatableString name)
Definition: Distortion.cpp:796

References defaultLabel(), ID_DCBlock, ID_NoiseFloor, ID_Param1, ID_Param2, ID_Repeats, ID_Threshold, kCubic, kEvenHarmonics, kExpCurve, kHalfSinCurve, kHardClip, kHardLimiter, kLeveller, kLogCurve, kRectifier, kSinCurve, kSoftClip, mNoiseFloorT, mOldmNoiseFloorTxt, mOldParam1Txt, mOldParam2Txt, mOldRepeatsTxt, mOldThresholdTxt, mParam1T, mParam2T, mParams, mRepeatsT, EffectDistortion::Params::mTableChoiceIndx, mThresholdT, UpdateControl(), UpdateControlText(), and XO.

Referenced by OnTypeChoice(), and TransferDataToWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaveShaper()

float EffectDistortion::WaveShaper ( float  sample)
private

Definition at line 1209 of file Distortion.cpp.

1210{
1211 float out;
1212 int index;
1213 double xOffset;
1214 double amount = 1;
1215
1216 switch (mParams.mTableChoiceIndx)
1217 {
1218 // Do any pre-processing here
1219 case kHardClip:
1220 // Pre-gain
1221 amount = mParams.mParam1 / 100.0;
1222 sample *= 1+amount;
1223 break;
1224 default: break;
1225 }
1226
1227 index = std::floor(sample * STEPS) + STEPS;
1228 index = wxMax<int>(wxMin<int>(index, 2 * STEPS - 1), 0);
1229 xOffset = ((1 + sample) * STEPS) - index;
1230 xOffset = wxMin<double>(wxMax<double>(xOffset, 0.0), 1.0); // Clip at 0dB
1231
1232 // linear interpolation: y = y0 + (y1-y0)*(x-x0)
1233 out = mTable[index] + (mTable[index + 1] - mTable[index]) * xOffset;
1234
1235 return out;
1236}

References kHardClip, EffectDistortion::Params::mParam1, mParams, mTable, EffectDistortion::Params::mTableChoiceIndx, and STEPS.

Referenced by InstanceProcess().

Here is the caller graph for this function:

Member Data Documentation

◆ DCBlock

constexpr EffectParameter EffectDistortion::DCBlock
staticconstexprprivate
Initial value:
L"DC Block", false, false, true, 1 }

Definition at line 243 of file Distortion.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ kTableTypeStrings

const EnumValueSymbol EffectDistortion::kTableTypeStrings
staticprivate
Initial value:
=
{
{ XO("Hard Clipping") },
{ XO("Soft Clipping") },
{ XO("Soft Overdrive") },
{ XO("Medium Overdrive") },
{ XO("Hard Overdrive") },
{ XO("Cubic Curve (odd harmonics)") },
{ XO("Even Harmonics") },
{ XO("Expand and Compress") },
{ XO("Leveller") },
{ XO("Rectifier Distortion") },
{ XO("Hard Limiter 1413") }
}

Definition at line 238 of file Distortion.h.

Referenced by PopulateOrExchange().

◆ mbSavedFilterState

bool EffectDistortion::mbSavedFilterState
private

Definition at line 182 of file Distortion.h.

Referenced by OnDCBlockCheckbox(), TransferDataToWindow(), and UpdateControl().

◆ mDCBlockCheckBox

wxCheckBox* EffectDistortion::mDCBlockCheckBox
private

◆ mMakeupGain

double EffectDistortion::mMakeupGain
private

Definition at line 186 of file Distortion.h.

Referenced by HardClip(), InstanceProcess(), and SoftClip().

◆ mMaster

EffectDistortionState EffectDistortion::mMaster
private

Definition at line 177 of file Distortion.h.

Referenced by ProcessBlock(), and ProcessInitialize().

◆ mNoiseFloorS

wxSlider* EffectDistortion::mNoiseFloorS
private

◆ mNoiseFloorT

wxTextCtrl* EffectDistortion::mNoiseFloorT
private

◆ mNoiseFloorTxt

wxStaticText* EffectDistortion::mNoiseFloorTxt
private

Definition at line 206 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mOldmNoiseFloorTxt

wxString EffectDistortion::mOldmNoiseFloorTxt
private

Definition at line 212 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldParam1Txt

wxString EffectDistortion::mOldParam1Txt
private

Definition at line 213 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldParam2Txt

wxString EffectDistortion::mOldParam2Txt
private

Definition at line 214 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldRepeatsTxt

wxString EffectDistortion::mOldRepeatsTxt
private

Definition at line 215 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldThresholdTxt

wxString EffectDistortion::mOldThresholdTxt
private

Definition at line 211 of file Distortion.h.

Referenced by UpdateUI().

◆ mParam1S

wxSlider* EffectDistortion::mParam1S
private

◆ mParam1T

wxTextCtrl* EffectDistortion::mParam1T
private

◆ mParam1Txt

wxStaticText* EffectDistortion::mParam1Txt
private

Definition at line 207 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mParam2S

wxSlider* EffectDistortion::mParam2S
private

◆ mParam2T

wxTextCtrl* EffectDistortion::mParam2T
private

◆ mParam2Txt

wxStaticText* EffectDistortion::mParam2Txt
private

Definition at line 208 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mParams

Params EffectDistortion::mParams
private

◆ mRepeatsS

wxSlider* EffectDistortion::mRepeatsS
private

◆ mRepeatsT

wxTextCtrl* EffectDistortion::mRepeatsT
private

◆ mRepeatsTxt

wxStaticText* EffectDistortion::mRepeatsTxt
private

Definition at line 209 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mSlaves

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

Definition at line 178 of file Distortion.h.

Referenced by RealtimeAddProcessor(), RealtimeInitialize(), and RealtimeProcess().

◆ mTable

double EffectDistortion::mTable[TABLESIZE]
private

◆ mThreshold

double EffectDistortion::mThreshold
private

◆ mThresholdS

wxSlider* EffectDistortion::mThresholdS
private

◆ mThresholdT

wxTextCtrl* EffectDistortion::mThresholdT
private

◆ mThresholdTxt

wxStaticText* EffectDistortion::mThresholdTxt
private

Definition at line 205 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mTypChoiceIndex

int EffectDistortion::mTypChoiceIndex
private

Definition at line 188 of file Distortion.h.

◆ mTypeChoiceCtrl

wxChoice* EffectDistortion::mTypeChoiceCtrl
private

Definition at line 190 of file Distortion.h.

Referenced by OnTypeChoice(), and PopulateOrExchange().

◆ NoiseFloor

constexpr EffectParameter EffectDistortion::NoiseFloor
staticconstexprprivate
Initial value:
L"Noise Floor", -70.0, -80.0, -20.0, 1 }

Definition at line 247 of file Distortion.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Param1

constexpr EffectParameter EffectDistortion::Param1
staticconstexprprivate
Initial value:
L"Parameter 1", 50.0, 0.0, 100.0, 1 }

Definition at line 249 of file Distortion.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Param2

constexpr EffectParameter EffectDistortion::Param2
staticconstexprprivate
Initial value:
L"Parameter 2", 50.0, 0.0, 100.0, 1 }

Definition at line 251 of file Distortion.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Repeats

constexpr EffectParameter EffectDistortion::Repeats
staticconstexprprivate
Initial value:
L"Repeats", 1, 0, 5, 1 }

Definition at line 253 of file Distortion.h.

Referenced by Parameters(), and PopulateOrExchange().

◆ Symbol

const ComponentInterfaceSymbol EffectDistortion::Symbol { XO("Distortion") }
static

Definition at line 53 of file Distortion.h.

Referenced by GetSymbol().

◆ TableTypeIndx

constexpr EnumParameter EffectDistortion::TableTypeIndx
staticconstexprprivate
Initial value:

Definition at line 241 of file Distortion.h.

Referenced by Parameters().

◆ Threshold_dB

constexpr EffectParameter EffectDistortion::Threshold_dB
staticconstexprprivate
Initial value:
L"Threshold dB", -6.0, -100.0, 0.0, 1000.0f }

Definition at line 245 of file Distortion.h.

Referenced by OnThresholdSlider(), OnThresholdText(), Parameters(), PopulateOrExchange(), TransferDataToWindow(), and UpdateControl().


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