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...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage 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, 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, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize (EffectSettings &settings) noexcept override
 
size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inbuf, float *const *outbuf, size_t numSamples) override
 
std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) 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 bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
virtual size_t ProcessBlock (EffectSettings &settings, const float *const *inBlock, float *const *outBlock, size_t blockLen)=0
 Called for destructive effect computation. More...
 
- Public Member Functions inherited from 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, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () 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...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
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...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal) override
 
EffectUIClientInterfaceGetEffectUIClientInterface () override
 Returns the EffectUIClientInterface instance for this effect. More...
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) 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
 
OptionalMessage 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
 
OptionalMessage 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
 
void SetTracks (TrackList *pTracks)
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=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 OptionalMessage ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=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 EffectUIClientInterfaceGetEffectUIClientInterface ()=0
 Returns the EffectUIClientInterface instance for this effect. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage 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...
 
- 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...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. 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 StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- 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, const EffectOutputs *pOutputs)
 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
 
- 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 }
 
- 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 110 of file Distortion.h.

◆ kTableType

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

Definition at line 223 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:222
bool mbSavedFilterState
Definition: Distortion.h:183
double mMakeupGain
Definition: Distortion.h:187
static const EnumValueSymbol kTableTypeStrings[nTableTypes]
Definition: Distortion.h:239
static constexpr EffectParameter DCBlock
Definition: Distortion.h:244
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 1211 of file Distortion.cpp.

1212{
1213 // Copy negative half of table from positive half
1214 int count = TABLESIZE - 1;
1215 for (int n = 0; n < STEPS; n++) {
1216 mTable[n] = -mTable[count];
1217 count--;
1218 }
1219}
#define TABLESIZE
Definition: Distortion.h:27
#define STEPS
Definition: Distortion.h:26
double mTable[TABLESIZE]
Definition: Distortion.h:181

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 1080 of file Distortion.cpp.

1081{
1082 if (mParams.mParam1 == 0.0)
1083 return x;
1084
1085 return x - (std::pow(x, 3.0) / 3.0);
1086}

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 1054 of file Distortion.cpp.

1055{
1056 double amount = mParams.mParam1 * std::sqrt(3.0) / 100.0;
1057 double gain = 1.0;
1058 if (amount != 0.0)
1059 gain = 1.0 / Cubic(std::min(amount, 1.0));
1060
1061 double stepsize = amount / STEPS;
1062 double x = -amount;
1063
1064 if (amount == 0) {
1065 for (int i = 0; i < TABLESIZE; i++) {
1066 mTable[i] = (i / (double)STEPS) - 1.0;
1067 }
1068 }
1069 else {
1070 for (int i = 0; i < TABLESIZE; i++) {
1071 mTable[i] = gain * Cubic(x);
1072 for (int j = 0; j < mParams.mRepeats; j++) {
1073 mTable[i] = gain * Cubic(mTable[i] * amount);
1074 }
1075 x += stepsize;
1076 }
1077 }
1078}
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 1252 of file Distortion.cpp.

1253{
1254 // Rolling average gives less offset at the start than an IIR filter.
1255 const unsigned int queueLength = std::floor(data.samplerate / 20.0);
1256
1257 data.queuetotal += sample;
1258 data.queuesamples.push(sample);
1259
1260 if (data.queuesamples.size() > queueLength) {
1261 data.queuetotal -= data.queuesamples.front();
1262 data.queuesamples.pop();
1263 }
1264
1265 return sample - (data.queuetotal / data.queuesamples.size());
1266}
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()

OptionalMessage EffectDistortion::DoLoadFactoryPreset ( int  id)

Definition at line 272 of file Distortion.cpp.

273{
274 if (id < 0 || id >= (int) WXSIZEOF(FactoryPresets))
275 {
276 return {};
277 }
278
279 mParams = FactoryPresets[id].params;
281
282 return { nullptr };
283}
static const struct @21 FactoryPresets[]
#define DB_TO_LINEAR(x)
Definition: MemoryX.h:543
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 1089 of file Distortion.cpp.

1090{
1091 double amount = mParams.mParam1 / -100.0;
1092 // double C = std::sin(std::max(0.001, mParams.mParam2) / 100.0) * 10.0;
1093 double C = std::max(0.001, mParams.mParam2) / 10.0;
1094
1095 double step = 1.0 / STEPS;
1096 double xval = -1.0;
1097
1098 for (int i = 0; i < TABLESIZE; i++) {
1099 mTable[i] = ((1 + amount) * xval) -
1100 (xval * (amount / std::tanh(C)) * std::tanh(C * xval));
1101 xval += step;
1102 }
1103}

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 1002 of file Distortion.cpp.

