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 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include "cnst.h"
43 : #include "rom_com.h"
44 : #include "prot.h"
45 : #include "wmc_auto.h"
46 :
47 : /*---------------------------------------------------------------------*
48 : * isf_dec_amr_wb()
49 : *
50 : * Decoding of ISF parameters in AMR-WB IO mode
51 : *---------------------------------------------------------------------*/
52 :
53 0 : void isf_dec_amr_wb(
54 : Decoder_State *st, /* i/o: State structure */
55 : float *Aq, /* o : quantized A(z) for 4 subframes */
56 : float *isf_new, /* o : de-quantized ISF vector */
57 : float *isp_new /* o : de-quantized ISP vector */
58 : )
59 : {
60 : int16_t i;
61 : int16_t indice[7];
62 :
63 0 : set_s( indice, -1, 7 );
64 :
65 : /*---------------------------------*
66 : * ISF de-quantization of SID frames
67 : *---------------------------------*/
68 :
69 0 : if ( st->core_brate == SID_1k75 )
70 : {
71 0 : indice[0] = get_next_indice( st, 6 );
72 0 : indice[1] = get_next_indice( st, 6 );
73 0 : indice[2] = get_next_indice( st, 6 );
74 0 : indice[3] = get_next_indice( st, 5 );
75 0 : indice[4] = get_next_indice( st, 5 );
76 :
77 0 : disf_ns_28b( indice, isf_new );
78 :
79 0 : reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 );
80 :
81 0 : isf2isp( isf_new, isp_new, M, INT_FS_12k8 );
82 :
83 : /* return if SID frame (conversion to A(z) done in the calling function) */
84 0 : return;
85 : }
86 :
87 : /*-----------------------------------------------------------------*
88 : * ISF de-quantization of all other frames
89 : *-----------------------------------------------------------------*/
90 :
91 0 : if ( st->core_brate == ACELP_6k60 )
92 : {
93 0 : indice[0] = get_next_indice( st, 8 );
94 0 : indice[1] = get_next_indice( st, 8 );
95 0 : indice[2] = get_next_indice( st, 7 );
96 0 : indice[3] = get_next_indice( st, 7 );
97 0 : indice[4] = get_next_indice( st, 6 );
98 :
99 0 : disf_2s_36b( indice, isf_new, st->mem_AR, st->mem_MA );
100 : }
101 : else
102 : {
103 0 : indice[0] = get_next_indice( st, 8 );
104 0 : indice[1] = get_next_indice( st, 8 );
105 0 : indice[2] = get_next_indice( st, 6 );
106 0 : indice[3] = get_next_indice( st, 7 );
107 0 : indice[4] = get_next_indice( st, 7 );
108 0 : indice[5] = get_next_indice( st, 5 );
109 0 : indice[6] = get_next_indice( st, 5 );
110 :
111 0 : disf_2s_46b( indice, isf_new, st->mem_AR, st->mem_MA );
112 : }
113 :
114 0 : reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 );
115 :
116 : /* convert quantized ISFs to ISPs */
117 0 : isf2isp( isf_new, isp_new, M, INT_FS_12k8 );
118 :
119 : /*-------------------------------------------------------------------------------------*
120 : * FEC - update adaptive mean ISF vector
121 : *-------------------------------------------------------------------------------------*/
122 :
123 0 : for ( i = 0; i < M; i++ )
124 : {
125 0 : st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i] ) / 3;
126 : }
127 :
128 : /*-------------------------------------------------------------------------------------*
129 : * ISP interpolation
130 : * A(z) calculation
131 : *-------------------------------------------------------------------------------------*/
132 :
133 0 : if ( st->rate_switching_reset )
134 : {
135 : /*extrapolation instead of interpolation*/
136 0 : mvr2r( isp_new, st->lsp_old, M );
137 0 : mvr2r( isf_new, st->lsf_old, M );
138 : }
139 :
140 : /* ISP interpolation and A(z) calculation */
141 0 : int_lsp( L_FRAME, st->lsp_old, isp_new, Aq, M, interpol_isp_amr_wb, 1 );
142 :
143 : /*------------------------------------------------------------------*
144 : * Check ISF stability : distance between old ISF and current ISF
145 : *------------------------------------------------------------------*/
146 :
147 0 : st->stab_fac = lsf_stab( isf_new, st->lsf_old, 1, st->L_frame );
148 :
149 0 : return;
150 : }
151 :
152 : /*-------------------------------------------------------------------*
153 : * disf_ns_28b()
154 : *
155 : * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode)
156 : *-------------------------------------------------------------------*/
157 :
158 0 : void disf_ns_28b( int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
159 : float *isf_q /* o : ISF in the frequency domain (0..6400) */
160 : )
161 : {
162 : int16_t i;
163 :
164 0 : for ( i = 0; i < 2; i++ )
165 : {
166 0 : isf_q[i] = dico1_ns_28b[indice[0] * 2 + i];
167 : }
168 :
169 0 : for ( i = 0; i < 3; i++ )
170 : {
171 0 : isf_q[i + 2] = dico2_ns_28b[indice[1] * 3 + i];
172 0 : isf_q[i + 5] = dico3_ns_28b[indice[2] * 3 + i];
173 : }
174 :
175 0 : for ( i = 0; i < 4; i++ )
176 : {
177 0 : isf_q[i + 8] = dico4_ns_28b[indice[3] * 4 + i];
178 0 : isf_q[i + 12] = dico5_ns_28b[indice[4] * 4 + i];
179 : }
180 :
181 0 : for ( i = 0; i < M; i++ )
182 : {
183 0 : isf_q[i] += mean_isf_noise_amr_wb[i];
184 : }
185 :
186 0 : return;
187 : }
188 :
189 : /*-------------------------------------------------------------------*
190 : * disf_2s_46b()
191 : *
192 : * ISF de-quantizer for 46b. codebooks (only for AMR-WB IO mode)
193 : *-------------------------------------------------------------------*/
194 :
195 0 : void disf_2s_46b(
196 : int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
197 : float *isf_q, /* o : quantized ISFs in the cosine domain */
198 : float *mem_AR, /* o : quantizer memory for AR model */
199 : float *mem_MA /* i/o: quantizer memory for MA model */
200 : )
201 : {
202 : int16_t i;
203 :
204 0 : for ( i = 0; i < 9; i++ )
205 : {
206 0 : isf_q[i] = dico1_isf[indice[0] * 9 + i];
207 : }
208 :
209 0 : for ( i = 0; i < 7; i++ )
210 : {
211 0 : isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
212 : }
213 :
214 0 : for ( i = 0; i < 3; i++ )
215 : {
216 0 : isf_q[i] += dico21_isf_46b[indice[2] * 3 + i];
217 0 : isf_q[i + 3] += dico22_isf_46b[indice[3] * 3 + i];
218 0 : isf_q[i + 6] += dico23_isf_46b[indice[4] * 3 + i];
219 0 : isf_q[i + 9] += dico24_isf_46b[indice[5] * 3 + i];
220 : }
221 :
222 0 : for ( i = 0; i < 4; i++ )
223 : {
224 0 : isf_q[i + 12] += dico25_isf_46b[indice[6] * 4 + i];
225 : }
226 :
227 0 : for ( i = 0; i < M; i++ )
228 : {
229 0 : mem_AR[i] = (float) ( isf_q[i] + MU_MA * mem_MA[i] ); /* Update with quantized ISF vector for AR model */
230 0 : mem_MA[i] = isf_q[i]; /* Update with quantized prediction error for MA model */
231 0 : isf_q[i] = mem_AR[i] + mean_isf_amr_wb[i]; /* Quantized ISFs */
232 : }
233 :
234 0 : return;
235 : }
236 :
237 :
238 : /*-------------------------------------------------------------------*
239 : * disf_2s_36b()
240 : *
241 : * ISF de-quantizer for 36b. codebooks (only for AMR-WB IO mode)
242 : *-------------------------------------------------------------------*/
243 :
244 0 : void disf_2s_36b(
245 : int16_t *indice, /* i : quantized indices (use indice[0] = -1 in the decoder) */
246 : float *isf_q, /* o : quantized ISFs in the cosine domain */
247 : float *mem_AR, /* i/o: quantizer memory for AR model */
248 : float *mem_MA /* i/o: quantizer memory for MA model */
249 : )
250 : {
251 : int16_t i;
252 : const float *pt_dico1;
253 :
254 0 : pt_dico1 = dico1_isf; /* Pointer of the 1st stage, 1st plit */
255 :
256 0 : for ( i = 0; i < 9; i++ )
257 : {
258 0 : isf_q[i] = pt_dico1[indice[0] * 9 + i];
259 : }
260 :
261 0 : for ( i = 0; i < 7; i++ )
262 : {
263 0 : isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
264 : }
265 :
266 0 : for ( i = 0; i < 5; i++ )
267 : {
268 0 : isf_q[i] += dico21_isf_36b[indice[2] * 5 + i];
269 : }
270 :
271 0 : for ( i = 0; i < 4; i++ )
272 : {
273 0 : isf_q[i + 5] += dico22_isf_36b[indice[3] * 4 + i];
274 : }
275 :
276 0 : for ( i = 0; i < 7; i++ )
277 : {
278 0 : isf_q[i + 9] += dico23_isf_36b[indice[4] * 7 + i];
279 : }
280 :
281 0 : for ( i = 0; i < M; i++ )
282 : {
283 0 : mem_AR[i] = (float) ( isf_q[i] + MU_MA * mem_MA[i] ); /* Update with quantized ISF vector for AR model */
284 0 : mem_MA[i] = isf_q[i]; /* Update with quantized prediction error for MA model */
285 0 : isf_q[i] = mem_AR[i] + mean_isf_amr_wb[i]; /* Quantized ISFs */
286 : }
287 :
288 0 : return;
289 : }
|