Audacity  3.2.0
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
 Type determines how it behaves. More...
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
 An override still here for historical reasons, ignoring the factory. More...
 
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
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () override
 Whether the effect sorts "above the line" in the menus. More...
 
bool IsLegacy () override
 
bool SupportsRealtime () override
 Whether the effect supports realtime previewing (while audio is playing). More...
 
bool SupportsAutomation () override
 Whether the effect can be used without the UI, in a macro. More...
 
bool GetAutomationParameters (CommandParameters &parms) override
 Save current settings into parms. More...
 
bool SetAutomationParameters (CommandParameters &parms) override
 Change settings to those stored in parms. More...
 
bool LoadUserPreset (const RegistryPath &name) override
 Change settings to a user-named preset. More...
 
bool SaveUserPreset (const RegistryPath &name) override
 Save current settings as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () override
 Report names of factory presets. More...
 
bool LoadFactoryPreset (int id) override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
 
bool LoadFactoryDefaults () override
 Change settings back to "factory default". More...
 
bool SetHost (EffectHostInterface *host) override
 
unsigned GetAudioInCount () override
 
unsigned GetAudioOutCount () override
 
int GetMidiInCount () override
 
int GetMidiOutCount () override
 
sampleCount GetLatency () override
 Called for destructive, non-realtime effect computation. More...
 
size_t GetTailSize () override
 
void SetSampleRate (double rate) override
 
size_t SetBlockSize (size_t maxBlockSize) override
 
size_t GetBlockSize () const override
 
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 Called for destructive, non-realtime effect computation. More...
 
bool ProcessFinalize () override
 Called for destructive, non-realtime effect computation. More...
 
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 Called for destructive, non-realtime effect computation. More...
 
bool RealtimeInitialize () override
 
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
 
bool RealtimeFinalize () override
 
bool RealtimeSuspend () override
 
bool RealtimeResume () noexcept override
 
bool RealtimeProcessStart () override
 
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
 
bool RealtimeProcessEnd () noexcept override
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
 
bool PopulateUI (ShuttleGui &S) final
 Adds controls to a panel that is given as the parent window of S More...
 
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
 
EffectDefinitionInterfaceGetDefinition () 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 ()
 
unsigned TestUIFlags (unsigned mask)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
virtual bool Startup (EffectUIClientInterface *client)
 
virtual bool GetAutomationParametersAsString (wxString &parms)
 
virtual bool SetAutomationParametersFromString (const wxString &parms)
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
 
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
virtual bool Startup ()
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
- Public Member Functions inherited from EffectProcessor
virtual ~EffectProcessor ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetClassification ()
 Determines which menu it appears in; default same as GetType(). More...
 
virtual bool EnablesDebug ()
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage ()
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage ()
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus ()
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
TranslatableString GetName ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 
- Public Member Functions inherited from EffectUIHostInterface
virtual ~EffectUIHostInterface ()
 
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()
 

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 }
 
- Static Public Member Functions inherited from Effect
static void IncEffectCounter ()
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Protected Member Functions inherited from Effect
bool EnableApply (bool enable=true)
 
bool EnablePreview (bool enable=true)
 
virtual bool ProcessPass ()
 
virtual bool InitPass1 ()
 
virtual bool InitPass2 ()
 
virtual void End ()
 
virtual double CalcPreviewInputLength (double previewLength)
 
virtual void Preview (bool dryOnly)
 
virtual void PopulateOrExchange (ShuttleGui &S)
 
virtual bool TransferDataToWindow ()
 
virtual bool TransferDataFromWindow ()
 
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
BasicUI::ProgressDialogmProgress = nullptr
 
double mProjectRate
 
double mSampleRate
 
WaveTrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWeakRef< wxDialog > mUIDialog
 This weak pointer may be the same as the above, or null. More...
 
wxWindow * mUIParent
 
unsigned mUIFlags { 0 }
 
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

Type determines how it behaves.

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

If Process() is not overridden, it uses ProcessInitialize(), ProcessBlock(), and ProcessFinalize() methods of EffectProcessor, and also GetLatency() to determine how many leading output samples to discard and how many extra samples to produce.

Reimplemented from Effect.

Definition at line 624 of file NoiseReduction.cpp.

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

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:

◆ ShowHostInterface()

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

An override still here for historical reasons, ignoring the factory.

We would like to make this effect behave more like others, but it does have its unusual two-pass nature. First choose and analyze an example of noise, then apply noise reduction to another selection. That is difficult to fit into the framework for managing settings of other effects.

Reimplemented from Effect.

Definition at line 454 of file NoiseReduction.cpp.

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

References mSettings, and mStatistics.

◆ TrackProgress()

bool Effect::TrackProgress

Definition at line 298 of file Effect.cpp.

1789 {
1790  auto updateResult = (mProgress ?
1791  mProgress->Poll(whichTrack + frac, (double) mNumTracks, msg) :
1793  return (updateResult != ProgressResult::Success);
1794 }

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 ShowHostInterface().

◆ 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:483
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:56
BasicUI::ProgressResult::Success
@ Success
BasicUI::ProgressDialog::Poll
virtual ProgressResult Poll(unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
Update the bar and poll for clicks. Call only on the main thread.
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:2238
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:1834
eWinFuncRectangular
@ eWinFuncRectangular
Definition: FFT.h:111
Effect::mT1
double mT1
Definition: Effect.h:424
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:423
Effect::mProgress
BasicUI::ProgressDialog * mProgress
Definition: Effect.h:415
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:1956
eWinFuncHann
@ eWinFuncHann
Definition: FFT.h:114
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:422
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