1003{
1004 double amount = std::min(0.999, DB_TO_LINEAR(-1 * mParams.mParam1)); // avoid divide by zero
1005
1006 for (int n = STEPS; n < TABLESIZE; n++) {
1007 double linVal = n/(float)STEPS;
1008 double scale = -1.0 / (1.0 - amount); // unity gain at 0dB
1009 double curve = std::exp((linVal - 1) * std::log(amount));
1010 mTable[n] = scale * (curve -1);
1011 }
1012 CopyHalfTable();
1013}

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 instance processes channels independently, this can return 1 The result is not necessarily well defined before RealtimeInitialize Default implementation returns 0

Reimplemented from StatefulEffectBase.

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.

The result is not necessarily well defined before RealtimeInitialize Default implementation returns 0

Reimplemented from StatefulEffectBase.

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 1036 of file Distortion.cpp.

1037{
1038 int iter = std::floor(mParams.mParam1 / 20.0);
1039 double fractionalpart = (mParams.mParam1 / 20.0) - iter;
1040 double stepsize = 1.0 / STEPS;
1041 double linVal = 0;
1042
1043 for (int n = STEPS; n < TABLESIZE; n++) {
1044 mTable[n] = linVal;
1045 for (int i = 0; i < iter; i++) {
1046 mTable[n] = std::sin(mTable[n] * M_PI_2);
1047 }
1048 mTable[n] += ((std::sin(mTable[n] * M_PI_2) - mTable[n]) * fractionalpart);
1049 linVal += stepsize;
1050 }
1051 CopyHalfTable();
1052}
#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 962 of file Distortion.cpp.

963{
964 double lowThresh = 1 - mThreshold;
965 double highThresh = 1 + mThreshold;
966
967 for (int n = 0; n < TABLESIZE; n++) {
968 if (n < (STEPS * lowThresh))
969 mTable[n] = - mThreshold;
970 else if (n > (STEPS * highThresh))
971 mTable[n] = mThreshold;
972 else
973 mTable[n] = n/(double)STEPS - 1;
974
975 mMakeupGain = 1.0 / mThreshold;
976 }
977}

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 1200 of file Distortion.cpp.

1201{
1202 // The LADSPA "hardLimiter 1413" is basically hard clipping,
1203 // but with a 'kind of' wet/dry mix:
1204 // out = ((wet-residual)*clipped) + (residual*in)
1205 HardClip();
1206}

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 458 of file Distortion.cpp.

459{
460 data.samplerate = sampleRate;
461 data.skipcount = 0;
463 data.dcblock = mParams.mDCBlock;
466 data.param1 = mParams.mParam1;
467 data.param2 = mParams.mParam2;
468 data.repeats = mParams.mRepeats;
469
470 // DC block filter variables
471 data.queuetotal = 0.0;
472
473 //std::queue<float>().swap(data.queuesamples);
474 while (!data.queuesamples.empty())
475 data.queuesamples.pop();
476
477 MakeTable();
478
479 return;
480}
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 482 of file Distortion.cpp.

