1 /**********************************************************************
2 
3    Audacity: A Digital Audio Editor
4    Audacity(R) is copyright (c) 1999-2016 Audacity Team.
5    License: GPL v2.  See License.txt.
6 
7    BassTreble.h (two shelf filters)
8    Steve Daulton
9 
10 **********************************************************************/
11 
12 #ifndef __AUDACITY_EFFECT_BASS_TREBLE__
13 #define __AUDACITY_EFFECT_BASS_TREBLE__
14 
15 #include "Effect.h"
16 
17 class wxSlider;
18 class wxCheckBox;
19 class wxTextCtrl;
20 class ShuttleGui;
21 
22 class EffectBassTrebleState
23 {
24 public:
25    float samplerate;
26    double treble;
27    double bass;
28    double gain;
29    double slope, hzBass, hzTreble;
30    double a0Bass, a1Bass, a2Bass, b0Bass, b1Bass, b2Bass;
31    double a0Treble, a1Treble, a2Treble, b0Treble, b1Treble, b2Treble;
32    double xn1Bass, xn2Bass, yn1Bass, yn2Bass;
33    double xn1Treble, xn2Treble, yn1Treble, yn2Treble;
34 };
35 
36 class EffectBassTreble final : public Effect
37 {
38 public:
39    static const ComponentInterfaceSymbol Symbol;
40 
41    EffectBassTreble();
42    virtual ~EffectBassTreble();
43 
44    // ComponentInterface implementation
45 
46    ComponentInterfaceSymbol GetSymbol() override;
47    TranslatableString GetDescription() override;
48    ManualPageID ManualPage() override;
49 
50    // EffectDefinitionInterface implementation
51 
52    EffectType GetType() override;
53    bool SupportsRealtime() override;
54 
55    // EffectClientInterface implementation
56 
57    unsigned GetAudioInCount() override;
58    unsigned GetAudioOutCount() override;
59    bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap = NULL) override;
60    size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override;
61    bool RealtimeInitialize() override;
62    bool RealtimeAddProcessor(unsigned numChannels, float sampleRate) override;
63    bool RealtimeFinalize() override;
64    size_t RealtimeProcess(int group,
65                                float **inbuf,
66                                float **outbuf,
67                                size_t numSamples) override;
68    bool DefineParams( ShuttleParams & S ) override;
69    bool GetAutomationParameters(CommandParameters & parms) override;
70    bool SetAutomationParameters(CommandParameters & parms) override;
71 
72 
73    // Effect Implementation
74 
75    void PopulateOrExchange(ShuttleGui & S) override;
76    bool TransferDataToWindow() override;
77    bool TransferDataFromWindow() override;
78 
79    bool CheckWhetherSkipEffect() override;
80 
81 private:
82    // EffectBassTreble implementation
83 
84    void InstanceInit(EffectBassTrebleState & data, float sampleRate);
85    size_t InstanceProcess(EffectBassTrebleState & data, float **inBlock, float **outBlock, size_t blockLen);
86 
87    void Coefficients(double hz, double slope, double gain, double samplerate, int type,
88                     double& a0, double& a1, double& a2, double& b0, double& b1, double& b2);
89    float DoFilter(EffectBassTrebleState & data, float in);
90 
91    void OnBassText(wxCommandEvent & evt);
92    void OnTrebleText(wxCommandEvent & evt);
93    void OnGainText(wxCommandEvent & evt);
94    void OnBassSlider(wxCommandEvent & evt);
95    void OnTrebleSlider(wxCommandEvent & evt);
96    void OnGainSlider(wxCommandEvent & evt);
97    void OnLinkCheckbox(wxCommandEvent & evt);
98 
99    // Auto-adjust gain to reduce variation in peak level
100    void UpdateGain(double oldVal, int control );
101 
102 private:
103    EffectBassTrebleState mMaster;
104    std::vector<EffectBassTrebleState> mSlaves;
105 
106    double      mBass;
107    double      mTreble;
108    double      mGain;
109    bool        mLink;
110 
111    wxSlider    *mBassS;
112    wxSlider    *mTrebleS;
113    wxSlider    *mGainS;
114 
115    wxTextCtrl  *mBassT;
116    wxTextCtrl  *mTrebleT;
117    wxTextCtrl  *mGainT;
118 
119    wxCheckBox  *mLinkCheckBox;
120 
121    DECLARE_EVENT_TABLE()
122 };
123 
124 #endif
125