annotate libtwamr/post_pro.c @ 515:bb36ef735f25

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