1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00
audacity/src/effects/NoiseRemoval.h
James Crook 1c988b4e3a Automation: AudacityCommand
This is a squash of 50 commits.

This merges the capabilities of BatchCommands and Effects using a new
AudacityCommand class.  AudacityCommand provides one function to specify the
parameters, and then we leverage that one function in automation, whether by chains,
mod-script-pipe or (future) Nyquist.

- Now have AudacityCommand which is using the same mechanism as Effect
- Has configurable parameters
- Has data-entry GUI (built using shuttle GUI)
- Registers with PluginManager.
- Menu commands now provided in chains, and to python batch.
   - Tested with Zoom Toggle.

- ShuttleParams now can set, get, set defaults, validate and specify
the parameters.
- Bugfix: Don't overwrite values with defaults first time out.
- Add DefineParams function for all built-in effects.
- Extend CommandContext to carry output channels for results.

We abuse EffectsManager.  It handles both Effects and
AudacityCommands now.  In time an Effect should become a special case of
AudacityCommand and we'll split and rename the EffectManager class.

- Don't use 'default' as a parameter name.
- Massive renaming for CommandDefinitionInterface
- EffectIdentInterface becomes EffectDefinitionInterface
- EffectAutomationParameters becomes CommandAutomationParameters
- PluginType is now a bit field.

This way we can search for related types at the same time.

- Most old batch commands made into AudacityCommands.
The ones that weren't are for a reason.  They are used by mod-script-pipe
to carry commands and responses across from a non-GUI thread to the GUI
thread.

- Major tidy up of ScreenshotCommand
- Reworking of SelectCommand
- GetPreferenceCommand and SetPreferenceCommand
- GetTrackInfo and SetTrackInfo
- GetInfoCommand
- Help, Open, Save, Import and Export commands.
- Removed obsolete commands ExecMenu, GetProjectInfo and SetProjectInfo
  which are now better handled by other commands.

- JSONify "GetInfo: Commands" output, i.e. commas in the right places.

- General work on better Doxygen.
    - Lyrics -> LyricsPanel
    - Meter -> MeterPanel
- Updated Linux makefile.
- Scripting commands added into Extra menu.
- Distinct names for previously duplicated find-clipping parameters.
- Fixed longstanding error with erroneous status field number which
  previously caused an ASSERT in debug.
- Sensible formatting of numbers in Chains, 0.1 not 0.1000000000137
2018-02-24 14:20:22 -05:00

