44#if !defined(EXPERIMENTAL_NOISE_REDUCTION)
48#include "../WaveTrack.h"
51#include "../ShuttleGui.h"
55#if defined(__WXMSW__) && !defined(__CYGWIN__)
57#define finite(x) _finite(x)
66#include <wx/radiobut.h>
67#include <wx/statbox.h>
68#include <wx/stattext.h>
69#include <wx/textctrl.h>
70#include <wx/valtext.h>
76{
XO(
"Noise Removal") };
85 gPrefs->Read(
wxT(
"/Effects/NoiseRemoval/NoiseSensitivity"),
87 gPrefs->Read(
wxT(
"/Effects/NoiseRemoval/NoiseGain"),
89 gPrefs->Read(
wxT(
"/Effects/NoiseRemoval/NoiseFreqSmoothing"),
91 gPrefs->Read(
wxT(
"/Effects/NoiseRemoval/NoiseAttackDecayTime"),
93 gPrefs->Read(
wxT(
"/Effects/NoiseRemoval/NoiseLeaveNoise"),
120 return XO(
"Removes constant background noise such as fans, tape noise, or hums");
137#define MAX_NOISE_LEVEL 30
166 if (pInstance && !pInstance->Init())
181 bool bAllowTwiddleSettings = forceModal;
193 dlog.CentreOnParent();
196 const auto returnCode = dlog.GetReturnCode();
225 bool bGoodResult =
true;
229 double trackStart = track->GetStartTime();
230 double trackEnd = track->GetEndTime();
231 double t0 =
mT0 < trackStart? trackStart:
mT0;
232 double t1 =
mT1 > trackEnd? trackEnd:
mT1;
235 auto start = track->TimeToLongSamples(t0);
236 auto end = track->TimeToLongSamples(t1);
237 auto len =
end - start;
265 for(j = j0; j <= j1; j++) {
268 tmp[i] /= (j1 - j0 + 1);
361 for(
size_t i = 0; i < avail; i++)
405 Floats temp = std::move( arrays[ historyLen - 1 ] );
407 for (
size_t nn = historyLen - 1; nn--; )
408 arrays[ nn + 1 ] = std::move( arrays[ nn ] );
409 arrays[0] = std::move( temp );
451 for (i = start+1; i < finish; i++) {
471 for (
size_t i = start+1; i < finish; i++) {
477 else mGains[center][j] = 1.0;
487 for (
size_t i = center + 1; i <
mHistoryLen; i++) {
493 for (
size_t i = center; i--;) {
549 Floats buffer{ bufferSize };
551 bool bLoopSuccess =
true;
552 auto samplePos = start;
553 while (samplePos < start + len) {
558 start + len - samplePos
567 samplePos += blockSize;
571 bLoopSuccess =
false;
619#define SENSITIVITY_MIN 0
620#define SENSITIVITY_MAX 4000
657 m_pButton_GetProfile = NULL;
658 m_pButton_Preview = NULL;
659 m_pButton_RemoveNoise = NULL;
665 m_pButton_RemoveNoise =
666 (wxButton *)wxWindow::FindWindowById(wxID_OK,
this);
698 auto cleanup =
finally( [&] {
723 S.StartStatic(
XO(
"Step 1"));
725 S.AddVariableText(
XO(
726"Select a few seconds of just noise so Audacity knows what to filter out,\nthen click Get Noise Profile:"));
731 S.StartStatic(
XO(
"Step 2"));
733 S.AddVariableText(
XO(
734"Select all of the audio you want filtered, choose how much noise you want\nfiltered out, and then click 'OK' to remove noise.\n"));
736 S.StartMultiColumn(3, wxEXPAND);
740 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
741 .AddTextBox(
XXO(
"Noise re&duction (dB):"),
wxT(
""), 0);
744 .Name(
XO(
"Noise reduction"))
745 .Style(wxSL_HORIZONTAL)
746 .MinSize( { 150, -1 } )
750 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
751 .AddTextBox(
XXO(
"&Sensitivity (dB):"),
wxT(
""), 0);
753 .Name(
XO(
"Sensitivity"))
754 .Style(wxSL_HORIZONTAL)
755 .MinSize( { 150, -1 } )
759 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
760 .AddTextBox(
XXO(
"Fr&equency smoothing (Hz):"),
wxT(
""), 0);
762 .Name(
XO(
"Frequency smoothing"))
763 .Style(wxSL_HORIZONTAL)
764 .MinSize( { 150, -1 } )
768 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
769 .AddTextBox(
XXO(
"Attac&k/decay time (secs):"),
wxT(
""), 0);
771 .Name(
XO(
"Attack/decay time"))
772 .Style(wxSL_HORIZONTAL)
773 .MinSize( { 150, -1 } )
776 S.AddPrompt(
XXO(
"Noise:"));
778 .AddRadioButton(
XXO(
"Re&move"));
780 .AddRadioButtonToGroup(
XXO(
"&Isolate"));
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
#define ID_EFFECT_PREVIEW
std::function< DialogFactoryResults(wxWindow &parent, EffectPlugin &, EffectUIClientInterface &, EffectSettingsAccess &) > EffectDialogFactory
Type of function that creates a dialog for an effect.
XXO("&Cut/Copy/Paste Toolbar")
@ ID_RADIOBUTTON_KEEPSIGNAL
@ ID_RADIOBUTTON_KEEPNOISE
void RealFFTf(fft_type *buffer, const FFTParam *h)
void InverseRealFFTf(fft_type *buffer, const FFTParam *h)
HFFT GetFFT(size_t fftlen)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
void reinit(Integral count, bool initialize=false)
void reinit(Integral count)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
std::shared_ptr< TrackList > mOutputTracks
void ReplaceProcessedTracks(const bool bGoodResult)
void Preview(EffectSettingsAccess &access, bool dryOnly) override
void CopyInputTracks(bool allSyncLockSelected=false)
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
int GetNumWaveTracks() const
Performs effect computation.
A two-pass effect to remove background noise.
void RotateHistoryWindows()
static const ComponentInterfaceSymbol Symbol
ComponentInterfaceSymbol GetSymbol() override
bool SupportsAutomation() const override
Whether the effect has any automatable controls.
void FillFirstHistoryWindow()
ArraysOf< float > mImagFFTs
void ProcessSamples(size_t len, float *buffer)
std::shared_ptr< WaveTrack > mOutputTrack
int ShowHostInterface(wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
ArraysOf< float > mRealFFTs
void ApplyFreqSmoothing(float *spec)
EffectType GetType() const override
Type determines how it behaves.
bool ProcessOne(int count, WaveTrack *track, sampleCount start, sampleCount len)
sampleCount mOutSampleCount
TranslatableString GetDescription() override
bool Process(EffectInstance &instance, EffectSettings &settings) override
ArraysOf< float > mSpectrums
bool CheckWhetherSkipEffect(const EffectSettings &settings) const override
Default implementation returns false.
float mOneBlockAttackDecay
virtual ~EffectNoiseRemoval()
sampleCount mInSampleCount
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Dialog used with EffectNoiseRemoval.
void OnFreqText(wxCommandEvent &event)
wxButton * m_pButton_RemoveNoise
void OnPreview(wxCommandEvent &event) override
void OnFreqSlider(wxCommandEvent &event)
void PopulateOrExchange(ShuttleGui &S) override
void OnCancel(wxCommandEvent &event)
EffectSettingsAccess & mAccess
void OnRemoveNoise(wxCommandEvent &event)
wxTextCtrl * mSensitivityT
wxButton * m_pButton_Preview
wxRadioButton * mKeepNoise
wxButton * m_pButton_GetProfile
void OnGainText(wxCommandEvent &event)
bool TransferDataFromWindow() override
void OnTimeSlider(wxCommandEvent &event)
void OnGainSlider(wxCommandEvent &event)
EffectNoiseRemoval * m_pEffect
void OnGetProfile(wxCommandEvent &event)
void OnKeepNoise(wxCommandEvent &event)
void OnSensitivityText(wxCommandEvent &event)
void OnSensitivitySlider(wxCommandEvent &event)
void OnTimeText(wxCommandEvent &event)
wxRadioButton * mKeepSignal
bool TransferDataToWindow() override
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
std::shared_ptr< EffectInstance > MakeInstance() const override
Make an object maintaining short-term state of an Effect.
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const override
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
void ClearAndPaste(double t0, double t1, const Track *src, bool preserve=true, bool merge=true, const TimeWarper *effectWarper=NULL)
Holder EmptyCopy(const SampleBlockFactoryPtr &pFactory={}, bool keepLink=true) const
Positions or offsets within audio files need a wide type.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
void Rotate(ArraysOf< float > &arrays, size_t historyLen)
BuiltinEffectsModule::Registration< EffectNoiseRemoval > reg
Externalized state of a plug-in.