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 : #include "cnst.h"
40 : #include "prot_fx.h"
41 : #include "rom_com.h"
42 : #include "wmc_auto.h"
43 : #include "ivas_prot_fx.h"
44 :
45 :
46 0 : void interleave_spectrum_fx(
47 : Word32 *coefs, /* i/o: input and output coefficients Q12 */
48 : const Word16 length /* i : length of spectrum Q0 */
49 : )
50 : {
51 : Word16 i, j, k;
52 : Word32 *p1, *p2, *p3, *p4;
53 : Word32 *p_out;
54 : Word32 coefs_out[L_FRAME48k];
55 0 : Word16 sublen[3] = { 240, 160, 80 };
56 : Word16 grps;
57 : const Word16 *bw;
58 : const Word16 *cnt;
59 :
60 0 : move16();
61 0 : move16();
62 0 : move16();
63 : /* Common inits */
64 0 : p1 = coefs; /*Q12*/
65 0 : p_out = coefs_out;
66 0 : IF( EQ_16( length, L_FRAME48k ) )
67 : {
68 0 : bw = intl_bw_48; /*Q0*/
69 0 : cnt = intl_cnt_48; /*Q0*/
70 0 : grps = N_INTL_GRP_48;
71 0 : move16();
72 0 : p2 = p1 + sublen[0];
73 0 : p3 = p2 + sublen[0];
74 0 : p4 = p3 + sublen[0];
75 : }
76 0 : ELSE IF( EQ_16( length, L_SPEC32k ) )
77 : {
78 0 : bw = intl_bw_32; /*Q0*/
79 0 : cnt = intl_cnt_32; /*Q0*/
80 0 : grps = N_INTL_GRP_32;
81 0 : move16();
82 0 : p2 = p1 + sublen[1];
83 0 : p3 = p2 + sublen[1];
84 0 : p4 = p3 + sublen[1];
85 : }
86 : ELSE /* length == L_SPEC16k */
87 : {
88 0 : bw = intl_bw_16; /*Q0*/
89 0 : cnt = intl_cnt_16; /*Q0*/
90 0 : grps = N_INTL_GRP_16;
91 0 : move16();
92 0 : p2 = p1 + sublen[2];
93 0 : p3 = p2 + sublen[2];
94 0 : p4 = p3 + sublen[2];
95 : }
96 :
97 0 : FOR( i = 0; i < grps; i++ )
98 : {
99 0 : FOR( j = 0; j < cnt[i]; j++ )
100 : {
101 0 : FOR( k = 0; k < bw[i]; k++ )
102 : {
103 0 : *p_out++ = *p1++; /*Q12*/
104 0 : move32();
105 : }
106 0 : FOR( k = 0; k < bw[i]; k++ )
107 : {
108 0 : *p_out++ = *p2++; /*Q12*/
109 0 : move32();
110 : }
111 0 : FOR( k = 0; k < bw[i]; k++ )
112 : {
113 0 : *p_out++ = *p3++; /*Q12*/
114 0 : move32();
115 : }
116 0 : FOR( k = 0; k < bw[i]; k++ )
117 : {
118 0 : *p_out++ = *p4++; /*Q12*/
119 0 : move32();
120 : }
121 : }
122 : }
123 :
124 : /* For FB the interleaved spectrum is 800 samples */
125 0 : Copy32( coefs_out, coefs, (Word16) ( p_out - coefs_out ) );
126 :
127 0 : return;
128 : }
129 :
130 0 : void interleave_spectrum_ivas_fx(
131 : Word32 *coefs, /* i/o: input and output coefficients Q12 */
132 : const Word16 length /* i : length of spectrum Q0 */
133 : )
134 : {
135 : Word16 i, j, k;
136 : Word32 *p1, *p2, *p3, *p4;
137 : Word32 *p_out;
138 : Word32 coefs_out[L_FRAME48k];
139 0 : Word16 sublen[3] = { 240, 160, 80 };
140 0 : move16();
141 0 : move16();
142 0 : move16();
143 : Word16 grps;
144 : const Word16 *bw;
145 : const Word16 *cnt;
146 :
147 : /* Common inits */
148 0 : p1 = coefs; /*Q12*/
149 0 : p_out = coefs_out;
150 :
151 0 : IF( EQ_16( length, L_SPEC48k ) )
152 : {
153 0 : bw = intl_bw_48; /*Q0*/
154 0 : cnt = intl_cnt_48; /*Q0*/
155 0 : grps = N_INTL_GRP_48;
156 0 : move16();
157 0 : p2 = p1 + sublen[0];
158 0 : p3 = p2 + sublen[0];
159 0 : p4 = p3 + sublen[0];
160 : }
161 0 : ELSE IF( EQ_16( length, L_SPEC32k ) )
162 : {
163 0 : bw = intl_bw_32; /*Q0*/
164 0 : cnt = intl_cnt_32; /*Q0*/
165 0 : grps = N_INTL_GRP_32;
166 0 : move16();
167 0 : p2 = p1 + sublen[1];
168 0 : p3 = p2 + sublen[1];
169 0 : p4 = p3 + sublen[1];
170 : }
171 : ELSE /* length == L_SPEC16k */
172 : {
173 0 : bw = intl_bw_16; /*Q0*/
174 0 : cnt = intl_cnt_16; /*Q0*/
175 0 : grps = N_INTL_GRP_16;
176 0 : move16();
177 0 : p2 = p1 + sublen[2];
178 0 : p3 = p2 + sublen[2];
179 0 : p4 = p3 + sublen[2];
180 : }
181 :
182 0 : FOR( i = 0; i < grps; i++ )
183 : {
184 0 : FOR( j = 0; j < cnt[i]; j++ )
185 : {
186 0 : FOR( k = 0; k < bw[i]; k++ )
187 : {
188 0 : *p_out++ = *p1++; /*Q12*/
189 0 : move32();
190 : }
191 0 : FOR( k = 0; k < bw[i]; k++ )
192 : {
193 0 : *p_out++ = *p2++; /*Q12*/
194 0 : move32();
195 : }
196 0 : FOR( k = 0; k < bw[i]; k++ )
197 : {
198 0 : *p_out++ = *p3++; /*Q12*/
199 0 : move32();
200 : }
201 0 : FOR( k = 0; k < bw[i]; k++ )
202 : {
203 0 : *p_out++ = *p4++; /*Q12*/
204 0 : move32();
205 : }
206 : }
207 : }
208 :
209 : /* For FB the interleaved spectrum is 800 samples */
210 0 : Copy32( coefs_out, coefs, (Word16) ( p_out - coefs_out ) );
211 :
212 0 : return;
213 : }
214 :
215 :
216 477 : void ivas_de_interleave_spectrum_fx(
217 : Word32 *coefs, /* i/o: input and output coefficients Q12 */
218 : const Word16 length /* i : length of spectrum Q0 */
219 : )
220 : {
221 : Word16 i, j, k;
222 : Word32 *p1, *p2, *p3, *p4;
223 : Word32 *p_in;
224 : Word32 coefs_out[L_FRAME48k];
225 477 : Word16 sublen[] = { 80, 160, 240, 320, 480, 720 };
226 477 : move16();
227 477 : move16();
228 477 : move16();
229 477 : move16();
230 477 : move16();
231 477 : move16();
232 : Word16 grps;
233 : Word16 l_frame;
234 : const Word16 *bw;
235 : const Word16 *cnt;
236 :
237 : /* common for all groups */
238 477 : p1 = coefs_out;
239 477 : l_frame = length;
240 477 : move16();
241 477 : IF( EQ_16( length, L_SPEC48k ) )
242 : {
243 360 : bw = intl_bw_48; /*Q0*/
244 360 : cnt = intl_cnt_48; /*Q0*/
245 360 : grps = N_INTL_GRP_48;
246 360 : move16();
247 360 : l_frame = L_FRAME48k;
248 360 : move16();
249 360 : p2 = coefs_out + sublen[2]; /* 240, length/4 */
250 360 : p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */
251 360 : p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */
252 : }
253 117 : ELSE IF( EQ_16( length, L_FRAME32k ) )
254 : {
255 98 : bw = intl_bw_32; /*Q0*/
256 98 : cnt = intl_cnt_32; /*Q0*/
257 98 : grps = N_INTL_GRP_32;
258 98 : move16();
259 :
260 98 : p2 = coefs_out + sublen[1]; /* 160 */
261 98 : p3 = coefs_out + sublen[3]; /* 320 */
262 98 : p4 = coefs_out + sublen[4]; /* 480 */
263 : }
264 : ELSE /* length == L_SPEC16k */
265 : {
266 19 : bw = intl_bw_16; /*Q0*/
267 19 : cnt = intl_cnt_16; /*Q0*/
268 19 : grps = N_INTL_GRP_16;
269 19 : move16();
270 :
271 19 : p2 = coefs_out + sublen[0]; /* 80 */
272 19 : p3 = coefs_out + sublen[1]; /* 160 */
273 19 : p4 = coefs_out + sublen[2]; /* 240 */
274 : }
275 :
276 477 : set32_fx( coefs_out, 0, L_FRAME48k );
277 477 : p_in = coefs; /*Q12*/
278 :
279 1791 : FOR( i = 0; i < grps; i++ )
280 : {
281 5433 : FOR( j = 0; j < cnt[i]; j++ )
282 : {
283 93319 : FOR( k = 0; k < bw[i]; k++ )
284 : {
285 89200 : *p1++ = *p_in++; /*Q12*/
286 89200 : move32();
287 : }
288 93319 : FOR( k = 0; k < bw[i]; k++ )
289 : {
290 89200 : *p2++ = *p_in++; /*Q12*/
291 89200 : move32();
292 : }
293 93319 : FOR( k = 0; k < bw[i]; k++ )
294 : {
295 89200 : *p3++ = *p_in++; /*Q12*/
296 89200 : move32();
297 : }
298 93319 : FOR( k = 0; k < bw[i]; k++ )
299 : {
300 89200 : *p4++ = *p_in++; /*Q12*/
301 89200 : move32();
302 : }
303 : }
304 : }
305 :
306 477 : Copy32( coefs_out, coefs, l_frame );
307 :
308 477 : return;
309 : }
310 :
311 35 : void de_interleave_spectrum_fx(
312 : Word32 *coefs, /* i/o: input and output coefficients Q12 */
313 : const Word16 length /* i : length of spectrum Q0 */
314 : )
315 : {
316 : Word16 i, j, k;
317 : Word32 *p1, *p2, *p3, *p4;
318 : Word32 *p_in;
319 : Word32 coefs_out[L_FRAME48k];
320 35 : Word16 sublen[] = { 80, 160, 240, 320, 480, 720 };
321 35 : move16();
322 35 : move16();
323 35 : move16();
324 35 : move16();
325 35 : move16();
326 35 : move16();
327 : Word16 grps;
328 : Word16 l_frame;
329 : const Word16 *bw;
330 : const Word16 *cnt;
331 :
332 : /* common for all groups */
333 35 : p1 = coefs_out;
334 35 : l_frame = length;
335 35 : move16();
336 35 : IF( EQ_16( length, L_FRAME48k ) )
337 : {
338 0 : bw = intl_bw_48; /*Q0*/
339 0 : cnt = intl_cnt_48; /*Q0*/
340 0 : grps = N_INTL_GRP_48;
341 0 : move16();
342 0 : p2 = coefs_out + sublen[2]; /* 240, length/4 */
343 0 : p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */
344 0 : p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */
345 : }
346 35 : ELSE IF( EQ_16( length, L_SPEC32k ) )
347 : {
348 35 : bw = intl_bw_32; /*Q0*/
349 35 : cnt = intl_cnt_32; /*Q0*/
350 35 : grps = N_INTL_GRP_32;
351 35 : move16();
352 :
353 35 : p2 = coefs_out + sublen[1]; /* 160 */
354 35 : p3 = coefs_out + sublen[3]; /* 320 */
355 35 : p4 = coefs_out + sublen[4]; /* 480 */
356 : }
357 : ELSE /* length == L_SPEC16k */
358 : {
359 0 : bw = intl_bw_16; /*Q0*/
360 0 : cnt = intl_cnt_16; /*Q0*/
361 0 : grps = N_INTL_GRP_16;
362 0 : move16();
363 :
364 0 : p2 = coefs_out + sublen[0]; /* 80 */
365 0 : p3 = coefs_out + sublen[1]; /* 160 */
366 0 : p4 = coefs_out + sublen[2]; /* 240 */
367 : }
368 :
369 35 : set32_fx( coefs_out, 0, L_FRAME48k );
370 35 : p_in = coefs; /*Q12*/
371 :
372 105 : FOR( i = 0; i < grps; i++ )
373 : {
374 350 : FOR( j = 0; j < cnt[i]; j++ )
375 : {
376 5880 : FOR( k = 0; k < bw[i]; k++ )
377 : {
378 5600 : *p1++ = *p_in++; /*Q12*/
379 5600 : move32();
380 : }
381 5880 : FOR( k = 0; k < bw[i]; k++ )
382 : {
383 5600 : *p2++ = *p_in++; /*Q12*/
384 5600 : move32();
385 : }
386 5880 : FOR( k = 0; k < bw[i]; k++ )
387 : {
388 5600 : *p3++ = *p_in++; /*Q12*/
389 5600 : move32();
390 : }
391 5880 : FOR( k = 0; k < bw[i]; k++ )
392 : {
393 5600 : *p4++ = *p_in++; /*Q12*/
394 5600 : move32();
395 : }
396 : }
397 : }
398 :
399 35 : Copy32( coefs_out, coefs, l_frame );
400 :
401 35 : return;
402 : }
|