Audacity 3.2.0
Equalization.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Equalization.h
6
7 Mitch Golden
8 Vaughan Johnson (Preview)
9
10***********************************************************************/
11
12#ifndef __AUDACITY_EFFECT_EQUALIZATION__
13#define __AUDACITY_EFFECT_EQUALIZATION__
14#define NUMBER_OF_BANDS 31
15#define NUM_PTS 180
16#define PANELBORDER 1 // only increase from '1' for testing purposes - MJS
17
18#include <wx/setup.h> // for wxUSE_* macros
19
20#include "Effect.h"
21#include "RealFFTf.h"
22#include "../ShuttleAutomation.h"
23#include "../widgets/wxPanelWrapper.h"
24#include "XMLTagHandler.h"
25
26// Flags to specialise the UI
27const int kEqOptionGraphic =1;
28const int kEqOptionCurve =1<<1;
29// The legacy version offers both Graphic and curve on the same UI.
31
32class wxBitmap;
33class wxBoxSizer;
34class wxButton;
35class wxCheckBox;
36class wxChoice;
37class wxListCtrl;
38class wxListEvent;
39class wxRadioButton;
40class wxSizer;
41class wxSizerItem;
42class wxSlider;
43class wxStaticText;
44class Envelope;
45class EnvelopeEditor;
47class RulerPanel;
48
50
51//
52// One point in a curve
53//
55{
56public:
57 EQPoint( const double f, const double d ) { Freq = f; dB = d; }
58
59 bool operator < (const EQPoint &p1) const
60 {
61 return Freq < p1.Freq;
62 }
63
64 double Freq;
65 double dB;
66};
67
68//
69// One curve in a list
70//
71// LLL: This "really" isn't needed as the array of points could be
72// attached as wxClientData to the wxChoice entries. I
73// didn't realize this until after the fact and am too
74// lazy to change it. (But, hollar if you want me to.)
75//
77{
78public:
79 EQCurve( const wxString & name = {} ) { Name = name; }
80 EQCurve( const wxChar * name ) { Name = name; }
81
82 bool operator < (const EQCurve &that) const
83 {
84 return Name.CmpNoCase(that.Name) < 0;
85 }
86
87 wxString Name;
88 std::vector<EQPoint> points;
89};
90
91using EQCurveArray = std::vector<EQCurve>;
92
93#ifdef EXPERIMENTAL_EQ_SSE_THREADED
94class EffectEqualization48x;
95#endif
96
98 public XMLTagHandler
99{
100public:
101 static inline EffectEqualization *
104
106
107 virtual ~EffectEqualization();
108
109 // ComponentInterface implementation
110
111 ComponentInterfaceSymbol GetSymbol() const override;
112 TranslatableString GetDescription() const override;
113 ManualPageID ManualPage() const override;
115 override;
116 bool VisitSettings(
118 const override;
119
120 // EffectDefinitionInterface implementation
121
122 EffectType GetType() const override;
123 bool LoadFactoryDefaults(EffectSettings &settings) const override;
125
126 RegistryPaths GetFactoryPresets() const override;
127 bool LoadFactoryPreset(int id, EffectSettings &settings) const override;
128
129 // EffectUIClientInterface implementation
130
131 bool ValidateUI(EffectSettings &) override;
132
133 // Effect implementation
134
135 bool Init() override;
136 bool Process(EffectInstance &instance, EffectSettings &settings) override;
137
138 bool CloseUI() override;
139 std::unique_ptr<EffectUIValidator> PopulateOrExchange(
140 ShuttleGui & S, EffectInstance &instance, EffectSettingsAccess &access)
141 override;
142 bool TransferDataToWindow(const EffectSettings &settings) override;
143
144private:
145 // EffectEqualization implementation
146 wxString GetPrefsPrefix();
147
148 // Number of samples in an FFT window
149 static const size_t windowSize = 16384u; //MJS - work out the optimum for this at run time? Have a dialog box for it?
150
151 // Low frequency of the FFT. 20Hz is the
152 // low range of human hearing
153 enum {loFreqI=20};
154
155 bool ProcessOne(int count, WaveTrack * t,
156 sampleCount start, sampleCount len);
157 bool CalcFilter();
158 void Filter(size_t len, float *buffer);
159
160 void Flatten();
161 void ForceRecalc();
162 void EnvelopeUpdated();
163 void EnvelopeUpdated(Envelope *env, bool lin);
164 bool IsLinear();
165
166 void LoadCurves(const wxString &fileName = {}, bool append = false);
167 void SaveCurves(const wxString &fileName = {});
168 // Merge NEW curves only or update all factory presets.
169 void UpdateDefaultCurves( bool updateAll = false);
170 void Select(int sel);
171 void setCurve(int currentCurve);
172 void setCurve(const wxString &curveName);
173 void setCurve(void);
174 bool GetDefaultFileName(wxFileName &fileName);
175
176 // XMLTagHandler callback methods for loading and saving
177 bool HandleXMLTag(const std::string_view& tag, const AttributesList &attrs) override;
178 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
179 void WriteXML(XMLWriter &xmlFile) const;
180
181 void UpdateCurves();
182 void UpdateRuler();
183 void UpdateDraw();
184
185 //void LayoutEQSliders();
186 void UpdateGraphic(void);
187 void EnvLogToLin(void);
188 void EnvLinToLog(void);
189 void ErrMin(void);
190 void GraphicEQ(Envelope *env);
191 void spline(double x[], double y[], size_t n, double y2[]);
192 double splint(double x[], double y[], size_t n, double y2[], double xr);
193
194 void OnErase( wxEvent &event );
195 void OnSize( wxSizeEvent & event );
196 void OnSlider( wxCommandEvent & event );
197 void OnInterp( wxCommandEvent & event );
198 void OnSliderM( wxCommandEvent & event );
199 void OnSliderDBMAX( wxCommandEvent & event );
200 void OnSliderDBMIN( wxCommandEvent & event );
201 void OnDrawMode( wxCommandEvent &event );
202 void OnGraphicMode( wxCommandEvent &event );
203 void OnCurve( wxCommandEvent & event );
204 void OnManage( wxCommandEvent & event );
205 void OnClear( wxCommandEvent & event );
206 void OnInvert( wxCommandEvent & event );
207 void OnGridOnOff( wxCommandEvent & event );
208 void OnLinFreq( wxCommandEvent & event );
209#ifdef EXPERIMENTAL_EQ_SSE_THREADED
210 void OnProcessingRadio( wxCommandEvent & event );
211 void OnBench( wxCommandEvent & event );
212#endif
213
217 size_t mM;
218 wxString mCurveName;
219 bool mLin;
220 float mdBMax;
221 float mdBMin;
225
231
233 double mLoFreq;
234 double mHiFreq;
236 bool mDirty;
239
241
242 std::unique_ptr<Envelope> mLogEnvelope, mLinEnvelope;
244
245#ifdef EXPERIMENTAL_EQ_SSE_THREADED
246 bool mBench;
247 std::unique_ptr<EffectEqualization48x> mEffectEqualization48x;
248 friend class EffectEqualization48x;
249#endif
250
251 wxSizer *szrC;
252 wxSizer *szrG;
253 wxSizer *szrV;
254 wxSizer *szrH;
255 wxSizer *szrI;
256 wxSizer *szrL;
257 wxSizer *szr1;
258 wxSizer *szr2;
259 wxSizer *szr3;
260 wxSizer *szr4;
261 wxSizer *szr5;
262
263 wxSizerItem *mLeftSpacer;
264
266 //wxPanel *mGraphicPanel;
267 wxRadioButton *mDraw;
268 wxRadioButton *mGraphic;
269 wxCheckBox *mLinFreq;
270 wxCheckBox *mGridOnOff;
271 wxChoice *mInterpChoice;
272 wxChoice *mCurve;
273 wxButton *mManage;
274 wxStaticText *mMText;
275 wxSlider *mMSlider;
276 wxSlider *mdBMinSlider;
277 wxSlider *mdBMaxSlider;
279
280#ifdef EXPERIMENTAL_EQ_SSE_THREADED
281 wxRadioButton *mMathProcessingType[5]; // default, sse, sse threaded, AVX, AVX threaded (note AVX is not implemented yet
282 wxBoxSizer *szrM;
283#endif
284
285 const EffectParameterMethods& Parameters() const override;
286
287 DECLARE_EVENT_TABLE()
288
289 friend class EqualizationPanel;
290 friend class EditCurvesDialog;
291
293 {
298 };
300
301// Not all of these are visited now
303 L"FilterLength", 8191, 21, 8191, 0 };
305 L"CurveName", L"unnamed", L"", L"", L""};
307 L"InterpolateLin", false, false, true, false };
309 L"InterpolationMethod", 0, 0, 0, 0, kInterpStrings, nInterpolations };
311 L"", true, false, true, false };
313 L"", true, false, true, false };
315 L"", -30.0f, -120.0, -10.0, 0 };
317 L"", 30.0f, 0.0, 60.0, 0 };
318};
319
321{
322public:
324
326};
327
329{
330public:
332
334};
335
337{
338public:
340 wxWindow *parent, wxWindowID winid, EffectEqualization *effect);
342
343 // We don't need or want to accept focus.
344 bool AcceptsFocus() const { return false; }
345 // So that wxPanel is not included in Tab traversal - see wxWidgets bug 15581
346 bool AcceptsFocusFromKeyboard() const { return false; }
347
348 void ForceRecalc();
349
350private:
351 void Recalc();
352
353 void OnMouseEvent(wxMouseEvent & event);
354 void OnCaptureLost(wxMouseCaptureLostEvent & event);
355 void OnPaint(wxPaintEvent & event);
356 void OnSize (wxSizeEvent & event);
357
358public:
359// int & mM;
360// float & mdBMax;
361// float & mdBMin;
362// Envelope & mEnvelope;
363
364private:
365 wxWindow *mParent;
367 std::unique_ptr<EnvelopeEditor> mLinEditor, mLogEditor;
368
370
371 std::unique_ptr<wxBitmap> mBitmap;
372 wxRect mEnvRect;
375// size_t mWindowSize;
376// float *mFilterFuncR;
377// float *mFilterFuncI;
379
380// double mLoFreq;
381// double mHiFreq;
382
383 DECLARE_EVENT_TABLE()
384};
385
386// EditCurvesDialog. Note that the 'modified' curve used to be called 'custom' but is now called 'unnamed'
387// Some things that deal with 'unnamed' curves still use, for example, 'mCustomBackup' as variable names.
389{
390public:
391 EditCurvesDialog(wxWindow * parent, EffectEqualization * effect, int position);
393
394private:
395
397 {
407 };
408
409 wxListCtrl *mList; // List of curves.
410 EQCurveArray mEditCurves; // Copy of curves to muck about with
411 wxWindow *mParent; // the parent EQ Dialog
412 EffectEqualization *mEffect; // the parent EQ effect
413 int mPosition; // position of current curve in list
414 void Populate();
416 void PopulateList(int position);
417 void OnUp(wxCommandEvent &event);
418 void OnDown(wxCommandEvent &event);
419 long GetPreviousItem(long item);
420 void OnRename( wxCommandEvent &event );
421 void OnDelete( wxCommandEvent &event );
422 void OnImport( wxCommandEvent &event );
423 void OnExport( wxCommandEvent &event );
424 void OnLibrary( wxCommandEvent &event );
425 void OnDefaults( wxCommandEvent &event );
426 void OnOK(wxCommandEvent &event);
427
428 void OnListSelectionChange( wxListEvent &event );
429 DECLARE_EVENT_TABLE()
430};
431
432#endif
const TranslatableString name
Definition: Distortion.cpp:82
EffectType
const int kEqLegacy
Definition: Equalization.h:30
#define NUM_PTS
Definition: Equalization.h:15
const int kEqOptionCurve
Definition: Equalization.h:28
const int kEqOptionGraphic
Definition: Equalization.h:27
#define NUMBER_OF_BANDS
Definition: Equalization.h:14
std::vector< EQCurve > EQCurveArray
Definition: Equalization.h:91
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:22
#define S(N)
Definition: ToChars.cpp:64
static Settings & settings()
Definition: TrackInfo.cpp:87
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
EQCurve is used with EffectEqualization.
Definition: Equalization.h:77
EQCurve(const wxChar *name)
Definition: Equalization.h:80
bool operator<(const EQCurve &that) const
Definition: Equalization.h:82
std::vector< EQPoint > points
Definition: Equalization.h:88
EQCurve(const wxString &name={})
Definition: Equalization.h:79
wxString Name
Definition: Equalization.h:87
EQPoint is used with EQCurve and hence EffectEqualization.
Definition: Equalization.h:55
double Freq
Definition: Equalization.h:64
EQPoint(const double f, const double d)
Definition: Equalization.h:57
bool operator<(const EQPoint &p1) const
Definition: Equalization.h:59
double dB
Definition: Equalization.h:65
void OnUp(wxCommandEvent &event)
void OnOK(wxCommandEvent &event)
void OnImport(wxCommandEvent &event)
wxWindow * mParent
Definition: Equalization.h:411
EffectEqualization * mEffect
Definition: Equalization.h:412
void OnDown(wxCommandEvent &event)
long GetPreviousItem(long item)
void Populate()
Creates the dialog and its contents.
void OnDelete(wxCommandEvent &event)
void PopulateList(int position)
wxListCtrl * mList
Definition: Equalization.h:409
void OnLibrary(wxCommandEvent &event)
EditCurvesDialog(wxWindow *parent, EffectEqualization *effect, int position)
void OnRename(wxCommandEvent &event)
EQCurveArray mEditCurves
Definition: Equalization.h:410
void OnListSelectionChange(wxListEvent &event)
void OnDefaults(wxCommandEvent &event)
void OnExport(wxCommandEvent &event)
void PopulateOrExchange(ShuttleGui &S)
Defines the dialog and does data exchange with it.
static const ComponentInterfaceSymbol Symbol
Definition: Equalization.h:323
static const ComponentInterfaceSymbol Symbol
Definition: Equalization.h:331
An Effect that modifies volume in different frequency bands.
Definition: Equalization.h:99
RegistryPaths GetFactoryPresets() const override
Report names of factory presets.
double mWhens[NUM_PTS]
Definition: Equalization.h:226
void OnLinFreq(wxCommandEvent &event)
bool GetDefaultFileName(wxFileName &fileName)
wxChoice * mInterpChoice
Definition: Equalization.h:271
const EffectParameterMethods & Parameters() const override
static const size_t windowSize
Definition: Equalization.h:149
bool LoadFactoryDefaults(EffectSettings &settings) const override
Change settings back to "factory default".
wxCheckBox * mLinFreq
Definition: Equalization.h:269
void UpdateGraphic(void)
virtual ~EffectEqualization()
std::unique_ptr< Envelope > mLinEnvelope
Definition: Equalization.h:242
wxCheckBox * mGridOnOff
Definition: Equalization.h:270
static constexpr EffectParameter DrawGrid
Definition: Equalization.h:312
wxStaticText * mMText
Definition: Equalization.h:274
EqualizationPanel * mPanel
Definition: Equalization.h:265
EffectType GetType() const override
Type determines how it behaves.
void OnSliderDBMIN(wxCommandEvent &event)
bool TransferDataToWindow(const EffectSettings &settings) override
Update controls for the settings.
static constexpr EffectParameter InterpLin
Definition: Equalization.h:306
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
Add controls to effect panel; always succeeds.
void OnGraphicMode(wxCommandEvent &event)
bool VisitSettings(SettingsVisitor &visitor, EffectSettings &settings) override
void GraphicEQ(Envelope *env)
void OnGridOnOff(wxCommandEvent &event)
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
wxRadioButton * mDraw
Definition: Equalization.h:267
void OnErase(wxEvent &event)
wxSizerItem * mLeftSpacer
Definition: Equalization.h:263
static constexpr EffectParameter dBMin
Definition: Equalization.h:314
std::unique_ptr< Envelope > mLogEnvelope
Definition: Equalization.h:242
TranslatableString GetDescription() const override
void OnManage(wxCommandEvent &event)
void Filter(size_t len, float *buffer)
void OnClear(wxCommandEvent &event)
wxSlider * mdBMinSlider
Definition: Equalization.h:276
double splint(double x[], double y[], size_t n, double y2[], double xr)
Envelope * mEnvelope
Definition: Equalization.h:243
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
void OnInvert(wxCommandEvent &event)
void spline(double x[], double y[], size_t n, double y2[])
wxString GetPrefsPrefix()
void OnCurve(wxCommandEvent &event)
void Select(int sel)
void OnSliderDBMAX(wxCommandEvent &event)
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
bool DoLoadFactoryDefaults(EffectSettings &settings)
RulerPanel * mdBRuler
Definition: Equalization.h:229
wxRadioButton * mGraphic
Definition: Equalization.h:268
static constexpr EffectParameter CurveName
Definition: Equalization.h:304
static const EnumValueSymbol kInterpStrings[nInterpolations]
Definition: Equalization.h:299
wxSlider * mMSlider
Definition: Equalization.h:275
wxSlider * mdBMaxSlider
Definition: Equalization.h:277
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
RulerPanel * mFreqRuler
Definition: Equalization.h:230
bool CloseUI() override
int mSlidersOld[NUMBER_OF_BANDS]
Definition: Equalization.h:237
void WriteXML(XMLWriter &xmlFile) const
static EffectEqualization * FetchParameters(EffectEqualization &e, EffectSettings &)
Definition: Equalization.h:102
EffectEqualization(int Options=kEqLegacy)
static constexpr EffectParameter FilterLength
Definition: Equalization.h:302
void LoadCurves(const wxString &fileName={}, bool append=false)
wxButton * mManage
Definition: Equalization.h:273
static constexpr EffectParameter DrawMode
Definition: Equalization.h:310
wxSlider * mSliders[NUMBER_OF_BANDS]
Definition: Equalization.h:278
static const ComponentInterfaceSymbol Symbol
Definition: Equalization.h:103
ComponentInterfaceSymbol GetSymbol() const override
bool ValidateUI(EffectSettings &) override
double mEQVals[NUMBER_OF_BANDS+1]
Definition: Equalization.h:238
bool LoadFactoryPreset(int id, EffectSettings &settings) const override
Change settings to the preset whose name is GetFactoryPresets()[id]
void SaveCurves(const wxString &fileName={})
void OnDrawMode(wxCommandEvent &event)
void OnSize(wxSizeEvent &event)
void OnSliderM(wxCommandEvent &event)
void OnSlider(wxCommandEvent &event)
double mWhenSliders[NUMBER_OF_BANDS+1]
Definition: Equalization.h:227
static constexpr EnumParameter InterpMeth
Definition: Equalization.h:308
void OnInterp(wxCommandEvent &event)
EQCurveArray mCurves
Definition: Equalization.h:240
bool Init() override
Call once to set up state for whole list of tracks to be processed.
void UpdateDefaultCurves(bool updateAll=false)
static constexpr EffectParameter dBMax
Definition: Equalization.h:316
bool ProcessOne(int count, WaveTrack *t, sampleCount start, sampleCount len)
Performs effect computation.
Interface for manipulations of an Effect's settings.
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:72
EqualizationPanel is used with EqualizationDialog and controls a graph for EffectEqualization....
Definition: Equalization.h:337
void OnSize(wxSizeEvent &event)
bool AcceptsFocusFromKeyboard() const
Definition: Equalization.h:346
EffectEqualization * mEffect
Definition: Equalization.h:366
bool AcceptsFocus() const
Definition: Equalization.h:344
void OnCaptureLost(wxMouseCaptureLostEvent &event)
std::unique_ptr< wxBitmap > mBitmap
Definition: Equalization.h:371
std::unique_ptr< EnvelopeEditor > mLinEditor
Definition: Equalization.h:367
void OnMouseEvent(wxMouseEvent &event)
void OnPaint(wxPaintEvent &event)
EqualizationPanel(wxWindow *parent, wxWindowID winid, EffectEqualization *effect)
wxWindow * mParent
Definition: Equalization.h:365
std::unique_ptr< EnvelopeEditor > mLogEditor
Definition: Equalization.h:367
RulerPanel class allows you to work with a Ruler like any other wxWindow.
Definition: Ruler.h:228
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Definition: Shuttle.h:115
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
std::vector< CommandFlagOptions > & Options()
Definition: Menus.cpp:535
Externalized state of a plug-in.