FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/pre_proc.c @ 397:9b699f30e6f3
libtwamr: integrate pre_proc.c
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Mon, 06 May 2024 19:02:44 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 396:38ee82480462 | 397:9b699f30e6f3 |
|---|---|
| 1 /* | |
| 2 ******************************************************************************** | |
| 3 * | |
| 4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 | |
| 5 * R99 Version 3.3.0 | |
| 6 * REL-4 Version 4.1.0 | |
| 7 * | |
| 8 ******************************************************************************** | |
| 9 * | |
| 10 * File : pre_proc.c | |
| 11 * Purpose : Preprocessing of input speech. | |
| 12 * | |
| 13 ******************************************************************************** | |
| 14 */ | |
| 15 | |
| 16 /* | |
| 17 ******************************************************************************** | |
| 18 * MODULE INCLUDE FILE AND VERSION ID | |
| 19 ******************************************************************************** | |
| 20 */ | |
| 21 #include "namespace.h" | |
| 22 #include "pre_proc.h" | |
| 23 | |
| 24 /* | |
| 25 ******************************************************************************** | |
| 26 * INCLUDE FILES | |
| 27 ******************************************************************************** | |
| 28 */ | |
| 29 #include "typedef.h" | |
| 30 #include "basic_op.h" | |
| 31 #include "oper_32b.h" | |
| 32 #include "no_count.h" | |
| 33 | |
| 34 /* | |
| 35 ******************************************************************************** | |
| 36 * LOCAL VARIABLES AND TABLES | |
| 37 ******************************************************************************** | |
| 38 */ | |
| 39 /* filter coefficients (fc = 80 Hz, coeff. b[] is divided by 2) */ | |
| 40 static const Word16 b[3] = {1899, -3798, 1899}; | |
| 41 static const Word16 a[3] = {4096, 7807, -3733}; | |
| 42 | |
| 43 /* | |
| 44 ******************************************************************************** | |
| 45 * PUBLIC PROGRAM CODE | |
| 46 ******************************************************************************** | |
| 47 */ | |
| 48 | |
| 49 /************************************************************************* | |
| 50 * | |
| 51 * Function: Pre_Process_reset | |
| 52 * Purpose: Initializes state memory to zero | |
| 53 * | |
| 54 ************************************************************************** | |
| 55 */ | |
| 56 void Pre_Process_reset (Pre_ProcessState *state) | |
| 57 { | |
| 58 state->y2_hi = 0; | |
| 59 state->y2_lo = 0; | |
| 60 state->y1_hi = 0; | |
| 61 state->y1_lo = 0; | |
| 62 state->x0 = 0; | |
| 63 state->x1 = 0; | |
| 64 } | |
| 65 | |
| 66 /************************************************************************* | |
| 67 * | |
| 68 * FUNCTION: Pre_Process() | |
| 69 * | |
| 70 * PURPOSE: Preprocessing of input speech. | |
| 71 * | |
| 72 * DESCRIPTION: | |
| 73 * - 2nd order high pass filtering with cut off frequency at 80 Hz. | |
| 74 * - Divide input by two. | |
| 75 * | |
| 76 * | |
| 77 * Algorithm: | |
| 78 * | |
| 79 * y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b[2]*x[i-2]/2 | |
| 80 * + a[1]*y[i-1] + a[2]*y[i-2]; | |
| 81 * | |
| 82 * | |
| 83 * Input is divided by two in the filtering process. | |
| 84 * | |
| 85 *************************************************************************/ | |
| 86 int Pre_Process ( | |
| 87 Pre_ProcessState *st, | |
| 88 Word16 signal[], /* input/output signal */ | |
| 89 Word16 lg) /* lenght of signal */ | |
| 90 { | |
| 91 Word16 i, x2; | |
| 92 Word32 L_tmp; | |
| 93 | |
| 94 for (i = 0; i < lg; i++) | |
| 95 { | |
| 96 x2 = st->x1; move16 (); | |
| 97 st->x1 = st->x0; move16 (); | |
| 98 st->x0 = signal[i]; move16 (); | |
| 99 | |
| 100 /* y[i] = b[0]*x[i]/2 + b[1]*x[i-1]/2 + b140[2]*x[i-2]/2 */ | |
| 101 /* + a[1]*y[i-1] + a[2] * y[i-2]; */ | |
| 102 | |
| 103 L_tmp = Mpy_32_16 (st->y1_hi, st->y1_lo, a[1]); | |
| 104 L_tmp = L_add (L_tmp, Mpy_32_16 (st->y2_hi, st->y2_lo, a[2])); | |
| 105 L_tmp = L_mac (L_tmp, st->x0, b[0]); | |
| 106 L_tmp = L_mac (L_tmp, st->x1, b[1]); | |
| 107 L_tmp = L_mac (L_tmp, x2, b[2]); | |
| 108 L_tmp = L_shl (L_tmp, 3); | |
| 109 signal[i] = round (L_tmp); move16 (); | |
| 110 | |
| 111 st->y2_hi = st->y1_hi; move16 (); | |
| 112 st->y2_lo = st->y1_lo; move16 (); | |
| 113 L_Extract (L_tmp, &st->y1_hi, &st->y1_lo); | |
| 114 } | |
| 115 return 0; | |
| 116 } |