485{
486 const float *ibuf = inBlock[0];
487 float *obuf = outBlock[0];
488
489 bool update = (mParams.mTableChoiceIndx == data.tablechoiceindx &&
492 mParams.mParam1 == data.param1 &&
493 mParams.mParam2 == data.param2 &&
494 mParams.mRepeats == data.repeats)? false : true;
495
496 double p1 = mParams.mParam1 / 100.0;
497 double p2 = mParams.mParam2 / 100.0;
498
502 data.param1 = mParams.mParam1;
503 data.repeats = mParams.mRepeats;
504
505 for (decltype(blockLen) i = 0; i < blockLen; i++) {
506 if (update && ((data.skipcount++) % skipsamples == 0)) {
507 MakeTable();
508 }
509
511 {
512 case kHardClip:
513 // Param2 = make-up gain.
514 obuf[i] = WaveShaper(ibuf[i]) * ((1 - p2) + (mMakeupGain * p2));
515 break;
516 case kSoftClip:
517 // Param2 = make-up gain.
518 obuf[i] = WaveShaper(ibuf[i]) * ((1 - p2) + (mMakeupGain * p2));
519 break;
520 case kHalfSinCurve:
521 obuf[i] = WaveShaper(ibuf[i]) * p2;
522 break;
523 case kExpCurve:
524 obuf[i] = WaveShaper(ibuf[i]) * p2;
525 break;
526 case kLogCurve:
527 obuf[i] = WaveShaper(ibuf[i]) * p2;
528 break;
529 case kCubic:
530 obuf[i] = WaveShaper(ibuf[i]) * p2;
531 break;
532 case kEvenHarmonics:
533 obuf[i] = WaveShaper(ibuf[i]);
534 break;
535 case kSinCurve:
536 obuf[i] = WaveShaper(ibuf[i]) * p2;
537 break;
538 case kLeveller:
539 obuf[i] = WaveShaper(ibuf[i]);
540 break;
541 case kRectifier:
542 obuf[i] = WaveShaper(ibuf[i]);
543 break;
544 case kHardLimiter:
545 // Mix equivalent to LADSPA effect's "Wet / Residual" mix
546 obuf[i] = (WaveShaper(ibuf[i]) * (p1 - p2)) + (ibuf[i] * p2);
547 break;
548 default:
549 obuf[i] = WaveShaper(ibuf[i]);
550 }
551 if (mParams.mDCBlock) {
552 obuf[i] = DCFilter(data, obuf[i]);
553 }
554 }
555
556 return blockLen;
557}
#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 1123 of file Distortion.cpp.

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

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()

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

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

Returns
nullopt for failure

Implements EffectSettingsManager.

Definition at line 266 of file Distortion.cpp.

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

References DoLoadFactoryPreset().

Here is the call graph for this function:

◆ LogarithmicTable()

void EffectDistortion::LogarithmicTable ( )
private

Definition at line 1015 of file Distortion.cpp.

1016{
1017 double amount = mParams.mParam1;
1018 double stepsize = 1.0 / STEPS;
1019 double linVal = 0;
1020
1021 if (amount == 0){
1022 for (int n = STEPS; n < TABLESIZE; n++) {
1023 mTable[n] = linVal;
1024 linVal += stepsize;
1025 }
1026 }
1027 else {
1028 for (int n = STEPS; n < TABLESIZE; n++) {
1029 mTable[n] = std::log(1 + (amount * linVal)) / std::log(1 + amount);
1030 linVal += stepsize;
1031 }
1032 }
1033 CopyHalfTable();
1034}

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 997 of file Distortion.cpp.

998{
999 return threshold + ((std::exp(ratio * (threshold - value)) - 1) / -ratio);
1000}

Referenced by SoftClip().

Here is the caller graph for this function:

◆ MakeTable()

void EffectDistortion::MakeTable ( )
private

Definition at line 917 of file Distortion.cpp.

918{
920 {
921 case kHardClip:
922 HardClip();
923 break;
924 case kSoftClip:
925 SoftClip();
926 break;
927 case kHalfSinCurve:
928 HalfSinTable();
929 break;
930 case kExpCurve:
932 break;
933 case kLogCurve:
935 break;
936 case kCubic:
937 CubicTable();
938 break;
939 case kEvenHarmonics:
941 break;
942 case kSinCurve:
943 SineTable();
944 break;
945 case kLeveller:
946 Leveller();
947 break;
948 case kRectifier:
949 Rectifier();
950 break;
951 case kHardLimiter:
952 HardLimiter();
953 break;
954 }
955}
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 566 of file Distortion.cpp.

567{
568 mParams.mDCBlock = mDCBlockCheckBox->GetValue();
570}
wxCheckBox * mDCBlockCheckBox
Definition: Distortion.h:204

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

◆ OnNoiseFloorSlider()

void EffectDistortion::OnNoiseFloorSlider ( wxCommandEvent &  evt)
private

Definition at line 596 of file Distortion.cpp.

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

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

◆ OnNoiseFloorText()

void EffectDistortion::OnNoiseFloorText ( wxCommandEvent &  evt)
private

Definition at line 590 of file Distortion.cpp.

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

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

◆ OnParam1Slider()

void EffectDistortion::OnParam1Slider ( wxCommandEvent &  evt)
private

Definition at line 609 of file Distortion.cpp.

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

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

◆ OnParam1Text()

void EffectDistortion::OnParam1Text ( wxCommandEvent &  evt)
private

