From 30325d24d107dbf133da39f7c96d1510fd1c9449 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Fri, 15 Aug 2025 12:42:40 +0200 Subject: Bump to codec2 version 1.2.0 --- postfilter.c | 58 +++++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'postfilter.c') diff --git a/postfilter.c b/postfilter.c index 6542c7c..e46d488 100644 --- a/postfilter.c +++ b/postfilter.c @@ -27,16 +27,17 @@ along with this program; if not, see . */ +#include "postfilter.h" + #include -#include -#include #include +#include +#include -#include "defines.h" #include "comp.h" +#include "defines.h" #include "dump.h" #include "sine.h" -#include "postfilter.h" /*---------------------------------------------------------------------------*\ @@ -44,13 +45,14 @@ \*---------------------------------------------------------------------------*/ -#define BG_THRESH 40.0 /* only consider low levels signals for bg_est */ -#define BG_BETA 0.1 /* averaging filter constant */ -#define BG_MARGIN 6.0 /* harmonics this far above BG noise are - randomised. Helped make bg noise less - spikey (impulsive) for mmt1, but speech was - perhaps a little rougher. - */ +#define BG_THRESH 40.0 /* only consider low levels signals for bg_est */ +#define BG_BETA 0.1 /* averaging filter constant */ +#define BG_MARGIN \ + 6.0 /* harmonics this far above BG noise are \ + randomised. Helped make bg noise less \ + spikey (impulsive) for mmt1, but speech was \ + perhaps a little rougher. \ + */ /*---------------------------------------------------------------------------*\ @@ -82,7 +84,7 @@ 1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track up to speech level? This would be a bad thing. - 2/ If background noise suddenly dissapears from the source speech does + 2/ If background noise suddenly disappears from the source speech does estimate drop quickly? What is noise suddenly re-appears? 3/ Background noise with a non-flat sepctrum. Current algorithm just @@ -98,45 +100,39 @@ \*---------------------------------------------------------------------------*/ -void postfilter( - MODEL *model, - float *bg_est -) -{ - int m, uv; +void postfilter(MODEL *model, float *bg_est) { + int m, uv; float e, thresh; /* determine average energy across spectrum */ e = 1E-12; - for(m=1; m<=model->L; m++) - e += model->A[m]*model->A[m]; + for (m = 1; m <= model->L; m++) e += model->A[m] * model->A[m]; assert(e > 0.0); - e = 10.0*log10f(e/model->L); + e = 10.0 * log10f(e / model->L); - /* If beneath threhold, update bg estimate. The idea + /* If beneath threshold, update bg estimate. The idea of the threshold is to prevent updating during high level speech. */ if ((e < BG_THRESH) && !model->voiced) - *bg_est = *bg_est*(1.0 - BG_BETA) + e*BG_BETA; + *bg_est = *bg_est * (1.0 - BG_BETA) + e * BG_BETA; /* now mess with phases during voiced frames to make any harmonics less then our background estimate unvoiced. */ uv = 0; - thresh = POW10F((*bg_est + BG_MARGIN)/20.0); + thresh = POW10F((*bg_est + BG_MARGIN) / 20.0); if (model->voiced) - for(m=1; m<=model->L; m++) - if (model->A[m] < thresh) { - model->phi[m] = (TWO_PI/CODEC2_RAND_MAX)*(float)codec2_rand(); - uv++; - } + for (m = 1; m <= model->L; m++) + if (model->A[m] < thresh) { + model->phi[m] = (TWO_PI / CODEC2_RAND_MAX) * (float)codec2_rand(); + uv++; + } #ifdef DUMP - dump_bg(e, *bg_est, 100.0*uv/model->L); + dump_bg(e, *bg_est, 100.0 * uv / model->L); #endif - } -- cgit v1.2.3