diff options
Diffstat (limited to 'codec2.c')
-rw-r--r-- | codec2.c | 43 |
1 files changed, 28 insertions, 15 deletions
@@ -29,6 +29,7 @@ | |||
29 | #include <assert.h> | 29 | #include <assert.h> |
30 | #include <stdio.h> | 30 | #include <stdio.h> |
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <stdbool.h> | ||
32 | #include <string.h> | 33 | #include <string.h> |
33 | #include <math.h> | 34 | #include <math.h> |
34 | 35 | ||
@@ -114,12 +115,25 @@ struct CODEC2 * codec2_create(int mode) | |||
114 | struct CODEC2 *c2; | 115 | struct CODEC2 *c2; |
115 | int i,l; | 116 | int i,l; |
116 | 117 | ||
117 | #ifndef CORTEX_M4 | 118 | // ALL POSSIBLE MODES MUST BE CHECKED HERE! |
118 | if (( CODEC2_MODE_ACTIVE(CODEC2_MODE_450, mode)) || | 119 | // we test if the desired mode is enabled at compile time |
119 | ( CODEC2_MODE_ACTIVE(CODEC2_MODE_450PWB, mode)) ) { | 120 | // and return NULL if not |
121 | |||
122 | if (false == ( CODEC2_MODE_ACTIVE(CODEC2_MODE_3200, mode) | ||
123 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_2400, mode) | ||
124 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_1600, mode) | ||
125 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_1400, mode) | ||
126 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_1300, mode) | ||
127 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_1200, mode) | ||
128 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_700, mode) | ||
129 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_700B, mode) | ||
130 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_700C, mode) | ||
131 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_450, mode) | ||
132 | || CODEC2_MODE_ACTIVE(CODEC2_MODE_450PWB, mode) | ||
133 | ) ) | ||
134 | { | ||
120 | return NULL; | 135 | return NULL; |
121 | } | 136 | } |
122 | #endif | ||
123 | 137 | ||
124 | c2 = (struct CODEC2*)MALLOC(sizeof(struct CODEC2)); | 138 | c2 = (struct CODEC2*)MALLOC(sizeof(struct CODEC2)); |
125 | if (c2 == NULL) | 139 | if (c2 == NULL) |
@@ -221,14 +235,15 @@ struct CODEC2 * codec2_create(int mode) | |||
221 | int k; | 235 | int k; |
222 | for(k=0; k<NEWAMP1_K; k++) { | 236 | for(k=0; k<NEWAMP1_K; k++) { |
223 | c2->prev_rate_K_vec_[k] = 0.0; | 237 | c2->prev_rate_K_vec_[k] = 0.0; |
238 | c2->eq[k] = 0.0; | ||
224 | } | 239 | } |
240 | c2->eq_en = 0; | ||
225 | c2->Wo_left = 0.0; | 241 | c2->Wo_left = 0.0; |
226 | c2->voicing_left = 0;; | 242 | c2->voicing_left = 0;; |
227 | c2->phase_fft_fwd_cfg = codec2_fft_alloc(NEWAMP1_PHASE_NFFT, 0, NULL, NULL); | 243 | c2->phase_fft_fwd_cfg = codec2_fft_alloc(NEWAMP1_PHASE_NFFT, 0, NULL, NULL); |
228 | c2->phase_fft_inv_cfg = codec2_fft_alloc(NEWAMP1_PHASE_NFFT, 1, NULL, NULL); | 244 | c2->phase_fft_inv_cfg = codec2_fft_alloc(NEWAMP1_PHASE_NFFT, 1, NULL, NULL); |
229 | } | 245 | } |
230 | 246 | ||
231 | #ifndef CORTEX_M4 | ||
232 | /* newamp2 initialisation */ | 247 | /* newamp2 initialisation */ |
233 | 248 | ||
234 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_450, c2->mode)) { | 249 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_450, c2->mode)) { |
@@ -255,7 +270,6 @@ struct CODEC2 * codec2_create(int mode) | |||
255 | c2->phase_fft_fwd_cfg = codec2_fft_alloc(NEWAMP2_PHASE_NFFT, 0, NULL, NULL); | 270 | c2->phase_fft_fwd_cfg = codec2_fft_alloc(NEWAMP2_PHASE_NFFT, 0, NULL, NULL); |
256 | c2->phase_fft_inv_cfg = codec2_fft_alloc(NEWAMP2_PHASE_NFFT, 1, NULL, NULL); | 271 | c2->phase_fft_inv_cfg = codec2_fft_alloc(NEWAMP2_PHASE_NFFT, 1, NULL, NULL); |
257 | } | 272 | } |
258 | #endif | ||
259 | 273 | ||
260 | c2->fmlfeat = NULL; | 274 | c2->fmlfeat = NULL; |
261 | 275 | ||
@@ -302,7 +316,6 @@ struct CODEC2 * codec2_create(int mode) | |||
302 | c2->decode = codec2_decode_1200; | 316 | c2->decode = codec2_decode_1200; |
303 | } | 317 | } |
304 | 318 | ||
305 | #ifndef CORTEX_M4 | ||
306 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_700, c2->mode)) | 319 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_700, c2->mode)) |
307 | { | 320 | { |
308 | c2->encode = codec2_encode_700; | 321 | c2->encode = codec2_encode_700; |
@@ -314,13 +327,13 @@ struct CODEC2 * codec2_create(int mode) | |||
314 | c2->encode = codec2_encode_700b; | 327 | c2->encode = codec2_encode_700b; |
315 | c2->decode = codec2_decode_700b; | 328 | c2->decode = codec2_decode_700b; |
316 | } | 329 | } |
317 | #endif | 330 | |
318 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_700C, c2->mode)) | 331 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_700C, c2->mode)) |
319 | { | 332 | { |
320 | c2->encode = codec2_encode_700c; | 333 | c2->encode = codec2_encode_700c; |
321 | c2->decode = codec2_decode_700c; | 334 | c2->decode = codec2_decode_700c; |
322 | } | 335 | } |
323 | #ifndef CORTEX_M4 | 336 | |
324 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_450, c2->mode)) | 337 | if ( CODEC2_MODE_ACTIVE(CODEC2_MODE_450, c2->mode)) |
325 | { | 338 | { |
326 | c2->encode = codec2_encode_450; | 339 | c2->encode = codec2_encode_450; |
@@ -334,7 +347,6 @@ struct CODEC2 * codec2_create(int mode) | |||
334 | c2->decode = codec2_decode_450pwb; | 347 | c2->decode = codec2_decode_450pwb; |
335 | } | 348 | } |
336 | 349 | ||
337 | #endif | ||
338 | 350 | ||
339 | return c2; | 351 | return c2; |
340 | } | 352 | } |
@@ -1518,7 +1530,6 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * | |||
1518 | } | 1530 | } |
1519 | 1531 | ||
1520 | 1532 | ||
1521 | #ifndef CORTEX_M4 | ||
1522 | /*---------------------------------------------------------------------------*\ | 1533 | /*---------------------------------------------------------------------------*\ |
1523 | 1534 | ||
1524 | FUNCTION....: codec2_encode_700 | 1535 | FUNCTION....: codec2_encode_700 |
@@ -1926,7 +1937,6 @@ void codec2_decode_700b(struct CODEC2 *c2, short speech[], const unsigned char * | |||
1926 | for(i=0; i<LPC_ORD_LOW; i++) | 1937 | for(i=0; i<LPC_ORD_LOW; i++) |
1927 | c2->prev_lsps_dec[i] = lsps[3][i]; | 1938 | c2->prev_lsps_dec[i] = lsps[3][i]; |
1928 | } | 1939 | } |
1929 | #endif | ||
1930 | 1940 | ||
1931 | 1941 | ||
1932 | /*---------------------------------------------------------------------------*\ | 1942 | /*---------------------------------------------------------------------------*\ |
@@ -1987,7 +1997,7 @@ void codec2_encode_700c(struct CODEC2 *c2, unsigned char * bits, short speech[]) | |||
1987 | K, | 1997 | K, |
1988 | &mean, | 1998 | &mean, |
1989 | rate_K_vec_no_mean, | 1999 | rate_K_vec_no_mean, |
1990 | rate_K_vec_no_mean_, &c2->se); | 2000 | rate_K_vec_no_mean_, &c2->se, c2->eq, c2->eq_en); |
1991 | c2->nse += K; | 2001 | c2->nse += K; |
1992 | 2002 | ||
1993 | #ifndef CORTEX_M4 | 2003 | #ifndef CORTEX_M4 |
@@ -2092,7 +2102,6 @@ float codec2_energy_700c(struct CODEC2 *c2, const unsigned char * bits) | |||
2092 | return POW10F(mean/10.0); | 2102 | return POW10F(mean/10.0); |
2093 | } | 2103 | } |
2094 | 2104 | ||
2095 | #ifndef CORTEX_M4 | ||
2096 | float codec2_energy_450(struct CODEC2 *c2, const unsigned char * bits) | 2105 | float codec2_energy_450(struct CODEC2 *c2, const unsigned char * bits) |
2097 | { | 2106 | { |
2098 | int indexes[4]; | 2107 | int indexes[4]; |
@@ -2418,7 +2427,6 @@ void codec2_decode_450pwb(struct CODEC2 *c2, short speech[], const unsigned char | |||
2418 | } | 2427 | } |
2419 | } | 2428 | } |
2420 | 2429 | ||
2421 | #endif | ||
2422 | 2430 | ||
2423 | /*---------------------------------------------------------------------------* \ | 2431 | /*---------------------------------------------------------------------------* \ |
2424 | 2432 | ||
@@ -2719,3 +2727,8 @@ float *codec2_enable_user_ratek(struct CODEC2 *codec2_state, int *K) { | |||
2719 | void codec2_700c_post_filter(struct CODEC2 *codec2_state, int en) { | 2727 | void codec2_700c_post_filter(struct CODEC2 *codec2_state, int en) { |
2720 | codec2_state->post_filter_en = en; | 2728 | codec2_state->post_filter_en = en; |
2721 | } | 2729 | } |
2730 | |||
2731 | void codec2_700c_eq(struct CODEC2 *codec2_state, int en) { | ||
2732 | codec2_state->eq_en = en; | ||
2733 | codec2_state->se = 0.0; codec2_state->nse = 0; | ||
2734 | } | ||