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;
124 const override;
126
127 RegistryPaths GetFactoryPresets() const override;
129 const override;
130
131 // EffectUIClientInterface implementation
132
133 bool ValidateUI(EffectSettings &) override;
134
135 // Effect implementation
136
137 bool Init() override;
138 bool Process(EffectInstance &instance, EffectSettings &settings) override;
139
140 bool CloseUI() override;
141 std::unique_ptr<EffectUIValidator> PopulateOrExchange(
142 ShuttleGui & S, EffectInstance &instance,
143 EffectSettingsAccess &access, const EffectOutputs *pOutputs) override;
144 bool TransferDataToWindow(const EffectSettings &settings) override;
145
146private:
147 // EffectEqualization implementation
148 wxString GetPrefsPrefix();
149
150 // Number of samples in an FFT window
151 static const size_t windowSize = 16384u; //MJS - work out the optimum for this at run time? Have a dialog box for it?
152
153 // Low frequency of the FFT. 20Hz is the
154 // low range of human hearing
155 enum {loFreqI=20};
156
157 bool ProcessOne(int count, WaveTrack * t,
158 sampleCount start, sampleCount len);
159 bool CalcFilter();
160 void Filter(size_t len, float *buffer);
161
162 void Flatten();
163 void ForceRecalc();
164 void EnvelopeUpdated();
165 void EnvelopeUpdated(Envelope *env, bool lin);
166 bool IsLinear();
167
168 void LoadCurves(const wxString &fileName = {}, bool append = false);
169 void SaveCurves(const wxString &fileName = {});
170 // Merge NEW curves only or update all factory presets.
171 void UpdateDefaultCurves( bool updateAll = false);
172 void Select(int sel);
173 void setCurve(int currentCurve);
174 void setCurve(const wxString &curveName);
175 void setCurve(void);
176 bool GetDefaultFileName(wxFileName &fileName);
177
178 // XMLTagHandler callback methods for loading and saving
179 bool HandleXMLTag(const std::string_view& tag, const AttributesList &attrs) override;
180 XMLTagHandler *HandleXMLChild(const std::string_view& tag) override;
181 void WriteXML(XMLWriter &xmlFile) const;
182
183 void UpdateCurves();
184 void UpdateRuler();
185 void UpdateDraw();
186
187 //void LayoutEQSliders();
188 void UpdateGraphic(void);
189 void EnvLogToLin(void);
190 void EnvLinToLog(void);
191 void ErrMin(void);
192 void GraphicEQ(Envelope *env);
193 void spline(double x[], double y[], size_t n, double y2[]);
194 double splint(double x[], double y[], size_t n, double y2[], double xr);
195
196 void OnErase( wxEvent &event );
197 void OnSize( wxSizeEvent & event );
198 void OnSlider( wxCommandEvent & event );
199 void OnInterp( wxCommandEvent & event );
200 void OnSliderM( wxCommandEvent & event );
201 void OnSliderDBMAX( wxCommandEvent & event );
202 void OnSliderDBMIN( wxCommandEvent & event );
203 void OnDrawMode( wxCommandEvent &event );
204 void OnGraphicMode( wxCommandEvent &event );
205 void OnCurve( wxCommandEvent & event );
206 void OnManage( wxCommandEvent & event );
207 void OnClear( wxCommandEvent & event );
208 void OnInvert( wxCommandEvent & event );
209 void OnGridOnOff( wxCommandEvent & event );
210 void OnLinFreq( wxCommandEvent & event );
211#ifdef EXPERIMENTAL_EQ_SSE_THREADED
212 void OnProcessingRadio( wxCommandEvent & event );
213 void OnBench( wxCommandEvent & event );
214#endif
215
219 size_t mM;
220 wxString mCurveName;
221 bool mLin;
222 float mdBMax;
223 float mdBMin;
227
233
235 double mLoFreq;
236 double mHiFreq;
238 bool mDirty;
241
243
244 std::unique_ptr<Envelope> mLogEnvelope, mLinEnvelope;
246
247#ifdef EXPERIMENTAL_EQ_SSE_THREADED
248 bool mBench;
249 std::unique_ptr<EffectEqualization48x> mEffectEqualization48x;
250 friend class EffectEqualization48x;
251#endif
252
253 wxSizer *szrC;
254 wxSizer *szrG;
255 wxSizer *szrV;
256 wxSizer *szrH;
257 wxSizer *szrI;
258 wxSizer *szrL;
259 wxSizer *szr1;
260 wxSizer *szr2;
261 wxSizer *szr3;
262 wxSizer *szr4;
263 wxSizer *szr5;
264
265 wxSizerItem *mLeftSpacer;
266
268 //wxPanel *mGraphicPanel;
269 wxRadioButton *mDraw;
270 wxRadioButton *mGraphic;
271 wxCheckBox *mLinFreq;
272 wxCheckBox *mGridOnOff;
273 wxChoice *mInterpChoice;
274 wxChoice *mCurve;
275 wxButton *mManage;
276 wxStaticText *mMText;
277 wxSlider *mMSlider;
278 wxSlider *mdBMinSlider;
279 wxSlider *mdBMaxSlider;
281
282#ifdef EXPERIMENTAL_EQ_SSE_THREADED
283 wxRadioButton *mMathProcessingType[5]; // default, sse, sse threaded, AVX, AVX threaded (note AVX is not implemented yet
284 wxBoxSizer *szrM;
285#endif
286
287 const EffectParameterMethods& Parameters() const override;
288
289 DECLARE_EVENT_TABLE()
290
291 friend class EqualizationPanel;
292 friend class EditCurvesDialog;
293
295 {
300 };
302
303// Not all of these are visited now
305 L"FilterLength", 8191, 21, 8191, 0 };
307 L"CurveName", L"unnamed", L"", L"", L""};
309 L"InterpolateLin", false, false, true, false };
311 L"InterpolationMethod", 0, 0, 0, 0, kInterpStrings, nInterpolations };
313 L"", true, false, true, false };
315 L"", true, false, true, false };
317 L"", -30.0f, -120.0, -10.0, 0 };
319 L"", 30.0f, 0.0, 60.0, 0 };
320};
321
323{
324public:
326
328};
329
331{
332public:
334
336};
337
339{
340public:
342 wxWindow *parent, wxWindowID winid, EffectEqualization *effect);
344
345 // We don't need or want to accept focus.
346 bool AcceptsFocus() const { return false; }
347 // So that wxPanel is not included in Tab traversal - see wxWidgets bug 15581
348 bool AcceptsFocusFromKeyboard() const { return false; }
349
350 void ForceRecalc();
351
352private:
353 void Recalc();
354
355 void OnMouseEvent(wxMouseEvent & event);
356 void OnCaptureLost(wxMouseCaptureLostEvent & event);
357 void OnPaint(wxPaintEvent & event);
358 void OnSize (wxSizeEvent & event);
359
360public:
361// int & mM;
362// float & mdBMax;
363// float & mdBMin;
364// Envelope & mEnvelope;
365
366private:
367 wxWindow *mParent;
369 std::unique_ptr<EnvelopeEditor> mLinEditor, mLogEditor;
370
372
373 std::unique_ptr<wxBitmap> mBitmap;
374 wxRect mEnvRect;
377// size_t mWindowSize;
378// float *mFilterFuncR;
379// float *mFilterFuncI;
381
382// double mLoFreq;
383// double mHiFreq;
384
385 DECLARE_EVENT_TABLE()
386};
387
388// EditCurvesDialog. Note that the 'modified' curve used to be called 'custom' but is now called 'unnamed'
389// Some things that deal with 'unnamed' curves still use, for example, 'mCustomBackup' as variable names.
391{
392public:
393 EditCurvesDialog(wxWindow * parent, EffectEqualization * effect, int position);
395
396private:
397
399 {
409 };
410
411 wxListCtrl *mList; // List of curves.
412 EQCurveArray mEditCurves; // Copy of curves to muck about with
413 wxWindow *mParent; // the parent EQ Dialog
414 EffectEqualization *mEffect; // the parent EQ effect
415 int mPosition; // position of current curve in list
416 void Populate();
418 void PopulateList(int position);
419 void OnUp(wxCommandEvent &event);
420 void OnDown(wxCommandEvent &event);
421 long GetPreviousItem(long item);
422 void OnRename( wxCommandEvent &event );
423 void OnDelete( wxCommandEvent &event );
424 void OnImport( wxCommandEvent &event );
425 void OnExport( wxCommandEvent &event );
426 void OnLibrary( wxCommandEvent &event );
427 void OnDefaults( wxCommandEvent &event );
428 void OnOK(wxCommandEvent &event);
429
430 void OnListSelectionChange( wxListEvent &event );
431 DECLARE_EVENT_TABLE()
432};
433
434#endif
const TranslatableString name
Definition: Distortion.cpp:82
std::optional< std::unique_ptr< EffectSettingsAccess::Message > > OptionalMessage
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:413
EffectEqualization * mEffect
Definition: Equalization.h:414
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:411
void OnLibrary(wxCommandEvent &event)
EditCurvesDialog(wxWindow *parent, EffectEqualization *effect, int position)
void OnRename(wxCommandEvent &event)
EQCurveArray mEditCurves
Definition: Equalization.h:412
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:325
static const ComponentInterfaceSymbol Symbol
Definition: Equalization.h:333
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:228
void OnLinFreq(wxCommandEvent &event)
bool GetDefaultFileName(wxFileName &fileName)
OptionalMessage DoLoadFactoryDefaults(EffectSettings &settings)
wxChoice * mInterpChoice
Definition: Equalization.h:273
const EffectParameterMethods & Parameters() const override
static const size_t windowSize
Definition: Equalization.h:151
wxCheckBox * mLinFreq
Definition: Equalization.h:271
void UpdateGraphic(void)
virtual ~EffectEqualization()
std::unique_ptr< Envelope > mLinEnvelope
Definition: Equalization.h:244
wxCheckBox * mGridOnOff
Definition: Equalization.h:272
static constexpr EffectParameter DrawGrid
Definition: Equalization.h:314
OptionalMessage LoadFactoryPreset(int id, EffectSettings &settings) const override
wxStaticText * mMText
Definition: Equalization.h:276
EqualizationPanel * mPanel
Definition: Equalization.h:267
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:308
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:269
void OnErase(wxEvent &event)
wxSizerItem * mLeftSpacer
Definition: Equalization.h:265
static constexpr EffectParameter dBMin
Definition: Equalization.h:316
std::unique_ptr< Envelope > mLogEnvelope
Definition: Equalization.h:244
TranslatableString GetDescription() const override
void OnManage(wxCommandEvent &event)
void Filter(size_t len, float *buffer)
void OnClear(wxCommandEvent &event)
wxSlider * mdBMinSlider
Definition: Equalization.h:278
double splint(double x[], double y[], size_t n, double y2[], double xr)
Envelope * mEnvelope
Definition: Equalization.h:245
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
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)
OptionalMessage LoadFactoryDefaults(EffectSettings &settings) const override
void OnSliderDBMAX(wxCommandEvent &event)
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
RulerPanel * mdBRuler
Definition: Equalization.h:231
wxRadioButton * mGraphic
Definition: Equalization.h:270
static constexpr EffectParameter CurveName
Definition: Equalization.h:306
static const EnumValueSymbol kInterpStrings[nInterpolations]
Definition: Equalization.h:301
wxSlider * mMSlider
Definition: Equalization.h:277
wxSlider * mdBMaxSlider
Definition: Equalization.h:279
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
RulerPanel * mFreqRuler
Definition: Equalization.h:232
bool CloseUI() override
int mSlidersOld[NUMBER_OF_BANDS]
Definition: Equalization.h:239
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:304
void LoadCurves(const wxString &fileName={}, bool append=false)
wxButton * mManage
Definition: Equalization.h:275
static constexpr EffectParameter DrawMode
Definition: Equalization.h:312
wxSlider * mSliders[NUMBER_OF_BANDS]
Definition: Equalization.h:280
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:240
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:229
static constexpr EnumParameter InterpMeth
Definition: Equalization.h:310
void OnInterp(wxCommandEvent &event)
EQCurveArray mCurves
Definition: Equalization.h:242
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:318
bool ProcessOne(int count, WaveTrack *t, sampleCount start, sampleCount len)
Performs effect computation.
Hold values to send to effect output meters.
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:339
void OnSize(wxSizeEvent &event)
bool AcceptsFocusFromKeyboard() const
Definition: Equalization.h:348
EffectEqualization * mEffect
Definition: Equalization.h:368
bool AcceptsFocus() const
Definition: Equalization.h:346
void OnCaptureLost(wxMouseCaptureLostEvent &event)
std::unique_ptr< wxBitmap > mBitmap
Definition: Equalization.h:373
std::unique_ptr< EnvelopeEditor > mLinEditor
Definition: Equalization.h:369
void OnMouseEvent(wxMouseEvent &event)
void OnPaint(wxPaintEvent &event)
EqualizationPanel(wxWindow *parent, wxWindowID winid, EffectEqualization *effect)
wxWindow * mParent
Definition: Equalization.h:367
std::unique_ptr< EnvelopeEditor > mLogEditor
Definition: Equalization.h:369
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.