comparison libgsmefr/d_plsf_5.c @ 63:6a623cb57d07

libgsmefr: d_plsf_5.c compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 26 Nov 2022 01:11:04 +0000
parents 49dd1ac8e75b
children d80e9f12a1d1
comparison
equal deleted inserted replaced
62:c87ccddf3fd1 63:6a623cb57d07
11 * 11 *
12 * See "q_plsf_5.c" for more details about the quantization procedure 12 * See "q_plsf_5.c" for more details about the quantization procedure
13 * 13 *
14 *************************************************************************/ 14 *************************************************************************/
15 15
16 #include "gsm_efr.h"
16 #include "typedef.h" 17 #include "typedef.h"
18 #include "namespace.h"
17 #include "basic_op.h" 19 #include "basic_op.h"
18 #include "count.h" 20 #include "no_count.h"
21 #include "codec.h"
19 #include "sig_proc.h" 22 #include "sig_proc.h"
23 #include "memops.h"
20 24
21 #include "q_plsf_5.tab" /* Codebooks of LSF prediction residual */ 25 #include "q_plsf_5.tab" /* Codebooks of LSF prediction residual */
22 26
23 #include "cnst.h" 27 #include "cnst.h"
24 #include "dtx.h" 28 #include "dtx.h"
29 #include "dec_state.h"
25 30
26 /* M ->order of linear prediction filter */ 31 /* M ->order of linear prediction filter */
27 /* LSF_GAP -> Minimum distance between LSF after quantization */ 32 /* LSF_GAP -> Minimum distance between LSF after quantization */
28 /* 50 Hz = 205 */ 33 /* 50 Hz = 205 */
29 /* PRED_FAC -> Prediction factor = 0.65 */ 34 /* PRED_FAC -> Prediction factor = 0.65 */
34 #define LSF_GAP 205 39 #define LSF_GAP 205
35 #define PRED_FAC 21299 40 #define PRED_FAC 21299
36 #define ALPHA 31128 41 #define ALPHA 31128
37 #define ONE_ALPHA 1639 42 #define ONE_ALPHA 1639
38 43
39 /* Past quantized prediction error */
40
41 Word16 past_r2_q[M];
42
43 /* Past dequantized lsfs */
44
45 Word16 past_lsf_q[M];
46
47 /* Reference LSF parameter vector (comfort noise) */
48
49 Word16 lsf_p_CN[M];
50
51 /* LSF memories for comfort noise interpolation */
52
53 Word16 lsf_old_CN[M], lsf_new_CN[M];
54
55 /* LSF parameter buffer */
56
57 extern Word16 lsf_old_rx[DTX_HANGOVER][M];
58
59 void D_plsf_5 ( 44 void D_plsf_5 (
45 struct EFR_decoder_state *st,
60 Word16 *indice, /* input : quantization indices of 5 submatrices */ 46 Word16 *indice, /* input : quantization indices of 5 submatrices */
61 Word16 *lsp1_q, /* output: quantized 1st LSP vector */ 47 Word16 *lsp1_q, /* output: quantized 1st LSP vector */
62 Word16 *lsp2_q, /* output: quantized 2nd LSP vector */ 48 Word16 *lsp2_q, /* output: quantized 2nd LSP vector */
63 Word16 bfi, /* input : bad frame indicator (set to 1 if a bad 49 Word16 bfi, /* input : bad frame indicator (set to 1 if a bad
64 frame is received) */ 50 frame is received) */
72 Word16 temp, sign; 58 Word16 temp, sign;
73 Word16 lsf1_r[M], lsf2_r[M]; 59 Word16 lsf1_r[M], lsf2_r[M];
74 Word16 lsf1_q[M], lsf2_q[M]; 60 Word16 lsf1_q[M], lsf2_q[M];
75 61
76 /* Update comfort noise LSF quantizer memory */ 62 /* Update comfort noise LSF quantizer memory */
77 test (); logic16 ();
78 if ((rxdtx_ctrl & RX_UPD_SID_QUANT_MEM) != 0) 63 if ((rxdtx_ctrl & RX_UPD_SID_QUANT_MEM) != 0)
79 { 64 {
80 update_lsf_p_CN (lsf_old_rx, lsf_p_CN); 65 update_lsf_p_CN (st->lsf_old_rx, st->lsf_p_CN);
81 } 66 }
82 /* Handle cases of comfort noise LSF decoding in which past 67 /* Handle cases of comfort noise LSF decoding in which past
83 valid SID frames are repeated */ 68 valid SID frames are repeated */
84 69
85 test (); logic16 ();
86 test (); logic16 ();
87 test (); logic16 ();
88 if (((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0) 70 if (((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0)
89 || ((rxdtx_ctrl & RX_INVALID_SID_FRAME) != 0) 71 || ((rxdtx_ctrl & RX_INVALID_SID_FRAME) != 0)
90 || ((rxdtx_ctrl & RX_LOST_SID_FRAME) != 0)) 72 || ((rxdtx_ctrl & RX_LOST_SID_FRAME) != 0))
91 { 73 {
92 74
93 test (); logic16 ();
94 if ((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0) 75 if ((rxdtx_ctrl & RX_NO_TRANSMISSION) != 0)
95 { 76 {
96 /* DTX active: no transmission. Interpolate LSF values in memory */ 77 /* DTX active: no transmission. Interpolate LSF values in memory */
97 interpolate_CN_lsf (lsf_old_CN, lsf_new_CN, lsf2_q, rx_dtx_state); 78 interpolate_CN_lsf (st->lsf_old_CN, st->lsf_new_CN, lsf2_q,
79 rx_dtx_state);
98 } 80 }
99 else 81 else
100 { /* Invalid or lost SID frame: use LSFs 82 { /* Invalid or lost SID frame: use LSFs
101 from last good SID frame */ 83 from last good SID frame */
102 for (i = 0; i < M; i++) 84 for (i = 0; i < M; i++)
103 { 85 {
104 lsf_old_CN[i] = lsf_new_CN[i]; move16 (); 86 st->lsf_old_CN[i] = st->lsf_new_CN[i];
105 lsf2_q[i] = lsf_new_CN[i]; move16 (); 87 lsf2_q[i] = st->lsf_new_CN[i];
106 past_r2_q[i] = 0; move16 (); 88 st->past_r2_q[i] = 0;
107 } 89 }
108 } 90 }
109 91
110 for (i = 0; i < M; i++) 92 for (i = 0; i < M; i++)
111 { 93 {
112 past_lsf_q[i] = lsf2_q[i]; move16 (); 94 st->past_lsf_q[i] = lsf2_q[i];
113 } 95 }
114 96
115 /* convert LSFs to the cosine domain */ 97 /* convert LSFs to the cosine domain */
116 Lsf_lsp (lsf2_q, lsp2_q, M); 98 Lsf_lsp (lsf2_q, lsp2_q, M);
117 99
118 return; 100 return;
119 } 101 }
120 102
121 test ();
122 if (bfi != 0) /* if bad frame */ 103 if (bfi != 0) /* if bad frame */
123 { 104 {
124 /* use the past LSFs slightly shifted towards their mean */ 105 /* use the past LSFs slightly shifted towards their mean */
125 106
126 for (i = 0; i < M; i++) 107 for (i = 0; i < M; i++)
127 { 108 {
128 /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */ 109 /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
129 110
130 lsf1_q[i] = add (mult (past_lsf_q[i], ALPHA), 111 lsf1_q[i] = add (mult (st->past_lsf_q[i], ALPHA),
131 mult (mean_lsf[i], ONE_ALPHA)); 112 mult (mean_lsf[i], ONE_ALPHA));
132 move16 (); 113
133 114 lsf2_q[i] = lsf1_q[i];
134 lsf2_q[i] = lsf1_q[i]; move16 ();
135 } 115 }
136 116
137 /* estimate past quantized residual to be used in next frame */ 117 /* estimate past quantized residual to be used in next frame */
138 118
139 for (i = 0; i < M; i++) 119 for (i = 0; i < M; i++)
140 { 120 {
141 /* temp = mean_lsf[i] + past_r2_q[i] * PRED_FAC; */ 121 /* temp = mean_lsf[i] + past_r2_q[i] * PRED_FAC; */
142 122
143 temp = add (mean_lsf[i], mult (past_r2_q[i], PRED_FAC)); 123 temp = add (mean_lsf[i], mult (st->past_r2_q[i], PRED_FAC));
144 124
145 past_r2_q[i] = sub (lsf2_q[i], temp); 125 st->past_r2_q[i] = sub (lsf2_q[i], temp);
146 move16 ();
147 } 126 }
148 } 127 }
149 else 128 else
150 /* if good LSFs received */ 129 /* if good LSFs received */
151 { 130 {
197 176
198 /* Compute quantized LSFs and update the past quantized residual */ 177 /* Compute quantized LSFs and update the past quantized residual */
199 /* Use lsf_p_CN as predicted LSF vector in case of no speech 178 /* Use lsf_p_CN as predicted LSF vector in case of no speech
200 activity */ 179 activity */
201 180
202 test (); logic16 ();
203 if ((rxdtx_ctrl & RX_SP_FLAG) != 0) 181 if ((rxdtx_ctrl & RX_SP_FLAG) != 0)
204 { 182 {
205 for (i = 0; i < M; i++) 183 for (i = 0; i < M; i++)
206 { 184 {
207 temp = add (mean_lsf[i], mult (past_r2_q[i], PRED_FAC)); 185 temp = add (mean_lsf[i], mult (st->past_r2_q[i], PRED_FAC));
208 lsf1_q[i] = add (lsf1_r[i], temp); 186 lsf1_q[i] = add (lsf1_r[i], temp);
209 move16 ();
210 lsf2_q[i] = add (lsf2_r[i], temp); 187 lsf2_q[i] = add (lsf2_r[i], temp);
211 move16 (); 188 st->past_r2_q[i] = lsf2_r[i];
212 past_r2_q[i] = lsf2_r[i]; move16 ();
213 } 189 }
214 } 190 }
215 else 191 else
216 { /* Valid SID frame */ 192 { /* Valid SID frame */
217 for (i = 0; i < M; i++) 193 for (i = 0; i < M; i++)
218 { 194 {
219 lsf2_q[i] = add (lsf2_r[i], lsf_p_CN[i]); 195 lsf2_q[i] = add (lsf2_r[i], st->lsf_p_CN[i]);
220 move16 ();
221 196
222 /* Use the dequantized values of lsf2 also for lsf1 */ 197 /* Use the dequantized values of lsf2 also for lsf1 */
223 lsf1_q[i] = lsf2_q[i]; move16 (); 198 lsf1_q[i] = lsf2_q[i];
224 199
225 past_r2_q[i] = 0; move16 (); 200 st->past_r2_q[i] = 0;
226 } 201 }
227 } 202 }
228 } 203 }
229 204
230 /* verification that LSFs have minimum distance of LSF_GAP Hz */ 205 /* verification that LSFs have minimum distance of LSF_GAP Hz */
231 206
232 Reorder_lsf (lsf1_q, LSF_GAP, M); 207 Reorder_lsf (lsf1_q, LSF_GAP, M);
233 Reorder_lsf (lsf2_q, LSF_GAP, M); 208 Reorder_lsf (lsf2_q, LSF_GAP, M);
234 209
235 test (); logic16 ();
236 if ((rxdtx_ctrl & RX_FIRST_SID_UPDATE) != 0) 210 if ((rxdtx_ctrl & RX_FIRST_SID_UPDATE) != 0)
237 { 211 {
238 for (i = 0; i < M; i++) 212 for (i = 0; i < M; i++)
239 { 213 {
240 lsf_new_CN[i] = lsf2_q[i]; move16 (); 214 st->lsf_new_CN[i] = lsf2_q[i];
241 } 215 }
242 } 216 }
243 test (); logic16 ();
244 if ((rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0) 217 if ((rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0)
245 { 218 {
246 for (i = 0; i < M; i++) 219 for (i = 0; i < M; i++)
247 { 220 {
248 lsf_old_CN[i] = lsf_new_CN[i]; move16 (); 221 st->lsf_old_CN[i] = st->lsf_new_CN[i];
249 lsf_new_CN[i] = lsf2_q[i]; move16 (); 222 st->lsf_new_CN[i] = lsf2_q[i];
250 } 223 }
251 } 224 }
252 test (); logic16 ();
253 if ((rxdtx_ctrl & RX_SP_FLAG) != 0) 225 if ((rxdtx_ctrl & RX_SP_FLAG) != 0)
254 { 226 {
255 /* Update lsf history with quantized LSFs 227 /* Update lsf history with quantized LSFs
256 when speech activity is present. If the current frame is 228 when speech activity is present. If the current frame is
257 a bad one, update with most recent good comfort noise LSFs */ 229 a bad one, update with most recent good comfort noise LSFs */
258 230
259 if (bfi==0) 231 if (bfi==0)
260 { 232 {
261 update_lsf_history (lsf1_q, lsf2_q, lsf_old_rx); 233 update_lsf_history (lsf1_q, lsf2_q, st->lsf_old_rx);
262 } 234 }
263 else 235 else
264 { 236 {
265 update_lsf_history (lsf_new_CN, lsf_new_CN, lsf_old_rx); 237 update_lsf_history (st->lsf_new_CN, st->lsf_new_CN, st->lsf_old_rx);
266 } 238 }
267 239
268 for (i = 0; i < M; i++) 240 for (i = 0; i < M; i++)
269 { 241 {
270 lsf_old_CN[i] = lsf2_q[i]; move16 (); 242 st->lsf_old_CN[i] = lsf2_q[i];
271 } 243 }
272 } 244 }
273 else 245 else
274 { 246 {
275 interpolate_CN_lsf (lsf_old_CN, lsf_new_CN, lsf2_q, rx_dtx_state); 247 interpolate_CN_lsf (st->lsf_old_CN, st->lsf_new_CN, lsf2_q,
248 rx_dtx_state);
276 } 249 }
277 250
278 for (i = 0; i < M; i++) 251 for (i = 0; i < M; i++)
279 { 252 {
280 past_lsf_q[i] = lsf2_q[i]; move16 (); 253 st->past_lsf_q[i] = lsf2_q[i];
281 } 254 }
282 255
283 /* convert LSFs to the cosine domain */ 256 /* convert LSFs to the cosine domain */
284 257
285 Lsf_lsp (lsf1_q, lsp1_q, M); 258 Lsf_lsp (lsf1_q, lsp1_q, M);