Definition at line 603 of file Distortion.cpp.

604{
605 mParam1T->GetValidator()->TransferFromWindow();
606 mParam1S->SetValue((int) floor(mParams.mParam1 + 0.5));
607}
wxSlider * mParam1S
Definition: Distortion.h:200

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

◆ OnParam2Slider()

void EffectDistortion::OnParam2Slider ( wxCommandEvent &  evt)
private

Definition at line 621 of file Distortion.cpp.

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

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

◆ OnParam2Text()

void EffectDistortion::OnParam2Text ( wxCommandEvent &  evt)
private

Definition at line 615 of file Distortion.cpp.

616{
617 mParam2T->GetValidator()->TransferFromWindow();
618 mParam2S->SetValue((int) floor(mParams.mParam2 + 0.5));
619}
wxSlider * mParam2S
Definition: Distortion.h:201

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

◆ OnRepeatsSlider()

void EffectDistortion::OnRepeatsSlider ( wxCommandEvent &  evt)
private

Definition at line 633 of file Distortion.cpp.

634{
635 mParams.mRepeats = evt.GetInt();
636 mRepeatsT->GetValidator()->TransferToWindow();
637
638}
wxTextCtrl * mRepeatsT
Definition: Distortion.h:196

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

◆ OnRepeatsText()

void EffectDistortion::OnRepeatsText ( wxCommandEvent &  evt)
private

Definition at line 627 of file Distortion.cpp.

628{
629 mRepeatsT->GetValidator()->TransferFromWindow();
630 mRepeatsS->SetValue(mParams.mRepeats);
631}
wxSlider * mRepeatsS
Definition: Distortion.h:202

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

◆ OnThresholdSlider()

void EffectDistortion::OnThresholdSlider ( wxCommandEvent &  evt)
private

Definition at line 580 of file Distortion.cpp.

581{
582 static const double MIN_Threshold_Linear = DB_TO_LINEAR(Threshold_dB.min);
583
584 mThreshold = (double) evt.GetInt() / Threshold_dB.scale;
586 mThreshold = std::max(MIN_Threshold_Linear, mThreshold);
587 mThresholdT->GetValidator()->TransferToWindow();
588}
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:544
static constexpr EffectParameter Threshold_dB
Definition: Distortion.h:246
wxTextCtrl * mThresholdT
Definition: Distortion.h:192
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 559 of file Distortion.cpp.

560{
561 mTypeChoiceCtrl->GetValidator()->TransferFromWindow();
562
563 UpdateUI();
564}
wxChoice * mTypeChoiceCtrl
Definition: Distortion.h:191

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:252
static constexpr EffectParameter Param1
Definition: Distortion.h:250
static constexpr EffectParameter Repeats
Definition: Distortion.h:254
static constexpr EnumParameter TableTypeIndx
Definition: Distortion.h:242
static constexpr EffectParameter NoiseFloor
Definition: Distortion.h:248
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,
const EffectOutputs pOutputs 
)
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 288 of file Distortion.cpp.

