2016-06-15 00:05:59 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
Distortion.h
|
|
|
|
|
|
|
|
Steve Daulton
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_EFFECT_DISTORTION__
|
|
|
|
#define __AUDACITY_EFFECT_DISTORTION__
|
|
|
|
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include "Effect.h"
|
|
|
|
|
2018-11-11 21:18:23 +00:00
|
|
|
class wxSlider;
|
2018-11-11 21:41:45 +00:00
|
|
|
class wxStaticText;
|
2018-11-11 22:30:55 +00:00
|
|
|
class wxCheckBox;
|
2018-11-11 21:11:18 +00:00
|
|
|
class wxTextCtrl;
|
2016-06-15 00:05:59 +00:00
|
|
|
class ShuttleGui;
|
|
|
|
|
|
|
|
#define STEPS 1024 // number of +ve or -ve steps in lookup tabe
|
|
|
|
#define TABLESIZE 2049 // size of lookup table (steps * 2 + 1)
|
|
|
|
|
|
|
|
class EffectDistortionState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
float samplerate;
|
|
|
|
sampleCount skipcount;
|
|
|
|
int tablechoiceindx;
|
|
|
|
bool dcblock;
|
|
|
|
double threshold;
|
|
|
|
double noisefloor;
|
|
|
|
double param1;
|
|
|
|
double param2;
|
|
|
|
int repeats;
|
|
|
|
|
|
|
|
// DC block filter variables
|
|
|
|
std::queue<float> queuesamples;
|
|
|
|
double queuetotal;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EffectDistortion final : public Effect
|
|
|
|
{
|
|
|
|
public:
|
2019-01-17 22:33:49 +00:00
|
|
|
static const ComponentInterfaceSymbol Symbol;
|
|
|
|
|
2016-06-15 00:05:59 +00:00
|
|
|
EffectDistortion();
|
|
|
|
virtual ~EffectDistortion();
|
|
|
|
|
|
|
|
struct Params
|
|
|
|
{
|
|
|
|
int mTableChoiceIndx;
|
|
|
|
bool mDCBlock;
|
|
|
|
double mThreshold_dB;
|
|
|
|
double mNoiseFloor;
|
|
|
|
double mParam1;
|
|
|
|
double mParam2;
|
|
|
|
int mRepeats;
|
|
|
|
};
|
|
|
|
|
2018-11-02 15:31:44 +00:00
|
|
|
// ComponentInterface implementation
|
2016-06-15 00:05:59 +00:00
|
|
|
|
2018-11-02 15:31:44 +00:00
|
|
|
ComponentInterfaceSymbol GetSymbol() override;
|
2019-12-08 18:53:48 +00:00
|
|
|
TranslatableString GetDescription() override;
|
2021-06-06 16:18:35 +00:00
|
|
|
ManualPageID ManualPage() override;
|
2016-06-15 00:05:59 +00:00
|
|
|
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
// EffectDefinitionInterface implementation
|
2016-06-15 00:05:59 +00:00
|
|
|
|
|
|
|
EffectType GetType() override;
|
|
|
|
bool SupportsRealtime() override;
|
|
|
|
|
|
|
|
// EffectClientInterface implementation
|
|
|
|
|
2016-09-02 19:53:09 +00:00
|
|
|
unsigned GetAudioInCount() override;
|
|
|
|
unsigned GetAudioOutCount() override;
|
2016-06-15 00:05:59 +00:00
|
|
|
bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap = NULL) override;
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override;
|
2016-06-15 00:05:59 +00:00
|
|
|
bool RealtimeInitialize() override;
|
2016-09-02 19:53:09 +00:00
|
|
|
bool RealtimeAddProcessor(unsigned numChannels, float sampleRate) override;
|
2016-06-15 00:05:59 +00:00
|
|
|
bool RealtimeFinalize() override;
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t RealtimeProcess(int group,
|
2016-06-15 00:05:59 +00:00
|
|
|
float **inbuf,
|
|
|
|
float **outbuf,
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t numSamples) override;
|
Automation: AudacityCommand
This is a squash of 50 commits.
This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class. AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.
- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
- Tested with Zoom Toggle.
- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.
We abuse EffectsManager. It handles both Effects and
AudacityCommands now. In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.
- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.
This way we can search for related types at the same time.
- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason. They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.
- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
which are now better handled by other commands.
- JSONify "GetInfo: Commands" output, i.e. commas in the right places.
- General work on better Doxygen.
- Lyrics -> LyricsPanel
- Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-01-14 18:51:41 +00:00
|
|
|
bool DefineParams( ShuttleParams & S ) override;
|
2018-02-21 14:24:25 +00:00
|
|
|
bool GetAutomationParameters(CommandParameters & parms) override;
|
|
|
|
bool SetAutomationParameters(CommandParameters & parms) override;
|
2019-03-01 17:20:51 +00:00
|
|
|
RegistryPaths GetFactoryPresets() override;
|
2016-06-15 00:05:59 +00:00
|
|
|
bool LoadFactoryPreset(int id) override;
|
|
|
|
|
|
|
|
// Effect implementation
|
|
|
|
|
|
|
|
void PopulateOrExchange(ShuttleGui & S) override;
|
|
|
|
bool TransferDataToWindow() override;
|
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
enum control
|
|
|
|
{
|
|
|
|
ID_Type = 10000,
|
|
|
|
ID_DCBlock,
|
|
|
|
ID_Threshold,
|
|
|
|
ID_NoiseFloor,
|
|
|
|
ID_Param1,
|
|
|
|
ID_Param2,
|
|
|
|
ID_Repeats,
|
|
|
|
};
|
|
|
|
// EffectDistortion implementation
|
|
|
|
|
|
|
|
void InstanceInit(EffectDistortionState & data, float sampleRate);
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t InstanceProcess(EffectDistortionState & data,
|
2016-06-15 00:05:59 +00:00
|
|
|
float **inBlock,
|
|
|
|
float **outBlock,
|
2016-09-06 13:19:27 +00:00
|
|
|
size_t blockLen);
|
2016-06-15 00:05:59 +00:00
|
|
|
|
|
|
|
// Control Handlers
|
|
|
|
|
|
|
|
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();
|
2019-12-25 18:28:21 +00:00
|
|
|
void UpdateControl(control id, bool enable, TranslatableString name);
|
2016-06-15 00:05:59 +00:00
|
|
|
void UpdateControlText(wxTextCtrl *textCtrl, wxString &string, bool enabled);
|
|
|
|
|
|
|
|
void MakeTable();
|
|
|
|
float WaveShaper(float sample);
|
|
|
|
float DCFilter(EffectDistortionState & data, float sample);
|
|
|
|
|
|
|
|
// Preset tables for gain lookup
|
|
|
|
|
|
|
|
void HardClip(); // hard clipping
|
|
|
|
void SoftClip(); // soft clipping
|
|
|
|
void ExponentialTable(); // exponential mapping
|
|
|
|
void LogarithmicTable(); // logarithmic mapping
|
|
|
|
void HalfSinTable();
|
|
|
|
void CubicTable();
|
|
|
|
void EvenHarmonicTable();
|
|
|
|
void SineTable();
|
|
|
|
void Leveller(); // 'Leveller' wavetable is modeled on the legacy effect of the same name.
|
|
|
|
void Rectifier(); // 0% = Dry, 50% = half-wave rectified, 100% = full-wave rectified (abs value).
|
|
|
|
void HardLimiter(); // Same effect as the LADSPA "hardLimiter 1413"
|
|
|
|
|
|
|
|
// Wavetable helper functions
|
|
|
|
|
|
|
|
void CopyHalfTable(); // for symmetric tables
|
|
|
|
|
|
|
|
// Used by Soft Clipping but could be used for other tables.
|
|
|
|
// Log curve formula: y = T + (((e^(RT - Rx)) - 1) / -R)
|
|
|
|
// where R is the ratio, T is the threshold, and x is from T to 1.
|
|
|
|
inline float LogCurve(double threshold, float value, double ratio);
|
|
|
|
|
|
|
|
// Used by Cubic curve but could be used for other tables
|
|
|
|
// Cubic formula: y = x - (x^3 / 3.0)
|
|
|
|
inline double Cubic(double x);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
EffectDistortionState mMaster;
|
2018-02-02 18:24:53 +00:00
|
|
|
std::vector<EffectDistortionState> mSlaves;
|
2016-06-15 00:05:59 +00:00
|
|
|
|
|
|
|
double mTable[TABLESIZE];
|
|
|
|
double mThreshold;
|
|
|
|
bool mbSavedFilterState;
|
|
|
|
|
|
|
|
// mMakeupGain is used by some distortion types to pass the
|
|
|
|
// amount of gain required to bring overall effect gain to unity
|
|
|
|
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;
|
|
|
|
|
2016-09-18 14:26:29 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2016-06-15 00:05:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|