Audacity  2.2.2
Classes | Public Member Functions | 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:
Effect EffectClientInterface EffectUIClientInterface EffectHostInterface EffectDefinitionInterface ConfigClientInterface IdentInterface ParamsInterface

Classes

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

Public Member Functions

 EffectNoiseReduction ()
 
virtual ~EffectNoiseReduction ()
 
IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
EffectType GetType () override
 
bool PromptUser (wxWindow *parent) override
 
bool Init () override
 
bool CheckWhetherSkipEffect () override
 
bool Process () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
IdentInterfaceSymbol GetFamilyId () 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
 
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 ShowInterface (wxWindow *parent, bool forceModal=false) override
 
bool GetAutomationParameters (CommandParameters &parms) override
 
bool SetAutomationParameters (CommandParameters &parms) override
 
bool LoadUserPreset (const wxString &name) override
 
bool SaveUserPreset (const wxString &name) override
 
wxArrayString GetFactoryPresets () override
 
bool LoadFactoryPreset (int id) override
 
bool LoadFactoryDefaults () override
 
void SetHostUI (EffectUIHostInterface *host) override
 
bool PopulateUI (wxWindow *parent) override
 
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
 
NumericFormatId GetDurationFormat () override
 
virtual NumericFormatId GetSelectionFormat ()
 
void SetDuration (double duration) override
 
bool Apply () override
 
void Preview () override
 
wxDialog * CreateUI (wxWindow *parent, EffectUIClientInterface *client) override
 
wxString GetUserPresetsGroup (const wxString &name) override
 
wxString GetCurrentSettingsGroup () override
 
wxString GetFactoryDefaultsGroup () override
 
virtual wxString GetSavedStateGroup ()
 
bool HasSharedConfigGroup (const wxString &group) override
 
bool GetSharedConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetSharedConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetSharedConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemoveSharedConfigSubgroup (const wxString &group) override
 
bool RemoveSharedConfig (const wxString &group, const wxString &key) override
 
bool HasPrivateConfigGroup (const wxString &group) override
 
bool GetPrivateConfigSubgroups (const wxString &group, wxArrayString &subgroups) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, wxString &value, const wxString &defval=wxEmptyString) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, int &value, int defval=0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, bool &value, bool defval=false) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, float &value, float defval=0.0) override
 
bool GetPrivateConfig (const wxString &group, const wxString &key, double &value, double defval=0.0) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const wxString &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const int &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const bool &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const float &value) override
 
bool SetPrivateConfig (const wxString &group, const wxString &key, const double &value) override
 
bool RemovePrivateConfigSubgroup (const wxString &group) override
 
bool RemovePrivateConfig (const wxString &group, const wxString &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 wxArrayString GetUserPresets ()
 
virtual bool HasCurrentSettings ()
 
virtual bool HasFactoryDefaults ()
 
virtual wxString GetPreset (wxWindow *parent, const wxString &parms)
 
virtual wxString ManualPage ()
 
virtual wxString HelpPage ()
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
 
bool DoEffect (wxWindow *parent, double projectRate, TrackList *list, TrackFactory *factory, SelectedRegion *selectedRegion, bool shouldPrompt=true)
 
bool Delegate (Effect &delegate, wxWindow *parent, bool shouldPrompt)
 
bool RealtimeAddProcessor (int group, unsigned chans, float rate)
 
size_t RealtimeProcess (int group, unsigned chans, float **inbuf, float **outbuf, size_t numSamples)
 
bool IsRealtimeActive ()
 
virtual bool IsHidden ()
 
int MessageBox (const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 
- Public Member Functions inherited from EffectClientInterface
virtual ~EffectClientInterface ()
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
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 ()
 

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 }
 
- 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)
 
bool TrackProgress (int whichTrack, double frac, const wxString &=wxEmptyString)
 
bool TrackGroupProgress (int whichGroup, double frac, const wxString &=wxEmptyString)
 
int GetNumWaveTracks ()
 
int GetNumWaveGroups ()
 
void GetSamples (const WaveTrack *track, sampleCount *start, sampleCount *len)
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing ()
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void CopyInputTracks ()
 
void CopyInputTracks (int trackType)
 
std::shared_ptr
< AddedAnalysisTrack
AddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
TrackAddToOutputTracks (std::unique_ptr< Track > &&t)
 
TrackListinputTracks () const
 
- Protected Attributes inherited from Effect
ProgressDialogmProgress
 
double mProjectRate
 
double mSampleRate
 
SelectedRegionmpSelectedRegion {}
 
TrackFactorymFactory
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0
 
double mT1
 
double mF0
 
double mF1
 
wxArrayString mPresetNames
 
wxArrayString mPresetValues
 
int mPass
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 
int mUIResultID
 
sampleCount mSampleCnt
 
int mOutputTracksType
 

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 Hanning 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 22 of file NoiseReduction.h.

Constructor & Destructor Documentation

EffectNoiseReduction::EffectNoiseReduction ( )

Definition at line 420 of file NoiseReduction.cpp.

References Init().

421 : mSettings(std::make_unique<EffectNoiseReduction::Settings>())
422 {
423  Init();
424 }
bool Init() override
std::unique_ptr< Settings > mSettings
EffectNoiseReduction::~EffectNoiseReduction ( )
virtual

