comparison libtwamr/d_plsf_5.c @ 345:29769a9b89d3

libtwamr: integrate d_plsf_5.c
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Apr 2024 01:27:10 +0000
parents
children
comparison
equal deleted inserted replaced
344:05a46720af0f 345:29769a9b89d3
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_5.c
11 *
12 *****************************************************************************
13 */
14
15 /*
16 *****************************************************************************
17 * MODULE INCLUDE FILE AND VERSION ID
18 *****************************************************************************
19 */
20 #include "namespace.h"
21 #include "d_plsf.h"
22
23 /*
24 *****************************************************************************
25 * INCLUDE FILES
26 *****************************************************************************
27 */
28 #include "typedef.h"
29 #include "basic_op.h"
30 #include "no_count.h"
31 #include "lsp_lsf.h"
32 #include "reorder.h"
33 #include "cnst.h"
34 #include "memops.h"
35 #include "q_plsf5_tab.h"
36
37 /*
38 *****************************************************************************
39 * LOCAL VARIABLES AND TABLES
40 *****************************************************************************
41 */
42
43 /* ALPHA -> 0.95 */
44 /* ONE_ALPHA-> (1.0-ALPHA) */
45 #define ALPHA 31128
46 #define ONE_ALPHA 1639
47
48 /*
49 *--------------------------------------------------*
50 * Constants (defined in cnst.h) *
51 *--------------------------------------------------*
52 * M : LPC order
53 *--------------------------------------------------*
54 */
55
56 /*
57 *****************************************************************************
58 * PUBLIC PROGRAM CODE
59 *****************************************************************************
60 */
61 /*
62 **************************************************************************
63 *
64 * Function : D_plsf_5
65 * Purpose : Decodes the 2 sets of LSP parameters in a frame
66 * using the received quantization indices.
67 *
68 **************************************************************************
69 */
70 int D_plsf_5 (
71 D_plsfState *st, /* i/o: State variables */
72 Word16 bfi, /* i : bad frame indicator (set to 1 if a bad
73 frame is received) */
74 Word16 *indice, /* i : quantization indices of 5 submatrices, Q0 */
75 Word16 *lsp1_q, /* o : quantized 1st LSP vector (M), Q15 */
76 Word16 *lsp2_q /* o : quantized 2nd LSP vector (M), Q15 */
77 )
78 {
79 Word16 i;
80 const Word16 *p_dico;
81 Word16 temp, sign;
82 Word16 lsf1_r[M], lsf2_r[M];
83 Word16 lsf1_q[M], lsf2_q[M];
84
85 test ();
86 if (bfi != 0) /* if bad frame */
87 {
88 /* use the past LSFs slightly shifted towards their mean */
89
90 for (i = 0; i < M; i++)
91 {
92 /* lsfi_q[i] = ALPHA*st->past_lsf_q[i] + ONE_ALPHA*mean_lsf[i]; */
93
94 lsf1_q[i] = add (mult (st->past_lsf_q[i], ALPHA),
95 mult (mean_lsf[i], ONE_ALPHA));
96 move16 ();
97
98 lsf2_q[i] = lsf1_q[i]; move16 ();
99 }
100
101 /* estimate past quantized residual to be used in next frame */
102
103 for (i = 0; i < M; i++)
104 {
105 /* temp = mean_lsf[i] + st->past_r_q[i] * LSP_PRED_FAC_MR122; */
106
107 temp = add (mean_lsf[i], mult (st->past_r_q[i],
108 LSP_PRED_FAC_MR122));
109
110 st->past_r_q[i] = sub (lsf2_q[i], temp);
111 move16 ();
112 }
113 }
114 else
115 /* if good LSFs received */
116 {
117 /* decode prediction residuals from 5 received indices */
118
119 p_dico = &dico1_lsf[shl (indice[0], 2)];move16 ();
120 lsf1_r[0] = *p_dico++; move16 ();
121 lsf1_r[1] = *p_dico++; move16 ();
122 lsf2_r[0] = *p_dico++; move16 ();
123 lsf2_r[1] = *p_dico++; move16 ();
124
125 p_dico = &dico2_lsf[shl (indice[1], 2)];move16 ();
126 lsf1_r[2] = *p_dico++; move16 ();
127 lsf1_r[3] = *p_dico++; move16 ();
128 lsf2_r[2] = *p_dico++; move16 ();
129 lsf2_r[3] = *p_dico++; move16 ();
130
131 sign = indice[2] & 1; logic16 ();
132 i = shr (indice[2], 1);
133 p_dico = &dico3_lsf[shl (i, 2)]; move16 ();
134
135 test ();
136 if (sign == 0)
137 {
138 lsf1_r[4] = *p_dico++; move16 ();
139 lsf1_r[5] = *p_dico++; move16 ();
140 lsf2_r[4] = *p_dico++; move16 ();
141 lsf2_r[5] = *p_dico++; move16 ();
142 }
143 else
144 {
145 lsf1_r[4] = negate (*p_dico++); move16 ();
146 lsf1_r[5] = negate (*p_dico++); move16 ();
147 lsf2_r[4] = negate (*p_dico++); move16 ();
148 lsf2_r[5] = negate (*p_dico++); move16 ();
149 }
150
151 p_dico = &dico4_lsf[shl (indice[3], 2)];move16 ();
152 lsf1_r[6] = *p_dico++; move16 ();
153 lsf1_r[7] = *p_dico++; move16 ();
154 lsf2_r[6] = *p_dico++; move16 ();
155 lsf2_r[7] = *p_dico++; move16 ();
156
157 p_dico = &dico5_lsf[shl (indice[4], 2)];move16 ();
158 lsf1_r[8] = *p_dico++; move16 ();
159 lsf1_r[9] = *p_dico++; move16 ();
160 lsf2_r[8] = *p_dico++; move16 ();
161 lsf2_r[9] = *p_dico++; move16 ();
162
163 /* Compute quantized LSFs and update the past quantized residual */
164 for (i = 0; i < M; i++)
165 {
166 temp = add (mean_lsf[i], mult (st->past_r_q[i],
167 LSP_PRED_FAC_MR122));
168 lsf1_q[i] = add (lsf1_r[i], temp);
169 move16 ();
170 lsf2_q[i] = add (lsf2_r[i], temp);
171 move16 ();
172 st->past_r_q[i] = lsf2_r[i]; move16 ();
173 }
174 }
175
176 /* verification that LSFs have minimum distance of LSF_GAP Hz */
177
178 Reorder_lsf (lsf1_q, LSF_GAP, M);
179 Reorder_lsf (lsf2_q, LSF_GAP, M);
180
181 Copy (lsf2_q, st->past_lsf_q, M);
182
183 /* convert LSFs to the cosine domain */
184
185 Lsf_lsp (lsf1_q, lsp1_q, M);
186 Lsf_lsp (lsf2_q, lsp2_q, M);
187
188 return 0;
189 }