Audacity  2.2.0
NoiseRemoval.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  NoiseRemoval.h
6 
7  Dominic Mazzoni
8  Vaughan Johnson (Preview)
9 
10 **********************************************************************/
11 
12 #ifndef __AUDACITY_EFFECT_NOISE_REMOVAL__
13 #define __AUDACITY_EFFECT_NOISE_REMOVAL__
14 
15 #include "../Audacity.h"
16 
17 #include "../Experimental.h"
18 
19 #if !defined(EXPERIMENTAL_NOISE_REDUCTION)
20 
21 #include "Effect.h"
22 
23 #include "../MemoryX.h"
24 #include "../SampleFormat.h"
25 #include <wx/dialog.h>
26 #include <wx/slider.h>
27 
28 class wxButton;
29 class wxSizer;
30 class wxString;
31 
32 class Envelope;
33 class WaveTrack;
34 
35 class wxRadioButton;
36 class wxTextCtrl;
37 
38 #include "../RealFFTf.h"
39 
40 #define NOISEREMOVAL_PLUGIN_SYMBOL XO("Noise Removal")
41 
42 class EffectNoiseRemoval final : public Effect
43 {
44 public:
46  virtual ~EffectNoiseRemoval();
47 
48  // IdentInterface implementation
49 
50  wxString GetSymbol() override;
51  wxString GetDescription() override;
52 
53  // EffectIdentInterface implementation
54 
55  EffectType GetType() override;
56  bool SupportsAutomation() override;
57 
58  // Effect implementation
59 
60  bool PromptUser(wxWindow *parent) override;
61  bool Init() override;
62  bool CheckWhetherSkipEffect() override;
63  bool Process() override;
64  void End() override;
65 
66 private:
67 
68  bool mDoProfile;
69  bool mHasProfile;
70  int mLevel;
71 
72  // Parameters chosen before the first phase
73  double mSampleRate;
74  size_t mWindowSize;
75  size_t mSpectrumSize;
76  float mMinSignalTime; // in secs
77 
78  // The frequency-indexed noise threshold derived during the first
79  // phase of analysis
80  Floats mNoiseThreshold; // length is mSpectrumSize
81 
82  // Parameters that affect the noise removal, regardless of how the
83  // noise profile was extracted
84  double mSensitivity;
85  double mFreqSmoothingHz;
86  double mNoiseGain; // in dB, should be negative
87  double mAttackDecayTime; // in secs
88  bool mbLeaveNoise;
89 
90  bool ProcessOne(int count, WaveTrack * track,
91  sampleCount start, sampleCount len);
92 
93  void Initialize();
94  void StartNewTrack();
95  void ProcessSamples(size_t len, float *buffer);
96  void FillFirstHistoryWindow();
97  void ApplyFreqSmoothing(float *spec);
98  void GetProfile();
99  void RemoveNoise();
100  void RotateHistoryWindows();
101  void FinishTrack();
102 
103  // Variables that only exist during processing
104  std::unique_ptr<WaveTrack> mOutputTrack;
105  sampleCount mInSampleCount;
106  sampleCount mOutSampleCount;
107  int mInputPos;
108 
109  HFFT hFFT;
110  Floats mFFTBuffer; // mWindowSize
111  Floats mWindow; // mWindowSize
112 
113  int mFreqSmoothingBins;
114  int mAttackDecayBlocks;
115  float mOneBlockAttackDecay;
116  float mNoiseAttenFactor;
117  float mSensitivityFactor;
118  size_t mMinSignalBlocks;
119  size_t mHistoryLen;
120  Floats mInWaveBuffer; // mWindowSize
121  Floats mOutOverlapBuffer; // mWindowSize
122  ArraysOf<float> mSpectrums; // mHistoryLen x mSpectrumSize
123  ArraysOf<float> mGains; // mHistoryLen x mSpectrumSize
124  ArraysOf<float> mRealFFTs; // mHistoryLen x mWindowSize
125  ArraysOf<float> mImagFFTs; // mHistoryLen x mWindowSize
126 
127  friend class NoiseRemovalDialog;
128 };
129 
130 // WDR: class declarations
131 
132 //----------------------------------------------------------------------------
133 // NoiseRemovalDialog
134 //----------------------------------------------------------------------------
135 
136 // Declare window functions
137 
138 class NoiseRemovalDialog final : public EffectDialog
139 {
140 public:
141  // constructors and destructors
143  wxWindow *parent);
144 
145  wxSizer *MakeNoiseRemovalDialog(bool call_fit = true,
146  bool set_sizer = true);
147 
148  void PopulateOrExchange(ShuttleGui & S);
149  bool TransferDataToWindow() override;
150  bool TransferDataFromWindow() override;
151 
152 private:
153  // handlers
154  void OnGetProfile( wxCommandEvent &event );
155  void OnKeepNoise( wxCommandEvent &event );
156  void OnPreview(wxCommandEvent &event);
157  void OnRemoveNoise( wxCommandEvent &event );
158  void OnCancel( wxCommandEvent &event );
159 
160  void OnSensitivityText(wxCommandEvent & event);
161  void OnGainText(wxCommandEvent & event);
162  void OnFreqText(wxCommandEvent & event);
163  void OnTimeText(wxCommandEvent & event);
164  void OnSensitivitySlider(wxCommandEvent & event);
165  void OnGainSlider(wxCommandEvent & event);
166  void OnFreqSlider(wxCommandEvent & event);
167  void OnTimeSlider(wxCommandEvent & event);
168 
169  public:
170 
171  EffectNoiseRemoval * m_pEffect;
172 
173  wxButton * m_pButton_GetProfile;
174  wxButton * m_pButton_Preview;
175  wxButton * m_pButton_RemoveNoise;
176 
177  wxRadioButton *mKeepSignal;
178  wxRadioButton *mKeepNoise;
179 
180  wxSlider *mSensitivityS;
181  wxSlider *mGainS;
182  wxSlider *mFreqS;
183  wxSlider *mTimeS;
184 
185  wxTextCtrl *mSensitivityT;
186  wxTextCtrl *mGainT;
187  wxTextCtrl *mFreqT;
188  wxTextCtrl *mTimeT;
189 
190  double mSensitivity;
191  double mGain;
192  double mFreq;
193  double mTime;
194 
195  bool mbLeaveNoise;
196 
197 private:
198  DECLARE_EVENT_TABLE()
199 
200 };
201 
202 #endif
203 
204 #endif
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
Draggable curve used in TrackPanel for varying amplification.
Definition: Envelope.h:78
Base class for many of the effects in Audacity.
Definition: Effect.h:62
New (Jun-2006) base class for effects dialogs. Likely to get greater use in future.
Definition: Effect.h:559
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:24
A two-pass effect to remove background noise.
A Track that contains audio waveform data.
Definition: WaveTrack.h:76
Dialog used with EffectNoiseRemoval.