Audacity  3.0.3
Classes | Public Member Functions | Static Public Attributes | Private Attributes | Friends | List of all members
EffectNoiseReduction Class Referencefinal

A two-pass effect to reduce background noise. More...

#include <NoiseReduction.h>

Inheritance diagram for EffectNoiseReduction:
[legend]
Collaboration diagram for EffectNoiseReduction:
[legend]

Classes

class  Dialog
 Dialog used with EffectNoiseReduction. More...
 
class  Settings
 
class  Statistics
 
class  Worker
 

Public Member Functions

 EffectNoiseReduction ()
 
virtual ~EffectNoiseReduction ()
 
ComponentInterfaceSymbol GetSymbol () override
 
TranslatableString GetDescription () override
 
EffectType GetType () override
 
bool ShowInterface (wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
 
bool Init () override
 
bool CheckWhetherSkipEffect () override
 
bool Process () override
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={})
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () override
 
VendorSymbol GetVendor () override
 
wxString GetVersion () override
 
EffectFamilySymbol GetFamily () override
 
bool IsInteractive () override
 
bool IsDefault () override
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 
bool SupportsAutomation () override
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
bool IsReady () override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 
bool ProcessFinalize () override
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool LoadUserPreset (const RegistryPath &name) override
 
bool SaveUserPreset (const RegistryPath &name) override
 
RegistryPaths GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (ShuttleGui &S) final
 
bool IsGraphicalUI () override
 
bool ValidateUI () override
 
bool HideUI () override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets () override
 
void ImportPresets () override
 
bool HasOptions () override
 
void ShowOptions () override
 
double GetDefaultDuration () override
 
double GetDuration () override
 
NumericFormatSymbol GetDurationFormat () override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
void SetDuration (double duration) override
 
RegistryPath GetUserPresetsGroup (const RegistryPath &name) override
 
RegistryPath GetCurrentSettingsGroup () override
 
RegistryPath GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const RegistryPath &group) override
 
bool GetSharedConfigSubgroups (const RegistryPath &group, RegistryPaths &subgroups) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetSharedConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const RegistryPath &group) override
 
bool RemoveSharedConfig (const RegistryPath &group, const RegistryPath &key) override
 
bool HasPrivateConfigGroup (const RegistryPath &group) override
 
bool GetPrivateConfigSubgroups (const RegistryPath &group, RegistryPaths &paths) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, wxString &value, const wxString &defval={}) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const RegistryPath &group, const RegistryPath &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const wxString &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const int &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const bool &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const float &value) override
 
bool SetPrivateConfig (const RegistryPath &group, const RegistryPath &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const RegistryPath &group) override
 
bool RemovePrivateConfig (const RegistryPath &group, const RegistryPath &key) override
 
virtual PluginID GetID ()
 
virtual bool Startup (EffectClientInterface *client)
 
virtual bool Startup ()
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
virtual RegistryPaths GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual ManualPageID ManualPage ()
 
virtual FilePath HelpPage ()
 
virtual void SetUIFlags (unsigned flags)
 
virtual unsigned TestUIFlags (unsigned mask)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
virtual bool IsHidden ()
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 
- Public Member Functions inherited from ConfigClientInterface
virtual ~ConfigClientInterface ()
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Noise Reduction") }
 
- Static Public Attributes inherited from Effect
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 

Private Attributes

std::unique_ptr< SettingsmSettings
 
std::unique_ptr< StatisticsmStatistics
 

Friends

class Dialog
 

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
using VetoDialogHook = bool(*)(wxDialog *)
 
- Public Types inherited from EffectClientInterface
using EffectDialogFactory = std::function< wxDialog *(wxWindow &parent, EffectHostInterface *, EffectUIClientInterface *) >
 
- Static Public Member Functions inherited from Effect
static VetoDialogHook SetVetoDialogHook (VetoDialogHook hook)
 
static CommandID GetSquashedName (wxString name)
 
static void IncEffectCounter ()
 
- Protected Member Functions inherited from Effect
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual int GetPass ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual void PopulateOrExchange (ShuttleGui &S)
 
virtual bool TransferDataToWindow ()
 
virtual bool TransferDataFromWindow ()
 
virtual bool EnableApply (bool enable=true)
 
virtual bool EnablePreview (bool enable=true)
 
virtual void EnableDebug (bool enable=true)
 
bool TotalProgress (double frac, const TranslatableString &={})
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={})
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={})
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
wxWeakRef< NotifyingSelectedRegionmpSelectedRegion {}
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
unsigned mUIFlags
 
sampleCount mSampleCnt
 
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0
 

Detailed Description

A two-pass effect to reduce background noise.

The first pass is done over just noise. For each windowed sample of the sound, we take a FFT and then statistics are tabulated for each frequency band.

