Skip to content

Commit

Permalink
ZamNoise: Add reduction amount control
Browse files Browse the repository at this point in the history
  • Loading branch information
zamaudio committed Apr 27, 2024
1 parent 89ed906 commit 8d5dae7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
15 changes: 4 additions & 11 deletions plugins/ZamNoise/Denoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,7 @@ double Denoise::fft_window(int k, int N, int window_type)
return 0.0;
}

double Denoise::db2w(double db)
{
return pow(10,db/10);
}


void Denoise::fft_remove_noise(const float* ins, float* outs, uint32_t frames, fftw_real noise_min2[], fftw_real noise_max2[], FFTW(plan) *pFor, FFTW(plan) *pBak)
void Denoise::fft_remove_noise(const float* ins, float* outs, uint32_t frames, fftw_real noise_min2[], fftw_real noise_max2[], float amount, FFTW(plan) *pFor, FFTW(plan) *pBak)
{
int k;
uint32_t i;
Expand Down Expand Up @@ -138,7 +132,7 @@ void Denoise::fft_remove_noise(const float* ins, float* outs, uint32_t frames, f
gain_prev[k] = gain;
Y2_prev[k] = Y2[k];

Fk = amount*(1.0-gain);
Fk = amount * (1.0-gain);

if(Fk < 0.0)
Fk = 0.0;
Expand Down Expand Up @@ -173,7 +167,6 @@ Denoise::Denoise(float srate) {
dn_gamma = 0.95;
n_noise_samples = FFT_SIZE;
rate = (int) srate;
amount = 0.9;
noisebufpos = 0;
prev_sample = 0;

Expand All @@ -192,7 +185,7 @@ Denoise::Denoise(float srate) {
}


void Denoise::process(const float* ins, float* outs, float* noisebuffer, uint32_t frames, int togglenoise) {
void Denoise::process(const float* ins, float* outs, float* noisebuffer, uint32_t frames, int togglenoise, float amount) {

if (togglenoise == 1) {
uint32_t i;
Expand All @@ -208,7 +201,7 @@ void Denoise::process(const float* ins, float* outs, float* noisebuffer, uint32_
outs[i] = ins[i];
}
} else {
fft_remove_noise(ins, outs, frames, noise_min, noise_max, &pFor, &pBak);
fft_remove_noise(ins, outs, frames, noise_min, noise_max, amount, &pFor, &pBak);
}
}

Expand Down
6 changes: 2 additions & 4 deletions plugins/ZamNoise/Denoise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@ class Denoise {
public:
Denoise(float srate);
~Denoise();
void process(const float* ins, float* outs, float* noisebuffer, uint32_t frames, int noisetoggle);
void process(const float* ins, float* outs, float* noisebuffer, uint32_t frames, int noisetoggle, float amount);
double hypergeom(double theta);
double gain_em(double Rprio, double Rpost);
double blackman(int k, int N);
double hanning(int k, int N);
double blackman_hybrid(int k, int n_flat, int N);
double fft_window(int k, int N, int window_type);
double db2w(double db);
void fft_remove_noise(const float* ins, float* outs, uint32_t frames, fftw_real noise_min2[], fftw_real noise_max2[], FFTW(plan) *pFor, FFTW(plan) *pBak);
void fft_remove_noise(const float* ins, float* outs, uint32_t frames, fftw_real noise_min2[], fftw_real noise_max2[], float amount, FFTW(plan) *pFor, FFTW(plan) *pBak);
int denoise(long noise_start, long noise_end, long first_sample, long last_sample);
void get_noise_sample(float* noisebuffer, fftw_real *noise_min, fftw_real *noise_max);

private:
int window_type;
int FFT_SIZE;
int n_noise_samples;
double amount;
double dn_gamma;
double min_sample_freq;
double max_sample_freq;
Expand Down
18 changes: 17 additions & 1 deletion plugins/ZamNoise/ZamNoisePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ void ZamNoisePlugin::initParameter(uint32_t index, Parameter& parameter)
parameter.ranges.min = 0.f;
parameter.ranges.max = 1.f;
break;
case paramReductionAmount:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Reduction Amount";
parameter.symbol = "amount";
parameter.unit = "%";
parameter.ranges.def = 50.f;
parameter.ranges.min = 0.f;
parameter.ranges.max = 100.f;
break;
default:
break;
}
Expand All @@ -80,6 +89,9 @@ float ZamNoisePlugin::getParameterValue(uint32_t index) const
case paramNoiseToggle:
return noisetoggle;
break;
case paramReductionAmount:
return amount;
break;
default:
return 0.0f;
break;
Expand All @@ -96,6 +108,9 @@ void ZamNoisePlugin::setParameterValue(uint32_t index, float value)
}
noisetoggle = value;
break;
case paramReductionAmount:
amount = value;
break;
}
}

Expand All @@ -105,6 +120,7 @@ void ZamNoisePlugin::loadProgram(uint32_t index)
return;

noisetoggle = 0.f;
amount = 50.f;

activate();
}
Expand Down Expand Up @@ -134,7 +150,7 @@ void ZamNoisePlugin::deactivate()

void ZamNoisePlugin::run(const float** inputs, float** outputs, uint32_t frames)
{
zamnoise->process(inputs[0], outputs[0], buffer.cbi, frames, (int)noisetoggle);
zamnoise->process(inputs[0], outputs[0], buffer.cbi, frames, (int)noisetoggle, amount / 100.);
}

void ZamNoisePlugin::sampleRateChanged(double newSampleRate)
Expand Down
4 changes: 3 additions & 1 deletion plugins/ZamNoise/ZamNoisePlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ZamNoisePlugin : public Plugin
enum Parameters
{
paramNoiseToggle,
paramReductionAmount,
paramCount
};

Expand Down Expand Up @@ -74,7 +75,7 @@ class ZamNoisePlugin : public Plugin

uint32_t getVersion() const noexcept override
{
return d_version(3, 8, 0);
return d_version(4, 2, 0);
}

int64_t getUniqueId() const noexcept override
Expand Down Expand Up @@ -103,6 +104,7 @@ class ZamNoisePlugin : public Plugin

// -------------------------------------------------------------------
float noisetoggle;
float amount;

void InstantiateCircularBuffer(CircularBuffer* buffer);
inline void IncrementPointer(CircularBuffer& buffer);
Expand Down

0 comments on commit 8d5dae7

Please sign in to comment.