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 wxString ManualPage ()
 
virtual wxString 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 428 of file NoiseReduction.cpp.

429 : mSettings(std::make_unique<EffectNoiseReduction::Settings>())
430 {
431  Init();
432 }

References Init().

Here is the call graph for this function:

◆ ~EffectNoiseReduction()

EffectNoiseReduction::~EffectNoiseReduction ( )
virtual

Definition at line 434 of file NoiseReduction.cpp.

435 {
436 }

Member Function Documentation

◆ CheckWhetherSkipEffect()

bool EffectNoiseReduction::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 462 of file NoiseReduction.cpp.

463 {
464  return false;
465 }

◆ GetDescription()

TranslatableString EffectNoiseReduction::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 445 of file NoiseReduction.cpp.

446 {
447  return XO("Removes background noise such as fans, tape noise, or hums");
448 }

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectNoiseReduction::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 440 of file NoiseReduction.cpp.

441 {
442  return Symbol;
443 }

References Symbol.

◆ GetType()

EffectType EffectNoiseReduction::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 452 of file NoiseReduction.cpp.

453 {
454  return EffectTypeProcess;
455 }

References EffectTypeProcess.

◆ Init()

bool EffectNoiseReduction::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 457 of file NoiseReduction.cpp.

458 {
459  return true;
460 }

Referenced by EffectNoiseReduction().

Here is the caller graph for this function:

◆ Process()

bool EffectNoiseReduction::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 619 of file NoiseReduction.cpp.

620 {
621  // This same code will either reduce noise or profile it
622 
623  this->CopyInputTracks(); // Set up mOutputTracks.
624 
625  auto track = * (mOutputTracks->Selected< const WaveTrack >()).begin();
626  if (!track)
627  return false;
628 
629  // Initialize statistics if gathering them, or check for mismatched (advanced)
630  // settings if reducing noise.
631  if (mSettings->mDoProfile) {
632  size_t spectrumSize = 1 + mSettings->WindowSize() / 2;
633  mStatistics = std::make_unique<Statistics>
634  (spectrumSize, track->GetRate(), mSettings->mWindowTypes);
635  }
636  else if (mStatistics->mWindowSize != mSettings->WindowSize()) {
637  // possible only with advanced settings
639  XO("You must specify the same window size for steps 1 and 2.") );
640  return false;
641  }
642  else if (mStatistics->mWindowTypes != mSettings->mWindowTypes) {
643  // A warning only
645  XO("Warning: window types are not the same as for profiling.") );
646  }
647 
648  Worker worker(*mSettings, mStatistics->mRate
649 #ifdef EXPERIMENTAL_SPECTRAL_EDITING
650  , mF0, mF1
651 #endif
652  );
653  bool bGoodResult = worker.Process
654  (*this, *mStatistics, *mFactory, *mOutputTracks, mT0, mT1);
655  if (mSettings->mDoProfile) {
656  if (bGoodResult)
657  mSettings->mDoProfile = false; // So that "repeat last effect" will reduce noise
658  else
659  mStatistics.reset(); // So that profiling must be done again before noise reduction
660  }
661  this->ReplaceProcessedTracks(bGoodResult);
662  return bGoodResult;
663 }

References Effect::CopyInputTracks(), Effect::MessageBox(), Effect::mFactory, Effect::mOutputTracks, mSettings, mStatistics, Effect::mT0, Effect::mT1, EffectNoiseReduction::Worker::Process(), Effect::ReplaceProcessedTracks(), 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 467 of file NoiseReduction.cpp.

469 {
470  // to do: use forceModal correctly
471 
472  // Doesn't use the factory but substitutes its own dialog
473 
474  // We may want to twiddle the levels if we are setting
475  // from an automation dialog
476  return mSettings->PromptUser(this, parent,
477  bool(mStatistics), forceModal);
478 }

References mSettings, and mStatistics.

◆ TrackProgress()

bool Effect::TrackProgress

Definition at line 338 of file Effect.cpp.

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

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

Referenced by EffectNoiseReduction::Worker::ProcessOne().

Here is the call graph for this function:
Here is the caller 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

Definition at line 56 of file NoiseReduction.h.

Referenced by Process(), and ShowInterface().

◆ 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:523
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:68
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
Effect::mProgress
ProgressDialog * mProgress
Definition: Effect.h:456
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:2478
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:2070
Effect::mT1
double mT1
Definition: Effect.h:466
XO
#define XO(s)
Definition: Internat.h:32
Effect::mFactory
WaveTrackFactory * mFactory
Definition: Effect.h:461
Effect::mT0
double mT0
Definition: Effect.h:465
ProgressResult::Success
@ Success
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2192
ProgressDialog::Update
ProgressResult Update(int value, const TranslatableString &message={})
Definition: ProgressDialog.cpp:1327
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:464
EffectNoiseReduction::mSettings
std::unique_ptr< Settings > mSettings
Definition: NoiseReduction.h:55
EffectNoiseReduction::mStatistics
std::unique_ptr< Statistics > mStatistics
Definition: NoiseReduction.h:56
EffectNoiseReduction::Init
bool Init() override
Definition: NoiseReduction.cpp:457