During the noise reduction phase, we start by setting a gain control for each frequency band such that if the sound has exceeded the previously-determined threshold, the gain is set to 0 dB, otherwise the gain is set lower (e.g. -18 dB), to suppress the noise. Then time-smoothing is applied so that the gain for each frequency band moves slowly, and then frequency-smoothing is applied so that a single frequency is never suppressed or boosted in isolation. Lookahead is employed; this effect is not designed for real-time but if it were, there would be a significant delay.

The gain controls are applied to the complex FFT of the signal, and then the inverse FFT is applied. A Hann window may be applied (depending on the advanced window types setting), and then the output signal is then pieced together using overlap/add.

Definition at line 18 of file NoiseReduction.h.

Constructor & Destructor Documentation

◆ EffectNoiseReduction()

EffectNoiseReduction::EffectNoiseReduction ( )

Definition at line 410 of file NoiseReduction.cpp.

411 : mSettings(std::make_unique<EffectNoiseReduction::Settings>())
412 {
413  Init();
414 }

References Init().

Here is the call graph for this function:

◆ ~EffectNoiseReduction()

EffectNoiseReduction::~EffectNoiseReduction ( )
virtual

Definition at line 416 of file NoiseReduction.cpp.

417 {
418 }

Member Function Documentation

◆ CheckWhetherSkipEffect()

bool EffectNoiseReduction::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 444 of file NoiseReduction.cpp.

445 {
446  return false;
447 }

◆ GetDescription()

TranslatableString EffectNoiseReduction::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 427 of file NoiseReduction.cpp.

428 {
429  return XO("Removes background noise such as fans, tape noise, or hums");
430 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectNoiseReduction::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 422 of file NoiseReduction.cpp.

423 {
424  return Symbol;
425 }

References Symbol.

◆ GetType()

EffectType EffectNoiseReduction::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 434 of file NoiseReduction.cpp.

435 {
436  return EffectTypeProcess;
437 }

References EffectTypeProcess.

◆ Init()

bool EffectNoiseReduction::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 439 of file NoiseReduction.cpp.

440 {
441  return true;
442 }

Referenced by EffectNoiseReduction().

Here is the caller graph for this function:

◆ Process()

bool EffectNoiseReduction::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 616 of file NoiseReduction.cpp.

617 {
618  // This same code will either reduce noise or profile it
619 
620  this->CopyInputTracks(); // Set up mOutputTracks.
621 
622  auto track = * (mOutputTracks->Selected< const WaveTrack >()).begin();
623  if (!track)
624  return false;
625 
626  // Initialize statistics if gathering them, or check for mismatched (advanced)
627  // settings if reducing noise.
628  if (mSettings->mDoProfile) {
629  size_t spectrumSize = 1 + mSettings->WindowSize() / 2;
630  mStatistics = std::make_unique<Statistics>
631  (spectrumSize, track->GetRate(), mSettings->mWindowTypes);
632  }
633  else if (mStatistics->mWindowSize != mSettings->WindowSize()) {
634  // possible only with advanced settings
636  XO("You must specify the same window size for steps 1 and 2.") );
637  return false;
638  }
639  else if (mStatistics->mWindowTypes != mSettings->mWindowTypes) {
640  // A warning only
642  XO("Warning: window types are not the same as for profiling.") );
643  }
644 
645  eWindowFunctions inWindowType, outWindowType;
646  switch (mSettings->mWindowTypes) {
647  case WT_RECTANGULAR_HANN:
648  inWindowType = eWinFuncRectangular;
649  outWindowType = eWinFuncHann;
650  break;
651  case WT_HANN_RECTANGULAR:
652  inWindowType = eWinFuncHann;
653  outWindowType = eWinFuncRectangular;
654  break;
655  case WT_BLACKMAN_HANN:
656  inWindowType = eWinFuncBlackman;
657  outWindowType = eWinFuncHann;
658  break;
660  inWindowType = eWinFuncHamming;
661  outWindowType = eWinFuncRectangular;
662  break;
663  case WT_HAMMING_HANN:
664  inWindowType = eWinFuncHamming;
665  outWindowType = eWinFuncHann;
666  break;
667  default:
668  wxASSERT(false);
669  [[fallthrough]] ;
670  case WT_HANN_HANN:
671  inWindowType = outWindowType = eWinFuncHann;
672  break;
673  }
674  Worker worker{ inWindowType, outWindowType,
675  *this, *mSettings, *mStatistics
676 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
677  , mF0, mF1
678 #endif
679  };
680  bool bGoodResult = worker.Process(*mOutputTracks, mT0, mT1);
681  if (mSettings->mDoProfile) {
682  if (bGoodResult)
683  mSettings->mDoProfile = false; // So that "repeat last effect" will reduce noise
684  else
685  mStatistics.reset(); // So that profiling must be done again before noise reduction
686  }
687  this->ReplaceProcessedTracks(bGoodResult);
688  return bGoodResult;
689 }

