comparison libtwamr/int_lpc.c @ 381:32bc48faec4b

libtwamr: integrate int_lpc.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 05:35:21 +0000
parents
children
comparison
equal deleted inserted replaced
380:2ed325c9a507 381:32bc48faec4b
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 : int_lpc.c
11 *
12 ********************************************************************************
13 */
14 /*
15 ********************************************************************************
16 * MODULE INCLUDE FILE AND VERSION ID
17 ********************************************************************************
18 */
19 #include "namespace.h"
20 #include "int_lpc.h"
21
22 /*
23 ********************************************************************************
24 * INCLUDE FILES
25 ********************************************************************************
26 */
27 #include "typedef.h"
28 #include "basic_op.h"
29 #include "no_count.h"
30 #include "cnst.h"
31 #include "lsp_az.h"
32
33 /*
34 ********************************************************************************
35 * LOCAL VARIABLES AND TABLES
36 ********************************************************************************
37 */
38 /*
39 *--------------------------------------*
40 * Constants (defined in cnst.h) *
41 *--------------------------------------*
42 * M : LPC order *
43 * MP1 : LPC order + 1 *
44 *--------------------------------------*
45 */
46
47 /*
48 ********************************************************************************
49 * PUBLIC PROGRAM CODE
50 ********************************************************************************
51 */
52 /*
53 **************************************************************************
54 *
55 * Function : Int_lpc_1and3
56 * Purpose : Interpolates the LSPs and converts to LPC parameters
57 * to get a different LP filter in each subframe.
58 * Description : The 20 ms speech frame is divided into 4 subframes.
59 * The LSPs are quantized and transmitted at the 2nd and
60 * 4th subframes (twice per frame) and interpolated at the
61 * 1st and 3rd subframe.
62 *
63 * |------|------|------|------|
64 * sf1 sf2 sf3 sf4
65 * F0 Fm F1
66 *
67 * sf1: 1/2 Fm + 1/2 F0 sf3: 1/2 F1 + 1/2 Fm
68 * sf2: Fm sf4: F1
69 * Returns : void
70 *
71 **************************************************************************
72 */
73 void Int_lpc_1and3 (
74 Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */
75 Word16 lsp_mid[], /* i : LSP vector at the 2nd subfr. of
76 present frame (M) */
77 Word16 lsp_new[], /* i : LSP vector at the 4th subfr. of
78 present frame (M) */
79 Word16 Az[] /* o : interpolated LP parameters in all subfr.
80 (AZ_SIZE) */
81 )
82 {
83 Word16 i;
84 Word16 lsp[M];
85
86 /* lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */
87
88 for (i = 0; i < M; i++)
89 {
90 lsp[i] = add (shr (lsp_mid[i], 1), shr (lsp_old[i], 1));
91 move16 ();
92 }
93
94 Lsp_Az (lsp, Az); /* Subframe 1 */
95 Az += MP1; move16 ();
96
97 Lsp_Az (lsp_mid, Az); /* Subframe 2 */
98 Az += MP1; move16 ();
99
100 for (i = 0; i < M; i++)
101 {
102 lsp[i] = add (shr (lsp_mid[i], 1), shr (lsp_new[i], 1));
103 move16 ();
104 }
105
106 Lsp_Az (lsp, Az); /* Subframe 3 */
107 Az += MP1; move16 ();
108
109 Lsp_Az (lsp_new, Az); /* Subframe 4 */
110
111 return;
112 }
113
114 /*
115 **************************************************************************
116 *
117 * Function : Int_lpc_1and3_2
118 * Purpose : Interpolation of the LPC parameters. Same as the Int_lpc
119 * function but we do not recompute Az() for subframe 2 and
120 * 4 because it is already available.
121 * Returns : void
122 *
123 **************************************************************************
124 */
125 void Int_lpc_1and3_2 (
126 Word16 lsp_old[], /* i : LSP vector at the 4th subfr. of past frame (M) */
127 Word16 lsp_mid[], /* i : LSP vector at the 2nd subframe of
128 present frame (M) */
129 Word16 lsp_new[], /* i : LSP vector at the 4th subframe of
130 present frame (M) */
131 Word16 Az[] /* o :interpolated LP parameters
132 in subframes 1 and 3 (AZ_SIZE) */
133 )
134 {
135 Word16 i;
136 Word16 lsp[M];
137
138 /* lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */
139
140 for (i = 0; i < M; i++)
141 {
142 lsp[i] = add (shr (lsp_mid[i], 1), shr (lsp_old[i], 1));
143 move16 ();
144 }
145 Lsp_Az (lsp, Az); /* Subframe 1 */
146 Az += MP1 * 2; move16 ();
147
148 for (i = 0; i < M; i++)
149 {
150 lsp[i] = add (shr (lsp_mid[i], 1), shr (lsp_new[i], 1));
151 move16 ();
152 }
153 Lsp_Az (lsp, Az); /* Subframe 3 */
154
155 return;
156 }
157 /*************************************************************************
158 *
159 * FUNCTION: Int_lpc_1to3()
160 *
161 * PURPOSE: Interpolates the LSPs and convert to LP parameters to get
162 * a different LP filter in each subframe.
163 *
164 * DESCRIPTION:
165 * The 20 ms speech frame is divided into 4 subframes.
166 * The LSPs are quantized and transmitted at the 4th subframe
167 * (once per frame) and interpolated at the 1st, 2nd and 3rd subframe.
168 *
169 * |------|------|------|------|
170 * sf1 sf2 sf3 sf4
171 * F0 F1
172 *
173 * sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1
174 * sf2: 1/2 F0 + 1/2 F1 sf4: F1
175 *
176 *************************************************************************/
177 void Int_lpc_1to3(
178 Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame */
179 Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */
180 Word16 Az[] /* output: interpolated LP parameters in all SFs */
181 )
182 {
183 Word16 i;
184 Word16 lsp[M];
185
186 for (i = 0; i < M; i++) {
187 lsp[i] = add(shr(lsp_new[i], 2), sub(lsp_old[i], shr(lsp_old[i], 2)));
188 move16 ();
189 }
190
191 Lsp_Az(lsp, Az); /* Subframe 1 */
192 Az += MP1; move16 ();
193
194
195 for (i = 0; i < M; i++) {
196 lsp[i] = add(shr(lsp_old[i], 1), shr(lsp_new[i], 1));
197 move16 ();
198 }
199
200 Lsp_Az(lsp, Az); /* Subframe 2 */
201 Az += MP1; move16 ();
202
203 for (i = 0; i < M; i++) {
204 lsp[i] = add(shr(lsp_old[i], 2), sub(lsp_new[i], shr(lsp_new[i], 2)));
205 move16 ();
206 }
207
208 Lsp_Az(lsp, Az); /* Subframe 3 */
209 Az += MP1; move16 ();
210
211 Lsp_Az(lsp_new, Az); /* Subframe 4 */
212
213 return;
214 }
215
216 /*************************************************************************
217 * Function Int_lpc_1to3_2()
218 * Interpolation of the LPC parameters.
219 * Same as the previous function but we do not recompute Az() for
220 * subframe 4 because it is already available.
221 *************************************************************************/
222
223 void Int_lpc_1to3_2(
224 Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame */
225 Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */
226 Word16 Az[] /* output: interpolated LP parameters in SFs 1,2,3 */
227 )
228 {
229 Word16 i;
230 Word16 lsp[M];
231
232 for (i = 0; i < M; i++) {
233 lsp[i] = add(shr(lsp_new[i], 2), sub(lsp_old[i], shr(lsp_old[i], 2)));
234 move16 ();
235 }
236
237 Lsp_Az(lsp, Az); /* Subframe 1 */
238 Az += MP1; move16 ();
239
240 for (i = 0; i < M; i++) {
241 lsp[i] = add(shr(lsp_old[i], 1), shr(lsp_new[i], 1));
242 move16 ();
243 }
244
245 Lsp_Az(lsp, Az); /* Subframe 2 */
246 Az += MP1; move16 ();
247
248 for (i = 0; i < M; i++) {
249 lsp[i] = add(shr(lsp_old[i], 2), sub(lsp_new[i], shr(lsp_new[i], 2)));
250 move16 ();
251 }
252
253 Lsp_Az(lsp, Az); /* Subframe 3 */
254
255 return;
256 }