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