References Effect::CopyInputTracks(), eWinFuncBlackman, eWinFuncHamming, eWinFuncHann, eWinFuncRectangular, Effect::MessageBox(), Effect::mOutputTracks, mSettings, mStatistics, Effect::mT0, Effect::mT1, Effect::ReplaceProcessedTracks(), anonymous_namespace{NoiseReduction.cpp}::WT_BLACKMAN_HANN, anonymous_namespace{NoiseReduction.cpp}::WT_HAMMING_HANN, anonymous_namespace{NoiseReduction.cpp}::WT_HAMMING_RECTANGULAR, anonymous_namespace{NoiseReduction.cpp}::WT_HANN_HANN, anonymous_namespace{NoiseReduction.cpp}::WT_HANN_RECTANGULAR, anonymous_namespace{NoiseReduction.cpp}::WT_RECTANGULAR_HANN, and XO.

Here is the call graph for this function:

◆ ShowInterface()

bool EffectNoiseReduction::ShowInterface ( wxWindow &  parent,
const EffectDialogFactory factory,
bool  forceModal = false 
)
overridevirtual

Reimplemented from Effect.

Definition at line 449 of file NoiseReduction.cpp.

451 {
452  // to do: use forceModal correctly
453 
454  // Doesn't use the factory but substitutes its own dialog
455 
456  // We may want to twiddle the levels if we are setting
457  // from an automation dialog
458  return mSettings->PromptUser(this, parent,
459  bool(mStatistics), forceModal);
460 }

References mSettings, and mStatistics.

◆ TrackProgress()

bool Effect::TrackProgress

Definition at line 339 of file Effect.cpp.

2026 {
2027  auto updateResult = (mProgress ?
2028  mProgress->Update(whichTrack + frac, (double) mNumTracks, msg) :
2030  return (updateResult != ProgressResult::Success);
2031 }

References EffectClientInterface::GetLatency(), and Effect::mClient.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ Dialog

friend class Dialog
friend

Definition at line 53 of file NoiseReduction.h.

Member Data Documentation

◆ mSettings

std::unique_ptr<Settings> EffectNoiseReduction::mSettings
private

Definition at line 55 of file NoiseReduction.h.

Referenced by Process(), and ShowInterface().

◆ mStatistics

std::unique_ptr<Statistics> EffectNoiseReduction::mStatistics
private

◆ Symbol

const ComponentInterfaceSymbol EffectNoiseReduction::Symbol { XO("Noise Reduction") }
static

Definition at line 20 of file NoiseReduction.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files:
Effect::mNumTracks
int mNumTracks
Definition: Effect.h:524
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
BasicUI::ProgressResult::Success
@ Success
Effect::mProgress
ProgressDialog * mProgress
Definition: Effect.h:457
anonymous_namespace{NoiseReduction.cpp}::WT_HAMMING_HANN
@ WT_HAMMING_HANN
Definition: NoiseReduction.cpp:124
eWinFuncBlackman
@ eWinFuncBlackman
Definition: FFT.h:115
EffectNoiseReduction::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: NoiseReduction.h:20
Effect::MessageBox
int MessageBox(const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
Definition: Effect.cpp:2482
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:2071
eWinFuncRectangular
@ eWinFuncRectangular
Definition: FFT.h:111
Effect::mT1
double mT1
Definition: Effect.h:467
eWindowFunctions
eWindowFunctions
Definition: FFT.h:110
XO
#define XO(s)
Definition: Internat.h:31
eWinFuncHamming
@ eWinFuncHamming
Definition: FFT.h:113
Effect::mT0
double mT0
Definition: Effect.h:466
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2193
eWinFuncHann
@ eWinFuncHann
Definition: FFT.h:114
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:465
anonymous_namespace{NoiseReduction.cpp}::WT_HAMMING_RECTANGULAR
@ WT_HAMMING_RECTANGULAR
Definition: NoiseReduction.cpp:123
anonymous_namespace{NoiseReduction.cpp}::WT_RECTANGULAR_HANN
@ WT_RECTANGULAR_HANN
Definition: NoiseReduction.cpp:119
anonymous_namespace{NoiseReduction.cpp}::WT_HANN_HANN
@ WT_HANN_HANN
Definition: NoiseReduction.cpp:121
anonymous_namespace{NoiseReduction.cpp}::WT_HANN_RECTANGULAR
@ WT_HANN_RECTANGULAR
Definition: NoiseReduction.cpp:120
EffectNoiseReduction::mSettings
std::unique_ptr< Settings > mSettings
Definition: NoiseReduction.h:55
anonymous_namespace{NoiseReduction.cpp}::WT_BLACKMAN_HANN
@ WT_BLACKMAN_HANN
Definition: NoiseReduction.cpp:122
EffectNoiseReduction::mStatistics
std::unique_ptr< Statistics > mStatistics
Definition: NoiseReduction.h:56
EffectNoiseReduction::Init
bool Init() override
Definition: NoiseReduction.cpp:439