Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <stdint.h>
34 : #include "options.h" /* Compilation switches */
35 : #include "cnst.h" /* Common constants */
36 : #include "rom_com.h" /* Static table prototypes */
37 : #include "prot_fx.h" /* Function prototypes */
38 :
39 : #ifdef _MSC_VER
40 : void E_LPC_isf_isp_conversion( const Word16 isf[], Word16 isp[], const Word16 m );
41 : #endif
42 :
43 : /*---------------------------------------------------------------------*
44 : * isf_dec_amr_wb()
45 : *
46 : * Decoding of ISF parameters in AMR-WB IO mode
47 : *---------------------------------------------------------------------*/
48 :
49 0 : void isf_dec_amr_wb_fx(
50 : Decoder_State *st, /* i/o: State structure */
51 : Word16 *Aq, /* Q12 o : quantized A(z) for 4 subframes */
52 : Word16 *isf_new, /* Qlog2(2.56) o : de-quantized ISF vector */
53 : Word16 *isp_new /* Q15 o : de-quantized ISP vector */
54 : )
55 : {
56 : Word16 i;
57 : Word16 indice[7];
58 : Word32 L_tmp;
59 :
60 0 : set16_fx( indice, -1, 7 );
61 :
62 : /*---------------------------------*
63 : * ISF de-quantization of SID frames
64 : *---------------------------------*/
65 :
66 0 : IF( EQ_32( st->core_brate, SID_1k75 ) )
67 : {
68 :
69 0 : indice[0] = (Word16) get_next_indice_fx( st, 6 );
70 0 : move16();
71 0 : indice[1] = (Word16) get_next_indice_fx( st, 6 );
72 0 : move16();
73 0 : indice[2] = (Word16) get_next_indice_fx( st, 6 );
74 0 : move16();
75 0 : indice[3] = (Word16) get_next_indice_fx( st, 5 );
76 0 : move16();
77 0 : indice[4] = (Word16) get_next_indice_fx( st, 5 );
78 0 : move16();
79 :
80 0 : disf_ns_28b_fx( indice, isf_new );
81 :
82 0 : reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 );
83 :
84 0 : E_LPC_isf_isp_conversion( isf_new, isp_new, M );
85 : /* return if SID frame (conversion to A(z) done in the calling function) */
86 0 : return;
87 : }
88 :
89 : /*-----------------------------------------------------------------*
90 : * ISF de-quantization of all other frames
91 : *-----------------------------------------------------------------*/
92 :
93 0 : IF( EQ_32( st->core_brate, ACELP_6k60 ) )
94 : {
95 0 : indice[0] = (Word16) get_next_indice_fx( st, 8 );
96 0 : move16();
97 0 : indice[1] = (Word16) get_next_indice_fx( st, 8 );
98 0 : move16();
99 0 : indice[2] = (Word16) get_next_indice_fx( st, 7 );
100 0 : move16();
101 0 : indice[3] = (Word16) get_next_indice_fx( st, 7 );
102 0 : move16();
103 0 : indice[4] = (Word16) get_next_indice_fx( st, 6 );
104 0 : move16();
105 :
106 0 : disf_2s_36b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 );
107 : }
108 : ELSE
109 : {
110 0 : indice[0] = (Word16) get_next_indice_fx( st, 8 );
111 0 : move16();
112 0 : indice[1] = (Word16) get_next_indice_fx( st, 8 );
113 0 : move16();
114 0 : indice[2] = (Word16) get_next_indice_fx( st, 6 );
115 0 : move16();
116 0 : indice[3] = (Word16) get_next_indice_fx( st, 7 );
117 0 : move16();
118 0 : indice[4] = (Word16) get_next_indice_fx( st, 7 );
119 0 : move16();
120 0 : indice[5] = (Word16) get_next_indice_fx( st, 5 );
121 0 : move16();
122 0 : indice[6] = (Word16) get_next_indice_fx( st, 5 );
123 0 : move16();
124 :
125 0 : disf_2s_46b_fx( indice, isf_new, st->mem_AR_fx, st->mem_MA_fx, 1 );
126 : }
127 0 : reorder_isf_fx( isf_new, ISF_GAP_FX, M, Fs_2 );
128 : /* convert quantized ISFs to ISPs */
129 0 : E_LPC_isf_isp_conversion( isf_new, isp_new, M );
130 :
131 : /*-------------------------------------------------------------------------------------*
132 : * FEC - update adaptive mean ISF vector
133 : *-------------------------------------------------------------------------------------*/
134 :
135 0 : FOR( i = 0; i < M; i++ )
136 : {
137 : /*st->lsf_adaptive_mean[i] = (st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i]) / 3;*/
138 0 : L_tmp = L_mult( st->lsfoldbfi1_fx[i], 10923 /*0.3333 in Q15*/ ); /*Q2.56+15+1*/
139 0 : L_tmp = L_mac( L_tmp, st->lsfoldbfi0_fx[i], 10923 /*0.3333 in Q15*/ ); /*Q2.56+15+1*/
140 0 : st->lsf_adaptive_mean_fx[i] = round_fx( L_mac( L_tmp, isf_new[i], 10923 /*0.3333 in Q15*/ ) ); /*Q2.56*/
141 : }
142 :
143 : /*-------------------------------------------------------------------------------------*
144 : * ISP interpolation
145 : * A(z) calculation
146 : *-------------------------------------------------------------------------------------*/
147 :
148 0 : IF( st->rate_switching_reset )
149 : {
150 : /*extrapolation instead of interpolation*/
151 0 : Copy( isp_new, st->lsp_old_fx, M );
152 0 : Copy( isf_new, st->lsf_old_fx, M );
153 : }
154 :
155 : /* ISP interpolation and A(z) calculation */
156 0 : int_lsp_fx( L_FRAME, st->lsp_old_fx, isp_new, Aq, M, interpol_isp_amr_wb_fx, 1 );
157 :
158 : /*------------------------------------------------------------------*
159 : * Check ISF stability : distance between old ISF and current ISF
160 : *------------------------------------------------------------------*/
161 :
162 0 : IF( st->element_mode == EVS_MONO )
163 : {
164 0 : st->stab_fac_fx = lsf_stab_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); /*Q15*/
165 0 : move16();
166 : }
167 : ELSE
168 : {
169 0 : st->stab_fac_fx = lsf_stab_ivas_fx( isf_new, st->lsf_old_fx, 1, st->L_frame ); /*Q15*/
170 0 : move16();
171 : }
172 :
173 0 : return;
174 : }
175 :
176 : /*-------------------------------------------------------------------*
177 : * disf_ns_28b()
178 : *
179 : * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode)
180 : *-------------------------------------------------------------------*/
181 :
182 0 : void disf_ns_28b_fx(
183 : Word16 *indice, /* Q0 / i : quantized indices (use indice[0] = -1 in the decoder) */
184 : Word16 *isf_q /* Q1 / o : ISF in the frequency domain (0..6400) */
185 : )
186 : {
187 : Word16 i;
188 :
189 0 : FOR( i = 0; i < 2; i++ )
190 : {
191 0 : isf_q[i] = dico1_ns_28b_fx[indice[0] * 2 + i]; /* Q1 */
192 0 : move16();
193 : }
194 :
195 0 : FOR( i = 0; i < 3; i++ )
196 : {
197 0 : isf_q[i + 2] = dico2_ns_28b_fx[indice[1] * 3 + i]; /* Q1 */
198 0 : move16();
199 0 : isf_q[i + 5] = dico3_ns_28b_fx[indice[2] * 3 + i]; /* Q1 */
200 0 : move16();
201 : }
202 :
203 0 : FOR( i = 0; i < 4; i++ )
204 : {
205 0 : isf_q[i + 8] = dico4_ns_28b_fx[indice[3] * 4 + i]; /* Q1 */
206 0 : move16();
207 0 : isf_q[i + 12] = dico5_ns_28b_fx[indice[4] * 4 + i]; /* Q1 */
208 0 : move16();
209 : }
210 :
211 0 : FOR( i = 0; i < M; i++ )
212 : {
213 0 : isf_q[i] = add( isf_q[i], mean_isf_noise_amr_wb_fx[i] ); /* Q1 */
214 0 : move16();
215 : }
216 :
217 0 : return;
218 : }
219 :
220 : /*-------------------------------------------------------------------*
221 : * disf_2s_46b()
222 : *
223 : * ISF de-quantizer for 46b. codebooks (only for AMR-WB IO mode)
224 : *-------------------------------------------------------------------*/
225 :
226 0 : void disf_2s_46b_fx(
227 : Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
228 : Word16 *isf_q, /* (Qx2.56) o : quantized ISFs in the cosine domain */
229 : Word16 *mem_AR, /* (Qx2.56) o : quantizer memory for AR model */
230 : Word16 *mem_MA, /* (Qx2.56) i/o: quantizer memory for MA model */
231 : const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */
232 : )
233 : {
234 : Word16 i;
235 :
236 0 : IF( enc_dec != 0 ) /* Redirection for G722.2 compatibility */
237 : {
238 0 : i = 0;
239 0 : move16();
240 0 : WHILE( NE_16( Indirect_dico1[i], indice[0] ) )
241 : {
242 0 : i = add( i, 1 );
243 : }
244 0 : indice[0] = i;
245 0 : move16();
246 : }
247 :
248 0 : FOR( i = 0; i < 9; i++ )
249 : {
250 0 : isf_q[i] = dico1_isf_fx[indice[0] * 9 + i]; /*(Qx2.56)*/
251 0 : move16();
252 : }
253 :
254 0 : FOR( i = 0; i < 7; i++ )
255 : {
256 0 : isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; /*(Qx2.56)*/
257 0 : move16();
258 : }
259 :
260 0 : FOR( i = 0; i < 3; i++ )
261 : {
262 0 : isf_q[i] = add( isf_q[i], dico21_isf_46b_fx[indice[2] * 3 + i] ); /*(Qx2.56)*/
263 0 : move16();
264 0 : isf_q[i + 3] = add( isf_q[i + 3], dico22_isf_46b_fx[indice[3] * 3 + i] ); /*(Qx2.56)*/
265 0 : move16();
266 0 : isf_q[i + 6] = add( isf_q[i + 6], dico23_isf_46b_fx[indice[4] * 3 + i] ); /*(Qx2.56)*/
267 0 : move16();
268 0 : isf_q[i + 9] = add( isf_q[i + 9], dico24_isf_46b_fx[indice[5] * 3 + i] ); /*(Qx2.56)*/
269 0 : move16();
270 : }
271 :
272 0 : FOR( i = 0; i < 4; i++ )
273 : {
274 0 : isf_q[i + 12] = add( isf_q[i + 12], dico25_isf_46b_fx[indice[6] * 4 + i] ); /*(Qx2.56)*/
275 0 : move16();
276 : }
277 :
278 0 : FOR( i = 0; i < M; i++ )
279 : {
280 0 : mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /*(Qx2.56)*/
281 0 : move16(); /* Update with quantized ISF vector for AR model */
282 0 : mem_MA[i] = isf_q[i];
283 0 : move16(); /* Update with quantized prediction error for MA model */
284 0 : isf_q[i] = add( mem_AR[i], mean_isf_amr_wb_fx[i] ); /*(Qx2.56)*/
285 0 : move16(); /* Quantized ISFs */
286 : }
287 :
288 0 : return;
289 : }
290 :
291 :
292 : /*-------------------------------------------------------------------*
293 : * disf_2s_36b()
294 : *
295 : * ISF de-quantizer for 36b. codebooks (only for AMR-WB IO mode)
296 : *-------------------------------------------------------------------*/
297 :
298 0 : void disf_2s_36b_fx(
299 : Word16 *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
300 : Word16 *isf_q, /* (Qx2.56) o : quantized ISFs in the cosine domain */
301 : Word16 *mem_AR, /* (Qx2.56) i/o: quantizer memory for AR model */
302 : Word16 *mem_MA, /* (Qx2.56) i/o: quantizer memory for MA model */
303 : const Word16 enc_dec /* i : encoder (0), decoder (1) G722.2 FER */
304 : )
305 : {
306 : Word16 i;
307 : const Word16 *pt_dico1;
308 :
309 0 : IF( enc_dec != 0 ) /* Redirection for G722.2 interoperability */
310 : {
311 0 : i = 0;
312 0 : move16();
313 0 : WHILE( NE_16( Indirect_dico1[i], indice[0] ) )
314 : {
315 0 : i = add( i, 1 );
316 : }
317 0 : indice[0] = i;
318 0 : move16();
319 : }
320 :
321 :
322 0 : pt_dico1 = dico1_isf_fx; /* Pointer of the 1st stage, 1st plit */
323 :
324 0 : FOR( i = 0; i < 9; i++ )
325 : {
326 0 : isf_q[i] = pt_dico1[indice[0] * 9 + i]; /*(Qx2.56)*/
327 0 : move16();
328 : }
329 :
330 0 : FOR( i = 0; i < 7; i++ )
331 : {
332 0 : isf_q[i + 9] = dico2_isf_fx[indice[1] * 7 + i]; /*(Qx2.56)*/
333 0 : move16();
334 : }
335 :
336 0 : FOR( i = 0; i < 5; i++ )
337 : {
338 0 : isf_q[i] = add( isf_q[i], dico21_isf_36b_fx[indice[2] * 5 + i] ); /*(Qx2.56)*/
339 0 : move16();
340 : }
341 :
342 0 : FOR( i = 0; i < 4; i++ )
343 : {
344 0 : isf_q[i + 5] = add( isf_q[i + 5], dico22_isf_36b_fx[indice[3] * 4 + i] ); /*(Qx2.56)*/
345 0 : move16();
346 : }
347 :
348 0 : FOR( i = 0; i < 7; i++ )
349 : {
350 0 : isf_q[i + 9] = add( isf_q[i + 9], dico23_isf_36b_fx[indice[4] * 7 + i] ); /*(Qx2.56)*/
351 0 : move16();
352 : }
353 :
354 0 : FOR( i = 0; i < M; i++ )
355 : {
356 0 : mem_AR[i] = add( isf_q[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /*(Qx2.56)*/
357 0 : move16(); /* Update with quantized ISF vector for AR model */
358 0 : mem_MA[i] = isf_q[i];
359 0 : move16(); /* Update with quantized prediction error for MA model */
360 0 : isf_q[i] = add( mem_AR[i], mean_isf_amr_wb_fx[i] ); /*(Qx2.56)*/
361 0 : move16(); /* Quantized ISFs */
362 : }
363 :
364 0 : return;
365 : }
|