291{
292 S.AddSpace(0, 5);
293 S.StartVerticalLay();
294 {
295 S.StartMultiColumn(4, wxCENTER);
296 {
298 .MinSize( { -1, -1 } )
300 .AddChoice(XXO("Distortion type:"),
302
303 mDCBlockCheckBox = S.Id(ID_DCBlock).AddCheckBox(XXO("DC blocking filter"),
304 DCBlock.def);
305 }
306 S.EndMultiColumn();
307 S.AddSpace(0, 10);
308
309
310 S.StartStatic(XO("Threshold controls"));
311 {
312 S.StartMultiColumn(4, wxEXPAND);
313 S.SetStretchyCol(2);
314 {
315 // Allow space for first Column
316 S.AddSpace(250,0); S.AddSpace(0,0); S.AddSpace(0,0); S.AddSpace(0,0);
317
318 // Upper threshold control
319 mThresholdTxt = S.AddVariableText(defaultLabel(0),
320 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
322 .Name(defaultLabel(0))
323 .Validator<FloatingPointValidator<double>>(
324 2, &mParams.mThreshold_dB, NumValidatorStyle::DEFAULT,
326 .AddTextBox( {}, wxT(""), 10);
327
329 .Name(defaultLabel(0))
330 .Style(wxSL_HORIZONTAL)
331 .AddSlider( {}, 0,
334 S.AddSpace(20, 0);
335
336 // Noise floor control
337 mNoiseFloorTxt = S.AddVariableText(defaultLabel(1),
338 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
340 .Name(defaultLabel(1))
341 .Validator<FloatingPointValidator<double>>(
342 2, &mParams.mNoiseFloor, NumValidatorStyle::DEFAULT,
344 )
345 .AddTextBox( {}, wxT(""), 10);
346
348 .Name(defaultLabel(1))
349 .Style(wxSL_HORIZONTAL)
350 .AddSlider( {}, 0, NoiseFloor.max, NoiseFloor.min);
351 S.AddSpace(20, 0);
352 }
353 S.EndMultiColumn();
354 }
355 S.EndStatic();
356
357 S.StartStatic(XO("Parameter controls"));
358 {
359 S.StartMultiColumn(4, wxEXPAND);
360 S.SetStretchyCol(2);
361 {
362 // Allow space for first Column
363 S.AddSpace(250,0); S.AddSpace(0,0); S.AddSpace(0,0); S.AddSpace(0,0);
364
365 // Parameter1 control
366 mParam1Txt = S.AddVariableText(defaultLabel(2),
367 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
368 mParam1T = S.Id(ID_Param1)
369 .Name(defaultLabel(2))
370 .Validator<FloatingPointValidator<double>>(
371 2, &mParams.mParam1, NumValidatorStyle::DEFAULT,
373 )
374 .AddTextBox( {}, wxT(""), 10);
375
376 mParam1S = S.Id(ID_Param1)
377 .Name(defaultLabel(2))
378 .Style(wxSL_HORIZONTAL)
379 .AddSlider( {}, 0, Param1.max, Param1.min);
380 S.AddSpace(20, 0);
381
382 // Parameter2 control
383 mParam2Txt = S.AddVariableText(defaultLabel(3),
384 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
385 mParam2T = S.Id(ID_Param2)
386 .Name(defaultLabel(3))
387 .Validator<FloatingPointValidator<double>>(
388 2, &mParams.mParam2, NumValidatorStyle::DEFAULT,
390 )
391 .AddTextBox( {}, wxT(""), 10);
392
393 mParam2S = S.Id(ID_Param2)
394 .Name(defaultLabel(3))
395 .Style(wxSL_HORIZONTAL)
396 .AddSlider( {}, 0, Param2.max, Param2.min);
397 S.AddSpace(20, 0);
398
399 // Repeats control
400 mRepeatsTxt = S.AddVariableText(defaultLabel(4),
401 false, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT);
403 .Name(defaultLabel(4))
404 .Validator<IntegerValidator<int>>(
405 &mParams.mRepeats, NumValidatorStyle::DEFAULT,
407 )
408 .AddTextBox( {}, wxT(""), 10);
409
411 .Name(defaultLabel(4))
412 .Style(wxSL_HORIZONTAL)
413 .AddSlider( {}, Repeats.def, Repeats.max, Repeats.min);
414 S.AddSpace(20, 0);
415 }
416 S.EndMultiColumn();
417 }
418 S.EndStatic();
419 }
420 S.EndVerticalLay();
421
422 return nullptr;
423}
wxT("CloseDown"))
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:210
wxStaticText * mParam1Txt
Definition: Distortion.h:208
wxStaticText * mParam2Txt
Definition: Distortion.h:209
wxStaticText * mNoiseFloorTxt
Definition: Distortion.h:207
wxStaticText * mThresholdTxt
Definition: Distortion.h:206
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, wxT(), 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.

Implements 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:482
EffectDistortionState mMaster
Definition: Distortion.h:178

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

Here is the call graph for this function:

◆ ProcessInitialize()

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

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

Parameters
chanMapnull or array terminated with ChannelNameEOL. Do not retain the pointer
Postcondition
GetAudioInCount() and GetAudioOutCount() are well defined

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:458

References InstanceInit(), and mMaster.

Here is the call graph for this function:

◆ RealtimeAddProcessor()

bool EffectDistortion::RealtimeAddProcessor ( EffectSettings settings,
EffectOutputs pOutputs,
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:179

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
Postcondition
GetAudioInCount() and GetAudioOutCount() are well defined

Default implementation does nothing, returns false (so assume realtime is not supported). Other member functions related to realtime return true or zero, but will not be called, unless a derived class overrides RealtimeInitialize. 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 1180 of file Distortion.cpp.

1181{
1182 double amount = (mParams.mParam1 / 50.0) - 1;
1183 double stepsize = 1.0 / STEPS;
1184 int index = STEPS;
1185
1186 // positive half of waveform is passed unaltered.
1187 for (int n = 0; n <= STEPS; n++) {
1188 mTable[index] = n * stepsize;
1189 index += 1;
1190 }
1191
1192 // negative half of table
1193 index = STEPS - 1;
1194 for (int n = 1; n <= STEPS; n++) {
1195 mTable[index] = n * stepsize * amount;
1196 index--;
1197 }
1198}

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 1105 of file Distortion.cpp.

1106{
1107 int iter = std::floor(mParams.mParam1 / 20.0);
1108 double fractionalpart = (mParams.mParam1 / 20.0) - iter;
1109 double stepsize = 1.0 / STEPS;
1110 double linVal = 0.0;
1111
1112 for (int n = STEPS; n < TABLESIZE; n++) {
1113 mTable[n] = linVal;
1114 for (int i = 0; i < iter; i++) {
1115 mTable[n] = (1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0;
1116 }
1117 mTable[n] += (((1.0 + std::sin((mTable[n] * M_PI) - M_PI_2)) / 2.0) - mTable[n]) * fractionalpart;
1118 linVal += stepsize;
1119 }
1120 CopyHalfTable();
1121}
#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 979 of file Distortion.cpp.

980{
981 double threshold = 1 + mThreshold;
982 double amount = std::pow(2.0, 7.0 * mParams.mParam1 / 100.0); // range 1 to 128
983 double peak = LogCurve(mThreshold, 1.0, amount);
984 mMakeupGain = 1.0 / peak;
985 mTable[STEPS] = 0.0; // origin
986
987 // positive half of table
988 for (int n = STEPS; n < TABLESIZE; n++) {
989 if (n < (STEPS * threshold)) // origin to threshold
990 mTable[n] = n/(float)STEPS - 1;
991 else
992 mTable[n] = LogCurve(mThreshold, n/(double)STEPS - 1, amount);
993 }
995}
float LogCurve(double threshold, float value, double ratio)
Definition: Distortion.cpp:997

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 446 of file Distortion.cpp.

447{
448 if (!mUIParent->Validate() || !mUIParent->TransferDataFromWindow())
449 {
450 return false;
451 }
452
454
455 return true;
456}
wxWindow * mUIParent
Definition: Effect.h:307

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

◆ TransferDataToWindow()

bool EffectDistortion::TransferDataToWindow ( const EffectSettings settings)
overridevirtual

Update controls for the settings.

Implements EffectPlugin.

Definition at line 425 of file Distortion.cpp.

426{
427 if (!mUIParent->TransferDataToWindow())
428 {
429 return false;
430 }
431
432 mThresholdS->SetValue((int) (mThreshold * Threshold_dB.scale + 0.5));
434 mNoiseFloorS->SetValue((int) mParams.mNoiseFloor + 0.5);
435 mParam1S->SetValue((int) mParams.mParam1 + 0.5);
436 mParam2S->SetValue((int) mParams.mParam2 + 0.5);
437 mRepeatsS->SetValue(mParams.mRepeats);
438
440
441 UpdateUI();
442
443 return true;
444}

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, Effect::mUIParent, 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 809 of file Distortion.cpp.

811{
812 auto suffix = XO("(Not Used):");
813 switch (id)
814 {
815 case ID_Threshold: {
816 /* i18n-hint: Control range. */
817 if (enabled) suffix = XO("(-100 to 0 dB):");
818 name.Join( suffix, wxT(" ") );
819
820 // Logarithmic slider is set indirectly
822 mThresholdS->SetValue((int) (mThreshold * Threshold_dB.scale + 0.5));
823
824 auto translated = name.Translation();
825 mThresholdTxt->SetLabel(translated);
826 mThresholdS->SetName(translated);
827 mThresholdT->SetName(translated);
828 mThresholdS->Enable(enabled);
829 mThresholdT->Enable(enabled);
830 break;
831 }
832 case ID_NoiseFloor: {
833 /* i18n-hint: Control range. */
834 if (enabled) suffix = XO("(-80 to -20 dB):");
835 name.Join( suffix, wxT(" ") );
836
837 auto translated = name.Translation();
838 mNoiseFloorTxt->SetLabel(translated);
839 mNoiseFloorS->SetName(translated);
840 mNoiseFloorT->SetName(translated);
841 mNoiseFloorS->Enable(enabled);
842 mNoiseFloorT->Enable(enabled);
843 break;
844 }
845 case ID_Param1: {
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 mParam1Txt->SetLabel(translated);
852 mParam1S->SetName(translated);
853 mParam1T->SetName(translated);
854 mParam1S->Enable(enabled);
855 mParam1T->Enable(enabled);
856 break;
857 }
858 case ID_Param2: {
859 /* i18n-hint: Control range. */
860 if (enabled) suffix = XO("(0 to 100):");
861 name.Join( suffix, wxT(" ") );
862
863 auto translated = name.Translation();
864 mParam2Txt->SetLabel(translated);
865 mParam2S->SetName(translated);
866 mParam2T->SetName(translated);
867 mParam2S->Enable(enabled);
868 mParam2T->Enable(enabled);
869 break;
870 }
871 case ID_Repeats: {
872 /* i18n-hint: Control range. */
873 if (enabled) suffix = XO("(0 to 5):");
874 name.Join( suffix, wxT(" ") );
875
876 auto translated = name.Translation();
877 mRepeatsTxt->SetLabel(translated);
878 mRepeatsS->SetName(translated);
879 mRepeatsT->SetName(translated);
880 mRepeatsS->Enable(enabled);
881 mRepeatsT->Enable(enabled);
882 break;
883 }
884 case ID_DCBlock: {
885 if (enabled) {
888 }
889 else {
890 mDCBlockCheckBox->SetValue(false);
891 mParams.mDCBlock = false;
892 }
893
894 mDCBlockCheckBox->Enable(enabled);
895 break;
896 }
897 default:
898 break;
899 }
900}
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(), wxT(), 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 902 of file Distortion.cpp.

903{
904 if (enabled) {
905 if (textCtrl->GetValue().empty())
906 textCtrl->SetValue(string);
907 else
908 string = textCtrl->GetValue();
909 }
910 else {
911 if (!textCtrl->GetValue().empty())
912 string = textCtrl->GetValue();
913 textCtrl->SetValue(wxT(""));
914 }
915}

References wxT().

Referenced by UpdateUI().

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

◆ UpdateUI()

void EffectDistortion::UpdateUI ( )
private

Definition at line 640 of file Distortion.cpp.

641{
642 // set control text and names to match distortion type
644 {
645 case kHardClip:
651
652 UpdateControl(ID_Threshold, true, XO("Clipping level"));
654 UpdateControl(ID_Param1, true, XO("Drive"));
655 UpdateControl(ID_Param2, true, XO("Make-up Gain"));
657 UpdateControl(ID_DCBlock, false, {});
658 break;
659 case kSoftClip:
665
666 UpdateControl(ID_Threshold, true, XO("Clipping threshold"));
668 UpdateControl(ID_Param1, true, XO("Hardness"));
669 UpdateControl(ID_Param2, true, XO("Make-up Gain"));
671 UpdateControl(ID_DCBlock, false, {});
672 break;
673 case kHalfSinCurve:
679
682 UpdateControl(ID_Param1, true, XO("Distortion amount"));
683 UpdateControl(ID_Param2, true, XO("Output level"));
685 UpdateControl(ID_DCBlock, false, {});
686 break;
687 case kExpCurve:
693
696 UpdateControl(ID_Param1, true, XO("Distortion amount"));
697 UpdateControl(ID_Param2, true, XO("Output level"));
699 UpdateControl(ID_DCBlock, false, {});
700 break;
701 case kLogCurve:
707
710 UpdateControl(ID_Param1, true, XO("Distortion amount"));
711 UpdateControl(ID_Param2, true, XO("Output level"));
713 UpdateControl(ID_DCBlock, false, {});
714 break;
715 case kCubic:
721
724 UpdateControl(ID_Param1, true, XO("Distortion amount"));
725 UpdateControl(ID_Param2, true, XO("Output level"));
726 UpdateControl(ID_Repeats, true, XO("Repeat processing"));
727 UpdateControl(ID_DCBlock, false, {});
728 break;
729 case kEvenHarmonics:
735
738 UpdateControl(ID_Param1, true, XO("Distortion amount"));
739 UpdateControl(ID_Param2, true, XO("Harmonic brightness"));
741 UpdateControl(ID_DCBlock, true, {});
742 break;
743 case kSinCurve:
749
752 UpdateControl(ID_Param1, true, XO("Distortion amount"));
753 UpdateControl(ID_Param2, true, XO("Output level"));
755 UpdateControl(ID_DCBlock, false, {});
756 break;
757 case kLeveller:
763
766 UpdateControl(ID_Param1, true, XO("Levelling fine adjustment"));
768 UpdateControl(ID_Repeats, true, XO("Degree of Levelling"));
769 UpdateControl(ID_DCBlock, false, {});
770 break;
771 case kRectifier:
777
780 UpdateControl(ID_Param1, true, XO("Distortion amount"));
783 UpdateControl(ID_DCBlock, true, {});
784 break;
785 case kHardLimiter:
791
792 UpdateControl(ID_Threshold, true, XO("dB Limit"));
794 UpdateControl(ID_Param1, true, XO("Wet level"));
795 UpdateControl(ID_Param2, true, XO("Residual level"));
797 UpdateControl(ID_DCBlock, false, {});
798 break;
799 default:
805 UpdateControl(ID_DCBlock, false, {});
806 }
807}
wxString mOldRepeatsTxt
Definition: Distortion.h:216
wxString mOldParam2Txt
Definition: Distortion.h:215
wxString mOldmNoiseFloorTxt
Definition: Distortion.h:213
wxString mOldThresholdTxt
Definition: Distortion.h:212
wxString mOldParam1Txt
Definition: Distortion.h:214
void UpdateControlText(wxTextCtrl *textCtrl, wxString &string, bool enabled)
Definition: Distortion.cpp:902
void UpdateControl(control id, bool enable, TranslatableString name)
Definition: Distortion.cpp:809

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 1222 of file Distortion.cpp.

1223{
1224 float out;
1225 int index;
1226 double xOffset;
1227 double amount = 1;
1228
1229 switch (mParams.mTableChoiceIndx)
1230 {
1231 // Do any pre-processing here
1232 case kHardClip:
1233 // Pre-gain
1234 amount = mParams.mParam1 / 100.0;
1235 sample *= 1+amount;
1236 break;
1237 default: break;
1238 }
1239
1240 index = std::floor(sample * STEPS) + STEPS;
1241 index = wxMax<int>(wxMin<int>(index, 2 * STEPS - 1), 0);
1242 xOffset = ((1 + sample) * STEPS) - index;
1243 xOffset = wxMin<double>(wxMax<double>(xOffset, 0.0), 1.0); // Clip at 0dB
1244
1245 // linear interpolation: y = y0 + (y1-y0)*(x-x0)
1246 out = mTable[index] + (mTable[index + 1] - mTable[index]) * xOffset;
1247
1248 return out;
1249}

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 244 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 239 of file Distortion.h.

Referenced by PopulateOrExchange().

◆ mbSavedFilterState

bool EffectDistortion::mbSavedFilterState
private

Definition at line 183 of file Distortion.h.

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

◆ mDCBlockCheckBox

wxCheckBox* EffectDistortion::mDCBlockCheckBox
private

◆ mMakeupGain

double EffectDistortion::mMakeupGain
private

Definition at line 187 of file Distortion.h.

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

◆ mMaster

EffectDistortionState EffectDistortion::mMaster
private

Definition at line 178 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 207 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mOldmNoiseFloorTxt

wxString EffectDistortion::mOldmNoiseFloorTxt
private

Definition at line 213 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldParam1Txt

wxString EffectDistortion::mOldParam1Txt
private

Definition at line 214 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldParam2Txt

wxString EffectDistortion::mOldParam2Txt
private

Definition at line 215 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldRepeatsTxt

wxString EffectDistortion::mOldRepeatsTxt
private

Definition at line 216 of file Distortion.h.

Referenced by UpdateUI().

◆ mOldThresholdTxt

wxString EffectDistortion::mOldThresholdTxt
private

Definition at line 212 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 208 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 209 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 210 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mSlaves

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

Definition at line 179 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 206 of file Distortion.h.

Referenced by PopulateOrExchange(), and UpdateControl().

◆ mTypChoiceIndex

int EffectDistortion::mTypChoiceIndex
private

Definition at line 189 of file Distortion.h.

◆ mTypeChoiceCtrl

wxChoice* EffectDistortion::mTypeChoiceCtrl
private

Definition at line 191 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 248 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 250 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 252 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 254 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 242 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 246 of file Distortion.h.

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


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