1 /********************************************************************** 2 3 Audacity: A Digital Audio Editor 4 5 Compressor.h 6 7 Dominic Mazzoni 8 9 **********************************************************************/ 10 11 #ifndef __AUDACITY_EFFECT_COMPRESSOR__ 12 #define __AUDACITY_EFFECT_COMPRESSOR__ 13 14 #include "TwoPassSimpleMono.h" 15 16 class wxCheckBox; 17 class wxSlider; 18 class wxStaticText; 19 class EffectCompressorPanel; 20 class ShuttleGui; 21 22 class EffectCompressor final : public EffectTwoPassSimpleMono 23 { 24 public: 25 static const ComponentInterfaceSymbol Symbol; 26 27 EffectCompressor(); 28 virtual ~EffectCompressor(); 29 30 // ComponentInterface implementation 31 32 ComponentInterfaceSymbol GetSymbol() override; 33 TranslatableString GetDescription() override; 34 ManualPageID ManualPage() override; 35 36 // EffectDefinitionInterface implementation 37 38 EffectType GetType() override; 39 40 // EffectClientInterface implementation 41 42 bool DefineParams( ShuttleParams & S ) override; 43 bool GetAutomationParameters(CommandParameters & parms) override; 44 bool SetAutomationParameters(CommandParameters & parms) override; 45 46 // Effect implementation 47 48 bool Startup() override; 49 void PopulateOrExchange(ShuttleGui & S) override; 50 bool TransferDataToWindow() override; 51 bool TransferDataFromWindow() override; 52 53 protected: 54 // EffectTwoPassSimpleMono implementation 55 56 bool InitPass1() override; 57 bool InitPass2() override; 58 bool NewTrackPass1() override; 59 bool ProcessPass2(float *buffer, size_t len) override; 60 bool TwoBufferProcessPass1 61 (float *buffer1, size_t len1, float *buffer2, size_t len2) override; 62 63 private: 64 // EffectCompressor implementation 65 66 void FreshenCircle(); 67 float AvgCircle(float x); 68 void Follow(float *buffer, float *env, size_t len, float *previous, size_t previous_len); 69 float DoCompression(float x, double env); 70 71 void OnSlider(wxCommandEvent & evt); 72 void UpdateUI(); 73 74 private: 75 double mRMSSum; 76 size_t mCircleSize; 77 size_t mCirclePos; 78 Doubles mCircle; 79 80 double mAttackTime; 81 double mThresholdDB; 82 double mNoiseFloorDB; 83 double mRatio; 84 bool mNormalize; //MJS 85 bool mUsePeak; 86 87 double mDecayTime; // The "Release" time. 88 double mAttackFactor; 89 double mAttackInverseFactor; 90 double mDecayFactor; 91 double mThreshold; 92 double mCompression; 93 double mNoiseFloor; 94 int mNoiseCounter; 95 double mGain; 96 double mLastLevel; 97 Floats mFollow1, mFollow2; 98 size_t mFollowLen; 99 100 double mMax; //MJS 101 102 EffectCompressorPanel *mPanel; 103 104 wxStaticText *mThresholdLabel; 105 wxSlider *mThresholdSlider; 106 wxStaticText *mThresholdText; 107 108 wxStaticText *mNoiseFloorLabel; 109 wxSlider *mNoiseFloorSlider; 110 wxStaticText *mNoiseFloorText; 111 112 wxStaticText *mRatioLabel; 113 wxSlider *mRatioSlider; 114 wxStaticText *mRatioText; 115 116 wxStaticText *mAttackLabel; 117 wxSlider *mAttackSlider; 118 wxStaticText *mAttackText; 119 120 wxStaticText *mDecayLabel; 121 wxSlider *mDecaySlider; 122 wxStaticText *mDecayText; 123 124 wxCheckBox *mGainCheckBox; 125 wxCheckBox *mPeakCheckBox; 126 127 DECLARE_EVENT_TABLE() 128 }; 129 130 class EffectCompressorPanel final : public wxPanelWrapper 131 { 132 public: 133 EffectCompressorPanel(wxWindow *parent, wxWindowID winid, 134 double & threshold, 135 double & noiseFloor, 136 double & ratio); 137 138 private: 139 void OnPaint(wxPaintEvent & evt); 140 void OnSize(wxSizeEvent & evt); 141 142 private: 143 double & threshold; 144 double & noiseFloor; 145 double & ratio; 146 147 DECLARE_EVENT_TABLE() 148 }; 149 150 #endif 151 152