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>
70#include <wx/statbox.h>
71#include <wx/stattext.h>
72#include <wx/textctrl.h>
73#include <wx/valtext.h>
79{
XO(
"Noise Removal") };
88 gPrefs->Read(wxT(
"/Effects/NoiseRemoval/NoiseSensitivity"),
90 gPrefs->Read(wxT(
"/Effects/NoiseRemoval/NoiseGain"),
92 gPrefs->Read(wxT(
"/Effects/NoiseRemoval/NoiseFreqSmoothing"),
94 gPrefs->Read(wxT(
"/Effects/NoiseRemoval/NoiseAttackDecayTime"),
96 gPrefs->Read(wxT(
"/Effects/NoiseRemoval/NoiseLeaveNoise"),
123 return XO(
"Removes constant background noise such as fans, tape noise, or hums");
140#define MAX_NOISE_LEVEL 30
143 mLevel =
gPrefs->Read(wxT(
"/Effects/NoiseRemoval/Noise_Level"), 3L);
146 gPrefs->Write(wxT(
"/Effects/NoiseRemoval/Noise_Level"),
mLevel);
169 if (pInstance && !pInstance->Init())
184 bool bAllowTwiddleSettings = forceModal;
196 dlog.CentreOnParent();
199 const auto returnCode = dlog.GetReturnCode();
228 bool bGoodResult =
true;
232 double trackStart = track->GetStartTime();
233 double trackEnd = track->GetEndTime();
234 double t0 =
mT0 < trackStart? trackStart:
mT0;
235 double t1 =
mT1 > trackEnd? trackEnd:
mT1;
238 auto start = track->TimeToLongSamples(t0);
239 auto end = track->TimeToLongSamples(t1);
240 auto len =
end - start;
268 for(j = j0; j <= j1; j++) {
271 tmp[i] /= (j1 - j0 + 1);
364 for(
size_t i = 0; i < avail; i++)
408 Floats temp = std::move( arrays[ historyLen - 1 ] );
410 for (
size_t nn = historyLen - 1; nn--; )
411 arrays[ nn + 1 ] = std::move( arrays[ nn ] );
412 arrays[0] = std::move( temp );
454 for (i = start+1; i < finish; i++) {
474 for (
size_t i = start+1; i < finish; i++) {
480 else mGains[center][j] = 1.0;
490 for (
size_t i = center + 1; i <
mHistoryLen; i++) {
496 for (
size_t i = center; i--;) {
552 Floats buffer{ bufferSize };
554 bool bLoopSuccess =
true;
555 auto samplePos = start;
556 while (samplePos < start + len) {
561 start + len - samplePos
570 samplePos += blockSize;
574 bLoopSuccess =
false;
622#define SENSITIVITY_MIN 0
623#define SENSITIVITY_MAX 4000
660 m_pButton_GetProfile = NULL;
661 m_pButton_Preview = NULL;
662 m_pButton_RemoveNoise = NULL;
668 m_pButton_RemoveNoise =
669 (wxButton *)wxWindow::FindWindowById(wxID_OK,
this);
701 auto cleanup =
finally( [&] {
726 S.StartStatic(
XO(
"Step 1"));
728 S.AddVariableText(
XO(
729"Select a few seconds of just noise so Audacity knows what to filter out,\nthen click Get Noise Profile:"));
734 S.StartStatic(
XO(
"Step 2"));
736 S.AddVariableText(
XO(
737"Select all of the audio you want filtered, choose how much noise you want\nfiltered out, and then click 'OK' to remove noise.\n"));
739 S.StartMultiColumn(3, wxEXPAND);
743 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
744 .AddTextBox(
XXO(
"Noise re&duction (dB):"), wxT(
""), 0);
747 .Name(
XO(
"Noise reduction"))
748 .Style(wxSL_HORIZONTAL)
749 .MinSize( { 150, -1 } )
753 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
754 .AddTextBox(
XXO(
"&Sensitivity (dB):"), wxT(
""), 0);
756 .Name(
XO(
"Sensitivity"))
757 .Style(wxSL_HORIZONTAL)
758 .MinSize( { 150, -1 } )
762 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
763 .AddTextBox(
XXO(
"Fr&equency smoothing (Hz):"), wxT(
""), 0);
765 .Name(
XO(
"Frequency smoothing"))
766 .Style(wxSL_HORIZONTAL)
767 .MinSize( { 150, -1 } )
771 .Validator<wxTextValidator>(wxFILTER_NUMERIC)
772 .AddTextBox(
XXO(
"Attac&k/decay time (secs):"), wxT(
""), 0);
774 .Name(
XO(
"Attack/decay time"))
775 .Style(wxSL_HORIZONTAL)
776 .MinSize( { 150, -1 } )
779 S.AddPrompt(
XXO(
"Noise:"));
781 .AddRadioButton(
XXO(
"Re&move"));
783 .AddRadioButtonToGroup(
XXO(
"&Isolate"));
793 mGainT->SetValue(wxString::Format(wxT(
"%d"), (
int)
mGain));
794 mFreqT->SetValue(wxString::Format(wxT(
"%d"), (
int)
mFreq));
795 mTimeT->SetValue(wxString::Format(wxT(
"%.2f"),
mTime));
846 mGainT->SetValue(wxString::Format(wxT(
"%d"), (
int)
mGain));
852 mFreqT->SetValue(wxString::Format(wxT(
"%d"), (
int)
mFreq));
858 mTimeT->SetValue(wxString::Format(wxT(
"%.2f"),
mTime));
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
#define ID_EFFECT_PREVIEW
std::function< wxDialog *(wxWindow &parent, EffectPlugin &, EffectUIClientInterface &, std::shared_ptr< EffectInstance > &, EffectSettingsAccess &) > EffectDialogFactory
Type of function that creates a dialog for an effect.
@ 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.
bool Init() override
Call once to set up state for whole list of tracks to be processed.
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
Actually do the effect here.
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.