205 lines
5.1 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
NoiseRemoval.h
Dominic Mazzoni
Vaughan Johnson (Preview)
**********************************************************************/
#ifndef __AUDACITY_EFFECT_NOISE_REMOVAL__
#define __AUDACITY_EFFECT_NOISE_REMOVAL__
#include "../Audacity.h"
#include "../Experimental.h"
#if !defined(EXPERIMENTAL_NOISE_REDUCTION)
#include "Effect.h"
#include "../MemoryX.h"
#include "../SampleFormat.h"
#include <wx/dialog.h>
#include <wx/slider.h>
class wxButton;
class wxSizer;
class wxString;
class Envelope;
class WaveTrack;
class wxRadioButton;
class wxTextCtrl;
#include "../RealFFTf.h"
#define NOISEREMOVAL_PLUGIN_SYMBOL XO("Noise Removal")
class EffectNoiseRemoval final : public Effect
{
public:
EffectNoiseRemoval();
virtual ~EffectNoiseRemoval();
// IdentInterface implementation
wxString GetSymbol() override;
wxString GetDescription() override;
// EffectDefinitionInterface implementation
EffectType GetType() override;
bool SupportsAutomation() override;
// Effect implementation
bool PromptUser(wxWindow *parent) override;
bool Init() override;
bool CheckWhetherSkipEffect() override;
bool Process() override;
void End() override;
private:
bool mDoProfile;
bool mHasProfile;
int mLevel;
// Parameters chosen before the first phase
double mSampleRate;
size_t mWindowSize;
size_t mSpectrumSize;
float mMinSignalTime; // in secs
// The frequency-indexed noise threshold derived during the first
// phase of analysis
Floats mNoiseThreshold; // length is mSpectrumSize
// Parameters that affect the noise removal, regardless of how the
// noise profile was extracted
double mSensitivity;
double mFreqSmoothingHz;
double mNoiseGain; // in dB, should be negative
double mAttackDecayTime; // in secs
bool mbLeaveNoise;
bool ProcessOne(int count, WaveTrack * track,
sampleCount start, sampleCount len);
void Initialize();
void StartNewTrack();
void ProcessSamples(size_t len, float *buffer);
void FillFirstHistoryWindow();
void ApplyFreqSmoothing(float *spec);
void GetProfile();
void RemoveNoise();
void RotateHistoryWindows();
void FinishTrack();
// Variables that only exist during processing
std::unique_ptr<WaveTrack> mOutputTrack;
sampleCount mInSampleCount;
sampleCount mOutSampleCount;
int mInputPos;
HFFT hFFT;
Floats mFFTBuffer; // mWindowSize
Floats mWindow; // mWindowSize
int mFreqSmoothingBins;
int mAttackDecayBlocks;
float mOneBlockAttackDecay;
float mNoiseAttenFactor;
float mSensitivityFactor;
size_t mMinSignalBlocks;
size_t mHistoryLen;
Floats mInWaveBuffer; // mWindowSize
Floats mOutOverlapBuffer; // mWindowSize
ArraysOf<float> mSpectrums; // mHistoryLen x mSpectrumSize
ArraysOf<float> mGains; // mHistoryLen x mSpectrumSize
ArraysOf<float> mRealFFTs; // mHistoryLen x mWindowSize
ArraysOf<float> mImagFFTs; // mHistoryLen x mWindowSize
friend class NoiseRemovalDialog;
};
// WDR: class declarations
//----------------------------------------------------------------------------
// NoiseRemovalDialog
//----------------------------------------------------------------------------
// Declare window functions
class NoiseRemovalDialog final : public EffectDialog
{
public:
// constructors and destructors
NoiseRemovalDialog(EffectNoiseRemoval * effect,
wxWindow *parent);
wxSizer *MakeNoiseRemovalDialog(bool call_fit = true,
bool set_sizer = true);
void PopulateOrExchange(ShuttleGui & S);
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private:
// handlers
void OnGetProfile( wxCommandEvent &event );
void OnKeepNoise( wxCommandEvent &event );
void OnPreview(wxCommandEvent &event);
void OnRemoveNoise( wxCommandEvent &event );
void OnCancel( wxCommandEvent &event );
void OnSensitivityText(wxCommandEvent & event);
void OnGainText(wxCommandEvent & event);
void OnFreqText(wxCommandEvent & event);
void OnTimeText(wxCommandEvent & event);
void OnSensitivitySlider(wxCommandEvent & event);
void OnGainSlider(wxCommandEvent & event);
void OnFreqSlider(wxCommandEvent & event);
void OnTimeSlider(wxCommandEvent & event);
public:
EffectNoiseRemoval * m_pEffect;
wxButton * m_pButton_GetProfile;
wxButton * m_pButton_Preview;
wxButton * m_pButton_RemoveNoise;
wxRadioButton *mKeepSignal;
wxRadioButton *mKeepNoise;
wxSlider *mSensitivityS;
wxSlider *mGainS;
wxSlider *mFreqS;
wxSlider *mTimeS;
wxTextCtrl *mSensitivityT;
wxTextCtrl *mGainT;
wxTextCtrl *mFreqT;
wxTextCtrl *mTimeT;
double mSensitivity;
double mGain;
double mFreq;
double mTime;
bool mbLeaveNoise;
private:
DECLARE_EVENT_TABLE()
};
#endif
#endif