diff options
author | erdgeist <erdgeist@erdgeist.org> | 2025-08-15 12:42:40 +0200 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2025-08-15 12:42:40 +0200 |
commit | 30325d24d107dbf133da39f7c96d1510fd1c9449 (patch) | |
tree | 932baa5b2a4475821f16dccf9e3e05011daa6d92 /postfilter.c | |
parent | 9022d768021bbe15c7815cc6f8b64218b46f0e10 (diff) |
Bump to codec2 version 1.2.0erdgeist-bump-to-1.2.0
Diffstat (limited to 'postfilter.c')
-rw-r--r-- | postfilter.c | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/postfilter.c b/postfilter.c index 6542c7c..e46d488 100644 --- a/postfilter.c +++ b/postfilter.c | |||
@@ -27,16 +27,17 @@ | |||
27 | along with this program; if not, see <http://www.gnu.org/licenses/>. | 27 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "postfilter.h" | ||
31 | |||
30 | #include <assert.h> | 32 | #include <assert.h> |
31 | #include <stdlib.h> | ||
32 | #include <stdio.h> | ||
33 | #include <math.h> | 33 | #include <math.h> |
34 | #include <stdio.h> | ||
35 | #include <stdlib.h> | ||
34 | 36 | ||
35 | #include "defines.h" | ||
36 | #include "comp.h" | 37 | #include "comp.h" |
38 | #include "defines.h" | ||
37 | #include "dump.h" | 39 | #include "dump.h" |
38 | #include "sine.h" | 40 | #include "sine.h" |
39 | #include "postfilter.h" | ||
40 | 41 | ||
41 | /*---------------------------------------------------------------------------*\ | 42 | /*---------------------------------------------------------------------------*\ |
42 | 43 | ||
@@ -44,13 +45,14 @@ | |||
44 | 45 | ||
45 | \*---------------------------------------------------------------------------*/ | 46 | \*---------------------------------------------------------------------------*/ |
46 | 47 | ||
47 | #define BG_THRESH 40.0 /* only consider low levels signals for bg_est */ | 48 | #define BG_THRESH 40.0 /* only consider low levels signals for bg_est */ |
48 | #define BG_BETA 0.1 /* averaging filter constant */ | 49 | #define BG_BETA 0.1 /* averaging filter constant */ |
49 | #define BG_MARGIN 6.0 /* harmonics this far above BG noise are | 50 | #define BG_MARGIN \ |
50 | randomised. Helped make bg noise less | 51 | 6.0 /* harmonics this far above BG noise are \ |
51 | spikey (impulsive) for mmt1, but speech was | 52 | randomised. Helped make bg noise less \ |
52 | perhaps a little rougher. | 53 | spikey (impulsive) for mmt1, but speech was \ |
53 | */ | 54 | perhaps a little rougher. \ |
55 | */ | ||
54 | 56 | ||
55 | /*---------------------------------------------------------------------------*\ | 57 | /*---------------------------------------------------------------------------*\ |
56 | 58 | ||
@@ -82,7 +84,7 @@ | |||
82 | 1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track | 84 | 1/ If someone says "aaaaaaaahhhhhhhhh" will background estimator track |
83 | up to speech level? This would be a bad thing. | 85 | up to speech level? This would be a bad thing. |
84 | 86 | ||
85 | 2/ If background noise suddenly dissapears from the source speech does | 87 | 2/ If background noise suddenly disappears from the source speech does |
86 | estimate drop quickly? What is noise suddenly re-appears? | 88 | estimate drop quickly? What is noise suddenly re-appears? |
87 | 89 | ||
88 | 3/ Background noise with a non-flat sepctrum. Current algorithm just | 90 | 3/ Background noise with a non-flat sepctrum. Current algorithm just |
@@ -98,45 +100,39 @@ | |||
98 | 100 | ||
99 | \*---------------------------------------------------------------------------*/ | 101 | \*---------------------------------------------------------------------------*/ |
100 | 102 | ||
101 | void postfilter( | 103 | void postfilter(MODEL *model, float *bg_est) { |
102 | MODEL *model, | 104 | int m, uv; |
103 | float *bg_est | ||
104 | ) | ||
105 | { | ||
106 | int m, uv; | ||
107 | float e, thresh; | 105 | float e, thresh; |
108 | 106 | ||
109 | /* determine average energy across spectrum */ | 107 | /* determine average energy across spectrum */ |
110 | 108 | ||
111 | e = 1E-12; | 109 | e = 1E-12; |
112 | for(m=1; m<=model->L; m++) | 110 | for (m = 1; m <= model->L; m++) e += model->A[m] * model->A[m]; |
113 | e += model->A[m]*model->A[m]; | ||
114 | 111 | ||
115 | assert(e > 0.0); | 112 | assert(e > 0.0); |
116 | e = 10.0*log10f(e/model->L); | 113 | e = 10.0 * log10f(e / model->L); |
117 | 114 | ||
118 | /* If beneath threhold, update bg estimate. The idea | 115 | /* If beneath threshold, update bg estimate. The idea |
119 | of the threshold is to prevent updating during high level | 116 | of the threshold is to prevent updating during high level |
120 | speech. */ | 117 | speech. */ |
121 | 118 | ||
122 | if ((e < BG_THRESH) && !model->voiced) | 119 | if ((e < BG_THRESH) && !model->voiced) |
123 | *bg_est = *bg_est*(1.0 - BG_BETA) + e*BG_BETA; | 120 | *bg_est = *bg_est * (1.0 - BG_BETA) + e * BG_BETA; |
124 | 121 | ||
125 | /* now mess with phases during voiced frames to make any harmonics | 122 | /* now mess with phases during voiced frames to make any harmonics |
126 | less then our background estimate unvoiced. | 123 | less then our background estimate unvoiced. |
127 | */ | 124 | */ |
128 | 125 | ||
129 | uv = 0; | 126 | uv = 0; |
130 | thresh = POW10F((*bg_est + BG_MARGIN)/20.0); | 127 | thresh = POW10F((*bg_est + BG_MARGIN) / 20.0); |
131 | if (model->voiced) | 128 | if (model->voiced) |
132 | for(m=1; m<=model->L; m++) | 129 | for (m = 1; m <= model->L; m++) |
133 | if (model->A[m] < thresh) { | 130 | if (model->A[m] < thresh) { |
134 | model->phi[m] = (TWO_PI/CODEC2_RAND_MAX)*(float)codec2_rand(); | 131 | model->phi[m] = (TWO_PI / CODEC2_RAND_MAX) * (float)codec2_rand(); |
135 | uv++; | 132 | uv++; |
136 | } | 133 | } |
137 | 134 | ||
138 | #ifdef DUMP | 135 | #ifdef DUMP |
139 | dump_bg(e, *bg_est, 100.0*uv/model->L); | 136 | dump_bg(e, *bg_est, 100.0 * uv / model->L); |
140 | #endif | 137 | #endif |
141 | |||
142 | } | 138 | } |