Audacity  3.0.3
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 
16 
17 #if !defined(EXPERIMENTAL_NOISE_REDUCTION)
18 
19 #include "Effect.h"
20 #include "EffectUI.h"
21 
22 class wxButton;
23 class wxSizer;
24 class wxSlider;
25 
26 class Envelope;
27 class WaveTrack;
28 
29 class wxRadioButton;
30 class wxTextCtrl;
31 
32 #include "../RealFFTf.h"
33 
34 class EffectNoiseRemoval final : public Effect
35 {
36 public:
38 
40  virtual ~EffectNoiseRemoval();
41 
42  // ComponentInterface implementation
43 
46 
47  // EffectDefinitionInterface implementation
48 
49  EffectType GetType() override;
50  bool SupportsAutomation() override;
51 
52  // Effect implementation
53 
54  bool ShowInterface( wxWindow &parent,
55  const EffectDialogFactory &factory, bool forceModal = false) override;
56  bool Init() override;
57  bool CheckWhetherSkipEffect() override;
58  bool Process() override;
59  void End() override;
60 
61 private:
62 
63  bool mDoProfile;
65  int mLevel;
66 
67  // Parameters chosen before the first phase
68  double mSampleRate;
69  size_t mWindowSize;
70  size_t mSpectrumSize;
71  float mMinSignalTime; // in secs
72 
73  // The frequency-indexed noise threshold derived during the first
74  // phase of analysis
75  Floats mNoiseThreshold; // length is mSpectrumSize
76 
77  // Parameters that affect the noise removal, regardless of how the
78  // noise profile was extracted
79  double mSensitivity;
81  double mNoiseGain; // in dB, should be negative
82  double mAttackDecayTime; // in secs
84 
85  bool ProcessOne(int count, WaveTrack * track,
86  sampleCount start, sampleCount len);
87 
88  void Initialize();
89  void StartNewTrack();
90  void ProcessSamples(size_t len, float *buffer);
92  void ApplyFreqSmoothing(float *spec);
93  void GetProfile();
94  void RemoveNoise();
95  void RotateHistoryWindows();
96  void FinishTrack();
97 
98  // Variables that only exist during processing
99  std::shared_ptr<WaveTrack> mOutputTrack;
103 
105  Floats mFFTBuffer; // mWindowSize
106  Floats mWindow; // mWindowSize
107 
114  size_t mHistoryLen;
115  Floats mInWaveBuffer; // mWindowSize
116  Floats mOutOverlapBuffer; // mWindowSize
117  ArraysOf<float> mSpectrums; // mHistoryLen x mSpectrumSize
118  ArraysOf<float> mGains; // mHistoryLen x mSpectrumSize
119  ArraysOf<float> mRealFFTs; // mHistoryLen x mWindowSize
120  ArraysOf<float> mImagFFTs; // mHistoryLen x mWindowSize
121 
122  friend class NoiseRemovalDialog;
123 };
124 
125 // WDR: class declarations
126 
127 //----------------------------------------------------------------------------
128 // NoiseRemovalDialog
129 //----------------------------------------------------------------------------
130 
131 // Declare window functions
132 
133 class NoiseRemovalDialog final : public EffectDialog
134 {
135 public:
136  // constructors and destructors
138  wxWindow *parent);
139 
140  wxSizer *MakeNoiseRemovalDialog(bool call_fit = true,
141  bool set_sizer = true);
142 
143  void PopulateOrExchange(ShuttleGui & S) override;
144  bool TransferDataToWindow() override;
145  bool TransferDataFromWindow() override;
146 
147 private:
148  // handlers
149  void OnGetProfile( wxCommandEvent &event );
150  void OnKeepNoise( wxCommandEvent &event );
151  void OnPreview(wxCommandEvent &event) override;
152  void OnRemoveNoise( wxCommandEvent &event );
153  void OnCancel( wxCommandEvent &event );
154 
155  void OnSensitivityText(wxCommandEvent & event);
156  void OnGainText(wxCommandEvent & event);
157  void OnFreqText(wxCommandEvent & event);
158  void OnTimeText(wxCommandEvent & event);
159  void OnSensitivitySlider(wxCommandEvent & event);
160  void OnGainSlider(wxCommandEvent & event);
161  void OnFreqSlider(wxCommandEvent & event);
162  void OnTimeSlider(wxCommandEvent & event);
163 
164  public:
165 
167 
169  wxButton * m_pButton_Preview;
171 
172  wxRadioButton *mKeepSignal;
173  wxRadioButton *mKeepNoise;
174 
175  wxSlider *mSensitivityS;
176  wxSlider *mGainS;
177  wxSlider *mFreqS;
178  wxSlider *mTimeS;
179 
180  wxTextCtrl *mSensitivityT;
181  wxTextCtrl *mGainT;
182  wxTextCtrl *mFreqT;
183  wxTextCtrl *mTimeT;
184 
185  double mSensitivity;
186  double mGain;
187  double mFreq;
188  double mTime;
189 
191 
192 private:
193  DECLARE_EVENT_TABLE()
194 
195 };
196 
197 #endif
198 
199 #endif
NoiseRemovalDialog::OnKeepNoise
void OnKeepNoise(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:661
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
NoiseRemovalDialog::OnRemoveNoise
void OnRemoveNoise(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:697
EffectNoiseRemoval::mFFTBuffer
Floats mFFTBuffer
Definition: NoiseRemoval.h:105
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
NoiseRemovalDialog::OnSensitivitySlider
void OnSensitivitySlider(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:821
EffectNoiseRemoval::mDoProfile
bool mDoProfile
Definition: NoiseRemoval.h:63
EffectNoiseRemoval::CheckWhetherSkipEffect
bool CheckWhetherSkipEffect() override
Definition: NoiseRemoval.cpp:151
EffectNoiseRemoval::GetType
EffectType GetType() override
Definition: NoiseRemoval.cpp:128
EffectNoiseRemoval::End
void End() override
Definition: NoiseRemoval.cpp:305
Effect.h
EffectNoiseRemoval::mNoiseAttenFactor
float mNoiseAttenFactor
Definition: NoiseRemoval.h:111
EffectNoiseRemoval::mMinSignalTime
float mMinSignalTime
Definition: NoiseRemoval.h:71
EffectNoiseRemoval::mMinSignalBlocks
size_t mMinSignalBlocks
Definition: NoiseRemoval.h:113
NoiseRemovalDialog::TransferDataFromWindow
bool TransferDataFromWindow() override
Definition: NoiseRemoval.cpp:791
NoiseRemovalDialog::mKeepNoise
wxRadioButton * mKeepNoise
Definition: NoiseRemoval.h:173
Effect
Base class for many of the effects in Audacity.
Definition: Effect.h:72
EffectNoiseRemoval::Initialize
void Initialize()
Definition: NoiseRemoval.cpp:263
Envelope
Piecewise linear or piecewise exponential function from double to double.
Definition: Envelope.h:71
EffectNoiseRemoval::EffectNoiseRemoval
EffectNoiseRemoval()
Definition: NoiseRemoval.cpp:83
EffectNoiseRemoval::mWindowSize
size_t mWindowSize
Definition: NoiseRemoval.h:69
NoiseRemovalDialog::MakeNoiseRemovalDialog
wxSizer * MakeNoiseRemovalDialog(bool call_fit=true, bool set_sizer=true)
NoiseRemovalDialog::mFreq
double mFreq
Definition: NoiseRemoval.h:187
EffectNoiseRemoval::ProcessSamples
void ProcessSamples(size_t len, float *buffer)
Definition: NoiseRemoval.cpp:345
EffectNoiseRemoval
A two-pass effect to remove background noise.
Definition: NoiseRemoval.h:35
NoiseRemovalDialog::OnFreqSlider
void OnFreqSlider(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:833
EffectNoiseRemoval::mOutputTrack
std::shared_ptr< WaveTrack > mOutputTrack
Definition: NoiseRemoval.h:99
EffectNoiseRemoval::mOneBlockAttackDecay
float mOneBlockAttackDecay
Definition: NoiseRemoval.h:110
EffectNoiseRemoval::mOutOverlapBuffer
Floats mOutOverlapBuffer
Definition: NoiseRemoval.h:116
EffectNoiseRemoval::GetDescription
TranslatableString GetDescription() override
Definition: NoiseRemoval.cpp:121
EffectNoiseRemoval::mInWaveBuffer
Floats mInWaveBuffer
Definition: NoiseRemoval.h:115
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
EffectNoiseRemoval::mInputPos
int mInputPos
Definition: NoiseRemoval.h:102
NoiseRemovalDialog::OnFreqText
void OnFreqText(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:809
EffectNoiseRemoval::mInSampleCount
sampleCount mInSampleCount
Definition: NoiseRemoval.h:100
NoiseRemovalDialog::OnCancel
void OnCancel(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:703
EffectNoiseRemoval::ProcessOne
bool ProcessOne(int count, WaveTrack *track, sampleCount start, sampleCount len)
Definition: NoiseRemoval.cpp:525
NoiseRemovalDialog::mGainT
wxTextCtrl * mGainT
Definition: NoiseRemoval.h:181
NoiseRemovalDialog::mSensitivityT
wxTextCtrl * mSensitivityT
Definition: NoiseRemoval.h:180
EffectUI.h
EffectNoiseRemoval::mHasProfile
bool mHasProfile
Definition: NoiseRemoval.h:64
factory
static RegisteredToolbarFactory factory
Definition: ControlToolBar.cpp:817
ArraysOf< float >
EffectNoiseRemoval::mFreqSmoothingBins
int mFreqSmoothingBins
Definition: NoiseRemoval.h:108
NoiseRemovalDialog::m_pButton_Preview
wxButton * m_pButton_Preview
Definition: NoiseRemoval.h:169
EffectNoiseRemoval::mbLeaveNoise
bool mbLeaveNoise
Definition: NoiseRemoval.h:83
NoiseRemovalDialog::OnPreview
void OnPreview(wxCommandEvent &event) override
Definition: NoiseRemoval.cpp:666
NoiseRemovalDialog::mTimeS
wxSlider * mTimeS
Definition: NoiseRemoval.h:178
EffectNoiseRemoval::GetProfile
void GetProfile()
Definition: NoiseRemoval.cpp:427
NoiseRemovalDialog::OnTimeSlider
void OnTimeSlider(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:839
NoiseRemovalDialog::mFreqT
wxTextCtrl * mFreqT
Definition: NoiseRemoval.h:182
NoiseRemovalDialog::mSensitivity
double mSensitivity
Definition: NoiseRemoval.h:185
EffectNoiseRemoval::mAttackDecayTime
double mAttackDecayTime
Definition: NoiseRemoval.h:82
EffectNoiseRemoval::mWindow
Floats mWindow
Definition: NoiseRemoval.h:106
EffectNoiseRemoval::mSensitivity
double mSensitivity
Definition: NoiseRemoval.h:79
EffectNoiseRemoval::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: NoiseRemoval.h:37
EffectNoiseRemoval::mNoiseThreshold
Floats mNoiseThreshold
Definition: NoiseRemoval.h:75
EffectNoiseRemoval::RemoveNoise
void RemoveNoise()
Definition: NoiseRemoval.cpp:450
EffectDialog
Definition: EffectUI.h:243
EffectNoiseRemoval::FinishTrack
void FinishTrack()
Definition: NoiseRemoval.cpp:410
NoiseRemovalDialog::m_pButton_GetProfile
wxButton * m_pButton_GetProfile
Definition: NoiseRemoval.h:168
EffectNoiseRemoval::mLevel
int mLevel
Definition: NoiseRemoval.h:65
NoiseRemovalDialog::mGainS
wxSlider * mGainS
Definition: NoiseRemoval.h:176
EffectClientInterface::EffectDialogFactory
std::function< wxDialog *(wxWindow &parent, EffectHostInterface *, EffectUIClientInterface *) > EffectDialogFactory
Definition: EffectInterface.h:190
NoiseRemovalDialog::OnGainSlider
void OnGainSlider(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:827
EffectNoiseRemoval::mOutSampleCount
sampleCount mOutSampleCount
Definition: NoiseRemoval.h:101
NoiseRemovalDialog::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: NoiseRemoval.cpp:708
EffectNoiseRemoval::mGains
ArraysOf< float > mGains
Definition: NoiseRemoval.h:118
EffectNoiseRemoval::mHistoryLen
size_t mHistoryLen
Definition: NoiseRemoval.h:114
EffectNoiseRemoval::Process
bool Process() override
Definition: NoiseRemoval.cpp:206
EffectNoiseRemoval::mImagFFTs
ArraysOf< float > mImagFFTs
Definition: NoiseRemoval.h:120
EffectNoiseRemoval::mAttackDecayBlocks
int mAttackDecayBlocks
Definition: NoiseRemoval.h:109
EffectNoiseRemoval::ApplyFreqSmoothing
void ApplyFreqSmoothing(float *spec)
Definition: NoiseRemoval.cpp:244
EffectNoiseRemoval::mSpectrumSize
size_t mSpectrumSize
Definition: NoiseRemoval.h:70
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
EffectNoiseRemoval::hFFT
HFFT hFFT
Definition: NoiseRemoval.h:104
EffectNoiseRemoval::ShowInterface
bool ShowInterface(wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
Definition: NoiseRemoval.cpp:156
EffectNoiseRemoval::mFreqSmoothingHz
double mFreqSmoothingHz
Definition: NoiseRemoval.h:80
EffectNoiseRemoval::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: NoiseRemoval.cpp:116
EffectNoiseRemoval::StartNewTrack
void StartNewTrack()
Definition: NoiseRemoval.cpp:326
NoiseRemovalDialog::TransferDataToWindow
bool TransferDataToWindow() override
Definition: NoiseRemoval.cpp:774
NoiseRemovalDialog::m_pEffect
EffectNoiseRemoval * m_pEffect
Definition: NoiseRemoval.h:166
HFFT
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:22
NoiseRemovalDialog::mKeepSignal
wxRadioButton * mKeepSignal
Definition: NoiseRemoval.h:172
NoiseRemovalDialog::mTime
double mTime
Definition: NoiseRemoval.h:188
EffectNoiseRemoval::SupportsAutomation
bool SupportsAutomation() override
Definition: NoiseRemoval.cpp:133
NoiseRemovalDialog::mGain
double mGain
Definition: NoiseRemoval.h:186
NoiseRemovalDialog::NoiseRemovalDialog
NoiseRemovalDialog(EffectNoiseRemoval *effect, wxWindow *parent)
Definition: NoiseRemoval.cpp:637
NoiseRemovalDialog::OnTimeText
void OnTimeText(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:815
EffectNoiseRemoval::mNoiseGain
double mNoiseGain
Definition: NoiseRemoval.h:81
EffectNoiseRemoval::mSpectrums
ArraysOf< float > mSpectrums
Definition: NoiseRemoval.h:117
EffectType
EffectType
Definition: EffectInterface.h:55
NoiseRemovalDialog
Dialog used with EffectNoiseRemoval.
Definition: NoiseRemoval.h:134
NoiseRemovalDialog::mSensitivityS
wxSlider * mSensitivityS
Definition: NoiseRemoval.h:175
EffectNoiseRemoval::RotateHistoryWindows
void RotateHistoryWindows()
Definition: NoiseRemoval.cpp:401
NoiseRemovalDialog::OnSensitivityText
void OnSensitivityText(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:797
NoiseRemovalDialog::OnGetProfile
void OnGetProfile(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:656
EffectNoiseRemoval::~EffectNoiseRemoval
virtual ~EffectNoiseRemoval()
Definition: NoiseRemoval.cpp:110
EffectNoiseRemoval::mRealFFTs
ArraysOf< float > mRealFFTs
Definition: NoiseRemoval.h:119
ArrayOf< float >
NoiseRemovalDialog::m_pButton_RemoveNoise
wxButton * m_pButton_RemoveNoise
Definition: NoiseRemoval.h:170
NoiseRemovalDialog::mFreqS
wxSlider * mFreqS
Definition: NoiseRemoval.h:177
EffectNoiseRemoval::FillFirstHistoryWindow
void FillFirstHistoryWindow()
Definition: NoiseRemoval.cpp:372
NoiseRemovalDialog::mTimeT
wxTextCtrl * mTimeT
Definition: NoiseRemoval.h:183
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
NoiseRemovalDialog::mbLeaveNoise
bool mbLeaveNoise
Definition: NoiseRemoval.h:190
EffectNoiseRemoval::Init
bool Init() override
Definition: NoiseRemoval.cpp:141
NoiseRemovalDialog::OnGainText
void OnGainText(wxCommandEvent &event)
Definition: NoiseRemoval.cpp:803
EffectNoiseRemoval::mSensitivityFactor
float mSensitivityFactor
Definition: NoiseRemoval.h:112
EffectNoiseRemoval::mSampleRate
double mSampleRate
Definition: NoiseRemoval.h:68