From 396274ff665ff9c408f33a4e85366ec6e6b268c0 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sat, 1 Dec 2018 15:52:09 -0500 Subject: [PATCH] Add variable gain and response --- src/denoise.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/denoise.c b/src/denoise.c index b4eeffb..7bfd55c 100644 --- a/src/denoise.c +++ b/src/denoise.c @@ -608,7 +608,7 @@ float rnnoise_process_frame(DenoiseState *st, float *out, const float *in) { #if TRAINING -/*static float uni_rand() { +static float uni_rand() { return rand()/(double)RAND_MAX-.5; } @@ -617,16 +617,20 @@ static void rand_resp(float *a, float *b) { a[1] = .75*uni_rand(); b[0] = .75*uni_rand(); b[1] = .75*uni_rand(); -}*/ +} int main(int argc, char **argv) { int i; int count=0; static const float a_hp[2] = {-1.99599, 0.99600}; static const float b_hp[2] = {-2, 1}; + float a_sig[2] = {0}; + float b_sig[2] = {0}; float mem_hp_x[2]={0}; + float mem_resp_x[2]={0}; float mem_preemph=0; float x[FRAME_SIZE]; + int gain_change_count=0; FILE *f1; FILE *ffeat; FILE *fpcm; @@ -635,7 +639,9 @@ int main(int argc, char **argv) { short pcm[FRAME_SIZE]; short tmp[FRAME_SIZE] = {0}; float savedX[FRAME_SIZE] = {0}; + float speech_gain=1; int last_silent = 1; + float old_speech_gain = 1; DenoiseState *st; st = rnnoise_create(); if (argc!=4) { @@ -675,13 +681,27 @@ int main(int argc, char **argv) { continue; } last_silent = silent; + if (++gain_change_count > 2821) { + speech_gain = pow(10., (-20+(rand()%40))/20.); + if (rand()%20==0) speech_gain *= .01; + if (rand()%100==0) speech_gain = 0; + gain_change_count = 0; + rand_resp(a_sig, b_sig); + } biquad(x, mem_hp_x, x, b_hp, a_hp, FRAME_SIZE); + biquad(x, mem_resp_x, x, b_sig, a_sig, FRAME_SIZE); preemphasis(x, &mem_preemph, x, PREEMPHASIS, FRAME_SIZE); - + for (i=0;i