comparison libtwamr/d_plsf_3.c @ 344:05a46720af0f

libtwamr: integrate d_plsf_3.c
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Apr 2024 01:23:15 +0000
parents
children
comparison
equal deleted inserted replaced
343:3f574255c3aa 344:05a46720af0f
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 : d_plsf_3.c
11 * Purpose : Decodes the LSP parameters using the received
12 * quantization indices. 1st order MA prediction and
13 * split by 3 vector quantization (split-VQ)
14 *
15 ********************************************************************************
16 */
17
18 /*
19 ********************************************************************************
20 * MODULE INCLUDE FILE AND VERSION ID
21 ********************************************************************************
22 */
23 #include "namespace.h"
24 #include "d_plsf.h"
25
26 /*
27 ********************************************************************************
28 * INCLUDE FILES
29 ********************************************************************************
30 */
31 #include "typedef.h"
32 #include "basic_op.h"
33 #include "no_count.h"
34 #include "lsp_lsf.h"
35 #include "reorder.h"
36 #include "memops.h"
37 #include "q_plsf3_tab.h"
38
39 /*
40 ********************************************************************************
41 * LOCAL VARIABLES AND TABLES
42 ********************************************************************************
43 */
44
45 /* ALPHA -> 0.9 */
46 /* ONE_ALPHA-> (1.0-ALPHA) */
47
48 #define ALPHA 29491
49 #define ONE_ALPHA 3277
50
51 /*
52 ********************************************************************************
53 * PUBLIC PROGRAM CODE
54 ********************************************************************************
55 */
56 /*************************************************************************
57 *
58 * FUNCTION: D_plsf_3()
59 *
60 * PURPOSE: Decodes the LSP parameters using the received quantization
61 * indices.1st order MA prediction and split by 3 vector
62 * quantization (split-VQ)
63 *
64 *************************************************************************/
65
66 void D_plsf_3(
67 D_plsfState *st, /* i/o: State struct */
68 enum Mode mode, /* i : coder mode */
69 Word16 bfi, /* i : bad frame indicator (set to 1 if a */
70 /* bad frame is received) */
71 Word16 * indice, /* i : quantization indices of 3 submatrices, Q0 */
72 Word16 * lsp1_q /* o : quantized 1st LSP vector, Q15 */
73 )
74 {
75 Word16 i, index;
76 const Word16 *p_cb1, *p_cb2, *p_cb3, *p_dico;
77 Word16 temp;
78 Word16 lsf1_r[M];
79 Word16 lsf1_q[M];
80
81 test ();
82 if (bfi != 0) /* if bad frame */
83 {
84 /* use the past LSFs slightly shifted towards their mean */
85
86 for (i = 0; i < M; i++)
87 {
88 /* lsfi_q[i] = ALPHA*past_lsf_q[i] + ONE_ALPHA*mean_lsf3[i]; */
89
90 lsf1_q[i] = add(mult(st->past_lsf_q[i], ALPHA),
91 mult(mean_lsf3[i], ONE_ALPHA));
92 move16 ();
93 }
94
95 /* estimate past quantized residual to be used in next frame */
96 test();
97 if (sub(mode, MRDTX) != 0) {
98 for (i = 0; i < M; i++) {
99 /* temp = mean_lsf3[i] + past_r2_q[i] * PRED_FAC; */
100
101 temp = add(mean_lsf3[i], mult(st->past_r_q[i], pred_fac[i]));
102
103 st->past_r_q[i] = sub(lsf1_q[i], temp); move16 ();
104 }
105 } else {
106 for (i = 0; i < M; i++) {
107 /* temp = mean_lsf3[i] + past_r2_q[i]; */
108
109 temp = add(mean_lsf3[i], st->past_r_q[i]);
110 st->past_r_q[i] = sub(lsf1_q[i], temp); move16 ();
111 }
112 }
113 }
114 else /* if good LSFs received */
115 {
116 test (); test ();
117 if (sub (mode, MR475) == 0 || sub (mode, MR515) == 0)
118 { /* MR475, MR515 */
119 p_cb1 = dico1_lsf3; move16 ();
120 p_cb2 = dico2_lsf3; move16 ();
121 p_cb3 = mr515_3_lsf; move16 ();
122 }
123 else if (sub (mode, MR795) == 0)
124 { /* MR795 */
125 test();
126 p_cb1 = mr795_1_lsf; move16 ();
127 p_cb2 = dico2_lsf3; move16 ();
128 p_cb3 = dico3_lsf3; move16 ();
129 }
130 else
131 { /* MR59, MR67, MR74, MR102, MRDTX */
132 test();
133 p_cb1 = dico1_lsf3; move16 ();
134 p_cb2 = dico2_lsf3; move16 ();
135 p_cb3 = dico3_lsf3; move16 ();
136 }
137
138 /* decode prediction residuals from 3 received indices */
139
140 index = *indice++; move16 ();
141 p_dico = &p_cb1[add(index, add(index, index))]; move16 ();
142 lsf1_r[0] = *p_dico++; move16 ();
143 lsf1_r[1] = *p_dico++; move16 ();
144 lsf1_r[2] = *p_dico++; move16 ();
145
146 index = *indice++; move16 ();
147
148 test (); test ();
149 if ((sub (mode, MR475) == 0) || (sub (mode, MR515) == 0))
150 { /* MR475, MR515 only using every second entry */
151 index = shl(index,1);
152 }
153
154 p_dico = &p_cb2[add(index, add(index, index))]; move16 ();
155 lsf1_r[3] = *p_dico++; move16 ();
156 lsf1_r[4] = *p_dico++; move16 ();
157 lsf1_r[5] = *p_dico++; move16 ();
158
159 index = *indice++; move16 ();
160 p_dico = &p_cb3[shl(index, 2)]; move16 ();
161 lsf1_r[6] = *p_dico++; move16 ();
162 lsf1_r[7] = *p_dico++; move16 ();
163 lsf1_r[8] = *p_dico++; move16 ();
164 lsf1_r[9] = *p_dico++; move16 ();
165
166 /* Compute quantized LSFs and update the past quantized residual */
167
168 if (sub(mode, MRDTX) != 0)
169 for (i = 0; i < M; i++) {
170 temp = add(mean_lsf3[i], mult(st->past_r_q[i], pred_fac[i]));
171 lsf1_q[i] = add(lsf1_r[i], temp); move16 ();
172 st->past_r_q[i] = lsf1_r[i]; move16 ();
173 }
174 else
175 for (i = 0; i < M; i++) {
176 temp = add(mean_lsf3[i], st->past_r_q[i]);
177 lsf1_q[i] = add(lsf1_r[i], temp); move16 ();
178 st->past_r_q[i] = lsf1_r[i]; move16 ();
179 }
180 }
181
182 /* verification that LSFs has minimum distance of LSF_GAP Hz */
183
184 Reorder_lsf(lsf1_q, LSF_GAP, M);
185
186 Copy (lsf1_q, st->past_lsf_q, M);
187
188 /* convert LSFs to the cosine domain */
189
190 Lsf_lsp(lsf1_q, lsp1_q, M);
191
192 return;
193 }
194
195 void Init_D_plsf_3(D_plsfState *st, /* i/o: State struct */
196 Word16 index /* i : past_rq_init[] index [0, 7] */)
197 {
198 Copy(&past_rq_init[index * M], st->past_r_q, M);
199 }