Definition at line 426 of file NoiseReduction.cpp.

427 {
428 }

Member Function Documentation

bool EffectNoiseReduction::CheckWhetherSkipEffect ( )
overridevirtual

Reimplemented from Effect.

Definition at line 454 of file NoiseReduction.cpp.

455 {
456  return false;
457 }
wxString EffectNoiseReduction::GetDescription ( )
overridevirtual

Reimplemented from Effect.

Definition at line 437 of file NoiseReduction.cpp.

References _().

438 {
439  return _("Removes background noise such as fans, tape noise, or hums");
440 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
IdentInterfaceSymbol EffectNoiseReduction::GetSymbol ( )
overridevirtual

Reimplemented from Effect.

Definition at line 432 of file NoiseReduction.cpp.

References NOISEREDUCTION_PLUGIN_SYMBOL.

433 {
435 }
#define NOISEREDUCTION_PLUGIN_SYMBOL
EffectType EffectNoiseReduction::GetType ( )
overridevirtual

Reimplemented from Effect.

Definition at line 444 of file NoiseReduction.cpp.

References EffectTypeProcess.

445 {
446  return EffectTypeProcess;
447 }
bool EffectNoiseReduction::Init ( )
overridevirtual

Reimplemented from Effect.

Definition at line 449 of file NoiseReduction.cpp.

Referenced by EffectNoiseReduction().

450 {
451  return true;
452 }
bool EffectNoiseReduction::Process ( )
overridevirtual

Reimplemented from Effect.

Definition at line 603 of file NoiseReduction.cpp.

References _(), Effect::CopyInputTracks(), EXPERIMENTAL_SPECTRAL_EDITING, Effect::MessageBox(), Effect::mF0, Effect::mF1, Effect::mFactory, Effect::mOutputTracks, mSettings, mStatistics, Effect::mT0, Effect::mT1, EffectNoiseReduction::Worker::Process(), Effect::ReplaceProcessedTracks(), and Track::Wave.

604 {
605  // This same code will either reduce noise or profile it
606 
607  this->CopyInputTracks(); // Set up mOutputTracks.
608 
610  WaveTrack *track = (WaveTrack *) iter.First();
611  if (!track)
612  return false;
613 
614  // Initialize statistics if gathering them, or check for mismatched (advanced)
615  // settings if reducing noise.
616  if (mSettings->mDoProfile) {
617  size_t spectrumSize = 1 + mSettings->WindowSize() / 2;
618  mStatistics = std::make_unique<Statistics>
619  (spectrumSize, track->GetRate(), mSettings->mWindowTypes);
620  }
621  else if (mStatistics->mWindowSize != mSettings->WindowSize()) {
622  // possible only with advanced settings
623  ::Effect::MessageBox(_("You must specify the same window size for steps 1 and 2."));
624  return false;
625  }
626  else if (mStatistics->mWindowTypes != mSettings->mWindowTypes) {
627  // A warning only
628  ::Effect::MessageBox(_("Warning: window types are not the same as for profiling."));
629  }
630 
631  Worker worker(*mSettings, mStatistics->mRate
633  , mF0, mF1
634 #endif
635  );
636  bool bGoodResult = worker.Process(*this, *mStatistics, *mFactory, iter, mT0, mT1);
637  if (mSettings->mDoProfile) {
638  if (bGoodResult)
639  mSettings->mDoProfile = false; // So that "repeat last effect" will reduce noise
640  else
641  mStatistics.reset(); // So that profiling must be done again before noise reduction
642  }
643  this->ReplaceProcessedTracks(bGoodResult);
644  return bGoodResult;
645 }
#define EXPERIMENTAL_SPECTRAL_EDITING
Definition: Project.h:137
double mT1
Definition: Effect.h:461
int MessageBox(const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
Definition: Effect.cpp:2646
void CopyInputTracks()
Definition: Effect.cpp:2036
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
double mF0
Definition: Effect.h:463
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
TrackFactory * mFactory
Definition: Effect.h:457
double mF1
Definition: Effect.h:464
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
std::unique_ptr< Settings > mSettings
std::unique_ptr< Statistics > mStatistics
double mT0
Definition: Effect.h:460
bool EffectNoiseReduction::PromptUser ( wxWindow *  parent)
overridevirtual

Reimplemented from Effect.

Definition at line 459 of file NoiseReduction.cpp.

References Effect::GetNumWaveTracks(), mSettings, and mStatistics.

460 {
461  // We may want to twiddle the levels if we are setting
462  // from an automation dialog, the only case in which we can
463  // get here without any wavetracks.
464  return mSettings->PromptUser(this, parent,
465  bool(mStatistics), (GetNumWaveTracks() == 0));
466 }
int GetNumWaveTracks()
Definition: Effect.h:343
std::unique_ptr< Settings > mSettings
std::unique_ptr< Statistics > mStatistics

Friends And Related Function Documentation

friend class Dialog
friend

Definition at line 54 of file NoiseReduction.h.

Member Data Documentation

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

Definition at line 57 of file NoiseReduction.h.

Referenced by Process(), and PromptUser().

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

Definition at line 58 of file NoiseReduction.h.

Referenced by Process(), and PromptUser().


The documentation for this class was generated from the following files: