comparison libtwamr/post_pro.c @ 392:a0f914a28371

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