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 <math.h>
43 : #include "cnst.h"
44 : #include "rom_com.h"
45 : #include "prot.h"
46 : #include "wmc_auto.h"
47 :
48 : /*--------------------------------------------------------------------------
49 : * window_ola()
50 : *
51 : * Windowing, Overlap and Add
52 : *--------------------------------------------------------------------------*/
53 :
54 :
55 5381794 : void window_ola(
56 : const float *ImdctOut, /* i : input */
57 : float *auOut, /* o : output audio */
58 : float *OldauOut, /* i/o: audio from previous frame */
59 : const int16_t L, /* i : length */
60 : const int16_t right_mode,
61 : const int16_t left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */
62 : const int16_t use_bfi_win, /* i : use BFI windowing */
63 : const int16_t oldHqVoicing, /* i : previous HqVoicing */
64 : float *oldgapsynth /* i : previous gapsynth */
65 : )
66 : {
67 : int16_t i, decimate, decay;
68 : int16_t n, n16, windecay48, windecay16;
69 : float win_right[R2_48];
70 : float win_int_left[R1_16];
71 : float win_left[R1_48];
72 : float win_int_right[R2_16];
73 :
74 :
75 : float SS2[L_FRAME48k - NS2SA( 48000, N_ZERO_MDCT_NS )];
76 : float wret2[L_FRAME48k - NS2SA( 48000, N_ZERO_MDCT_NS )];
77 :
78 : float *paout;
79 :
80 :
81 5381794 : n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
82 5381794 : n16 = (int16_t) ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
83 5381794 : windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48;
84 5381794 : windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16;
85 5381794 : decimate = 1;
86 5381794 : decay = 0;
87 :
88 5381794 : tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L );
89 :
90 5381794 : if ( L == L_FRAME32k || L == L_FRAME16k )
91 : {
92 2555501 : decimate = 3;
93 2555501 : decay = 1;
94 : }
95 2826293 : else if ( L == L_FRAME8k )
96 : {
97 0 : decimate = 6;
98 0 : decay = 2;
99 : }
100 :
101 2826293 : else if ( L == 512 )
102 : {
103 760686 : windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
104 760686 : decimate = 1;
105 760686 : decay = 0;
106 : }
107 2065607 : else if ( L == 256 )
108 : {
109 200936 : windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
110 200936 : decimate = 2;
111 200936 : decay = 0;
112 : }
113 :
114 5381794 : paout = auOut - n;
115 :
116 5381794 : if ( use_bfi_win )
117 : {
118 24 : if ( L == L_FRAME32k )
119 : {
120 1932 : for ( i = 0; i < L / 2; i += 2 )
121 : {
122 1920 : wret2[L / 2 - n + i + 1] = win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
123 1920 : wret2[L / 2 - n + i] = win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
124 : }
125 :
126 852 : for ( i = n; i < L / 2; i += 2 )
127 : {
128 840 : wret2[i - n] = win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
129 840 : wret2[i + 1 - n] = win_int_left[L_FRAME16k - ( i / 2 ) - 1];
130 : }
131 : }
132 : else
133 : {
134 1932 : for ( i = 0; i < L / 2; i++ )
135 : {
136 1920 : wret2[i + L / 2 - n] = win_left[( L / 2 - i - 1 ) * decimate + decay];
137 : }
138 :
139 852 : for ( i = n; i < L / 2; i++ )
140 : {
141 840 : wret2[i - n] = win_left[( L - i ) * decimate - decay - 1];
142 : }
143 : }
144 24 : sinq( EVS_PI / ( 2 * ( L - n ) ), EVS_PI / ( 4 * ( L - n ) ), L - n, SS2 );
145 :
146 2544 : for ( i = n; i < L / 2; i++ )
147 : {
148 2520 : paout[i] = ImdctOut[L / 2 + i];
149 : }
150 :
151 5784 : for ( i = 0; i < L / 2; i++ )
152 : {
153 5760 : paout[L / 2 + i] = -ImdctOut[L - 1 - i];
154 : }
155 :
156 24 : if ( oldHqVoicing )
157 : {
158 0 : for ( i = 0; i < L - n; i++ )
159 : {
160 0 : auOut[i] = auOut[i] * SS2[i] + oldgapsynth[i + n] * ( SS2[L - n - i - 1] );
161 : }
162 : }
163 : else
164 : {
165 8304 : for ( i = 0; i < L - n; i++ )
166 : {
167 8280 : auOut[i] = auOut[i] * SS2[i] + OldauOut[i + n] * ( SS2[L - n - i - 1] ) / ( wret2[i] + 0.01f );
168 : }
169 : }
170 : }
171 :
172 5381794 : if ( L == L_FRAME32k )
173 : {
174 1870444 : if ( use_bfi_win == 0 )
175 : {
176 132800672 : for ( i = n; i < L / 2; i += 2 )
177 : {
178 130930240 : paout[i] = ImdctOut[L / 2 + i] * win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] + OldauOut[i];
179 130930240 : paout[i + 1] = ImdctOut[L / 2 + i + 1] * win_int_right[2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) - 1 - windecay16] + OldauOut[i + 1];
180 : }
181 :
182 132800672 : for ( i = 0; i < L / 2 - n; i += 2 )
183 : {
184 130930240 : paout[L / 2 + i + 1] = -ImdctOut[L - 1 - ( i + 1 )] * win_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - windecay48] + OldauOut[i + L / 2 + 1];
185 130930240 : paout[L / 2 + i] = -ImdctOut[L - 1 - i] * win_int_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - windecay16] + OldauOut[i + L / 2];
186 : }
187 :
188 170209312 : for ( i = L / 2 - n; i < L / 2; i += 2 )
189 : {
190 168338880 : paout[L / 2 + i + 1] = -ImdctOut[L - 1 - ( i + 1 )] + OldauOut[i + L / 2 + 1];
191 168338880 : paout[L / 2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i + L / 2];
192 : }
193 : }
194 :
195 301141484 : for ( i = 0; i < L / 2; i += 2 )
196 : {
197 299271040 : OldauOut[L / 2 + i + 1] = -ImdctOut[i + 1] * win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
198 299271040 : OldauOut[L / 2 + i] = -ImdctOut[i] * win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
199 : }
200 :
201 :
202 132801524 : for ( i = n; i < L / 2; i += 2 )
203 : {
204 130931080 : OldauOut[i] = -ImdctOut[L / 2 - 1 - i] * win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
205 130931080 : OldauOut[i + 1] = -ImdctOut[L / 2 - 1 - ( i + 1 )] * win_int_left[L_FRAME16k - ( i / 2 ) - 1];
206 : }
207 : }
208 : else
209 : {
210 3511350 : if ( use_bfi_win == 0 )
211 : {
212 :
213 539494646 : for ( i = n; i < L / 2; i++ )
214 : {
215 535983308 : paout[i] = ImdctOut[L / 2 + i] * win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] + OldauOut[i];
216 : }
217 :
218 539494646 : for ( i = 0; i < L / 2 - n; i++ )
219 : {
220 535983308 : paout[L / 2 + i] = -ImdctOut[L - 1 - i] * win_right[( 3 * L / 2 - 1 - i ) * decimate + decay - windecay48] + OldauOut[i + L / 2];
221 : }
222 :
223 692632734 : for ( i = L / 2 - n; i < L / 2; i++ )
224 : {
225 689121396 : paout[L / 2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i + L / 2];
226 : }
227 : }
228 :
229 1228617974 : for ( i = 0; i < L / 2; i++ )
230 : {
231 1225106624 : OldauOut[L / 2 + i] = -ImdctOut[i] * win_left[( L / 2 - i - 1 ) * decimate + decay];
232 : }
233 :
234 :
235 539495498 : for ( i = n; i < L / 2; i++ )
236 : {
237 535984148 : OldauOut[i] = -ImdctOut[L / 2 - 1 - i] * win_left[( L - i ) * decimate - decay - 1];
238 : }
239 : }
240 :
241 1031184190 : for ( i = 0; i < n; i++ )
242 : {
243 1025802396 : OldauOut[i] = -ImdctOut[L / 2 - 1 - i];
244 : }
245 1031184190 : for ( i = 0; i < n; i++ )
246 : {
247 1025802396 : paout[L + i] = OldauOut[i];
248 : }
249 :
250 5381794 : return;
251 : }
252 :
253 :
254 : /*-------------------------------------------------------------------*
255 : * window_ola_ext()
256 : *
257 : *
258 : *-------------------------------------------------------------------*/
259 :
260 4740 : void window_ola_ext(
261 : const float *ImdstOut, /* i : input */
262 : float *auOut, /* o : output audio */
263 : float *OldauOut, /* i/o: audio from previous frame */
264 : const int16_t L, /* i : length */
265 : const int16_t right_mode,
266 : const int16_t left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */
267 : const uint16_t kernel_type /* i : transform kernel type */
268 : )
269 : {
270 4740 : const float sign_left = ( kernel_type & 1 ? 1.f : -1.f );
271 4740 : const float sign_right = ( kernel_type >= MDCT_II ? -1.f : 1.f );
272 : int16_t i, decimate, decay;
273 : int16_t n, n16, windecay48, windecay16;
274 : float win_right[R2_48];
275 : float win_int_left[R1_16];
276 : float win_left[R1_48];
277 : float win_int_right[R2_16];
278 : float *paout;
279 :
280 4740 : n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
281 4740 : n16 = (int16_t) ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
282 4740 : windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48;
283 4740 : windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16;
284 4740 : decimate = 1;
285 4740 : decay = 0;
286 :
287 4740 : tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L );
288 :
289 4740 : if ( L == L_FRAME32k || L == L_FRAME16k )
290 : {
291 3060 : decimate = 3;
292 3060 : decay = 1;
293 : }
294 1680 : else if ( L == L_FRAME8k )
295 : {
296 0 : decimate = 6;
297 0 : decay = 2;
298 : }
299 :
300 1680 : else if ( L == 512 )
301 : {
302 1200 : windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
303 1200 : decimate = 1;
304 1200 : decay = 0;
305 : }
306 480 : else if ( L == 256 )
307 : {
308 0 : windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
309 0 : decimate = 2;
310 0 : decay = 0;
311 : }
312 :
313 4740 : paout = auOut - n;
314 :
315 4740 : if ( L == L_FRAME32k )
316 : {
317 66030 : for ( i = n; i < L / 2; i += 2 )
318 : {
319 65100 : paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] + OldauOut[i];
320 65100 : paout[i + 1] = sign_right * ImdstOut[L / 2 + i + 1] * win_int_right[2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) - 1 - windecay16] + OldauOut[i + 1];
321 : }
322 :
323 66030 : for ( i = 0; i < L / 2 - n; i += 2 )
324 : {
325 65100 : paout[L / 2 + i + 1] = -ImdstOut[L - 1 - ( i + 1 )] * win_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - windecay48] + OldauOut[i + L / 2 + 1];
326 65100 : paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_int_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - windecay16] + OldauOut[i + L / 2];
327 : }
328 :
329 84630 : for ( i = L / 2 - n; i < L / 2; i += 2 )
330 : {
331 83700 : paout[L / 2 + i + 1] = -ImdstOut[L - 1 - ( i + 1 )] + OldauOut[i + L / 2 + 1];
332 83700 : paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2];
333 : }
334 :
335 149730 : for ( i = 0; i < L / 2; i += 2 )
336 : {
337 148800 : OldauOut[L / 2 + i + 1] = sign_left * ImdstOut[i + 1] * win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
338 148800 : OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
339 : }
340 :
341 :
342 66030 : for ( i = n; i < L / 2; i += 2 )
343 : {
344 65100 : OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
345 65100 : OldauOut[i + 1] = -ImdstOut[L / 2 - 1 - ( i + 1 )] * win_int_left[L_FRAME16k - ( i / 2 ) - 1];
346 : }
347 : }
348 : else
349 : {
350 388110 : for ( i = n; i < L / 2; i++ )
351 : {
352 384300 : paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] + OldauOut[i];
353 : }
354 :
355 388110 : for ( i = 0; i < L / 2 - n; i++ )
356 : {
357 384300 : paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_right[( 3 * L / 2 - 1 - i ) * decimate + decay - windecay48] + OldauOut[i + L / 2];
358 : }
359 :
360 497910 : for ( i = L / 2 - n; i < L / 2; i++ )
361 : {
362 494100 : paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2];
363 : }
364 :
365 882210 : for ( i = 0; i < L / 2; i++ )
366 : {
367 878400 : OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_left[( L / 2 - i - 1 ) * decimate + decay];
368 : }
369 :
370 :
371 388110 : for ( i = n; i < L / 2; i++ )
372 : {
373 384300 : OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[( L - i ) * decimate - decay - 1];
374 : }
375 : }
376 :
377 666240 : for ( i = 0; i < n; i++ )
378 : {
379 661500 : OldauOut[i] = -ImdstOut[L / 2 - 1 - i];
380 : }
381 666240 : for ( i = 0; i < n; i++ )
382 : {
383 661500 : paout[L + i] = OldauOut[i];
384 : }
385 :
386 4740 : return;
387 : }
388 :
389 :
390 : /*---------------------------------------------------------------------*
391 : * core_switching_OLA()
392 : *
393 : * modify window after HQ core decoding
394 : * Overlap ACELP and HQ
395 : *---------------------------------------------------------------------*/
396 :
397 75 : void core_switching_OLA(
398 : const float *mem_over_hp, /* i : upsampling filter memory */
399 : const int16_t last_L_frame, /* i : last L_frame lengthture */
400 : const int32_t output_Fs, /* i : output sampling rate */
401 : float *synth, /* i/o: synthesized signal from HQ core */
402 : const float *synth_subfr_out, /* i : synthesized signal from ACELP core */
403 : float *synth_subfr_bwe, /* i : synthesized BWE from ACELP core */
404 : const int16_t output_frame, /* i : output frame length */
405 : const int16_t bwidth /* i : output bandwidth */
406 : )
407 : {
408 : int16_t i, L, Loverlapp, out_filt_length, filt_delay, decimate, decay;
409 : float tmp_buf_switch[SWITCH_MAX_GAP], tmp_buf_switch2[HQ_DELAY_COMP * HQ_DELTA_MAX + 2];
410 : float delta;
411 : const float *win, *win_int;
412 :
413 75 : win = window_48kHz;
414 75 : win_int = window_8_16_32kHz;
415 75 : decimate = 1;
416 75 : decay = 0;
417 :
418 75 : if ( output_frame == L_FRAME32k || output_frame == L_FRAME16k )
419 : {
420 15 : decimate = 3;
421 15 : decay = 1;
422 : }
423 60 : else if ( output_frame == L_FRAME8k )
424 : {
425 0 : decimate = 6;
426 0 : decay = 2;
427 : }
428 :
429 : /* set multiplication factor according to the sampling rate */
430 75 : delta = 1;
431 75 : if ( output_frame == L_FRAME16k )
432 : {
433 0 : delta = 2;
434 : }
435 75 : else if ( output_frame == L_FRAME32k )
436 : {
437 15 : delta = 4;
438 : }
439 60 : else if ( output_frame == L_FRAME48k )
440 : {
441 60 : delta = 6;
442 : }
443 :
444 75 : set_f( tmp_buf_switch, 0, SWITCH_MAX_GAP );
445 75 : set_f( tmp_buf_switch2, 0, HQ_DELAY_COMP * HQ_DELTA_MAX + 2 );
446 :
447 75 : Loverlapp = (int16_t) ( delta * SWITCH_OVERLAP_8k );
448 :
449 75 : mvr2r( synth_subfr_out, tmp_buf_switch, NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) ); /* copy 6.25 ms subframe */
450 :
451 : /* conversion from 12.8kHz to output_Fs */
452 75 : if ( last_L_frame == L_FRAME )
453 : {
454 : /* resample filter memory */
455 15 : if ( output_frame == L_FRAME8k )
456 : {
457 0 : mvr2r( synth_subfr_out + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), NS2SA( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */
458 : }
459 : else
460 : {
461 15 : out_filt_length = modify_Fs_intcub3m_sup( mem_over_hp + 2, NS2SA( 12800, DELAY_CLDFB_NS ), 12800, tmp_buf_switch2, output_Fs, &filt_delay );
462 :
463 45 : for ( i = 0; i < filt_delay; i++ )
464 : {
465 30 : tmp_buf_switch2[out_filt_length + i - filt_delay] = tmp_buf_switch2[out_filt_length - 1 - filt_delay];
466 : }
467 :
468 15 : if ( ( bwidth == NB && output_Fs >= 16000 ) || ( bwidth > NB && output_Fs > 16000 ) )
469 : {
470 : /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */
471 615 : for ( i = 0; i < out_filt_length; i++ )
472 : {
473 600 : float a = (float) i / out_filt_length;
474 600 : float b = 1.f - a;
475 :
476 600 : tmp_buf_switch[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i] = a * tmp_buf_switch2[i] + b * synth_subfr_out[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i];
477 : }
478 : }
479 : else
480 : {
481 : /* copy cubic resampled buffer (memory) */
482 0 : mvr2r( tmp_buf_switch2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), out_filt_length );
483 : }
484 : }
485 : }
486 : else
487 : {
488 60 : if ( output_frame == L_FRAME16k )
489 : {
490 : /* no resampling */
491 0 : mvr2r( mem_over_hp + 2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), NS2SA( output_Fs, DELAY_CLDFB_NS ) );
492 : }
493 : else
494 : {
495 60 : if ( output_frame == L_FRAME8k )
496 : {
497 0 : mvr2r( synth_subfr_out + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), NS2SA( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */
498 : }
499 : else
500 : {
501 : /* resample filter memory */
502 60 : out_filt_length = modify_Fs_intcub3m_sup( mem_over_hp + 2, NS2SA( 16000, DELAY_CLDFB_NS ), 16000, tmp_buf_switch2, output_Fs, &filt_delay );
503 :
504 180 : for ( i = 0; i < filt_delay; i++ )
505 : {
506 120 : tmp_buf_switch2[out_filt_length + i - filt_delay] = tmp_buf_switch2[out_filt_length - 1 - filt_delay];
507 : }
508 :
509 60 : if ( ( bwidth == NB && output_Fs >= 16000 ) || ( bwidth > NB && output_Fs > 16000 ) )
510 : {
511 : /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */
512 3660 : for ( i = 0; i < out_filt_length; i++ )
513 : {
514 3600 : float a = (float) i / out_filt_length;
515 3600 : float b = 1.f - a;
516 :
517 3600 : tmp_buf_switch[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i] = a * tmp_buf_switch2[i] + b * synth_subfr_out[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i];
518 : }
519 : }
520 : else
521 : {
522 : /* copy cubic resampled buffer (memory) */
523 0 : mvr2r( tmp_buf_switch2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), out_filt_length );
524 : }
525 : }
526 : }
527 : }
528 :
529 : /* Windowing for overlapadd */
530 75 : L = NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS + DELAY_CLDFB_NS ); /* 6.25 ms gap + 1.25 ms resamp */
531 :
532 75 : set_f( synth, 0, L - Loverlapp );
533 :
534 75 : if ( output_frame == L_FRAME32k )
535 : {
536 1065 : for ( i = 0; i < NS2SA( output_Fs, 10000000.0f - N_ZERO_MDCT_NS ); i += 2 )
537 : {
538 1050 : synth[L - Loverlapp + i] /= win[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) )];
539 1050 : synth[L - Loverlapp + i + 1] /= win_int[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) )];
540 : }
541 : }
542 : else
543 : {
544 12660 : for ( i = 0; i < NS2SA( output_Fs, 10000000.0f - N_ZERO_MDCT_NS ); i++ )
545 : {
546 12600 : synth[L - Loverlapp + i] /= win[( 3 * output_frame / 2 - 1 - i ) * decimate + decay - (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) )];
547 : }
548 : }
549 :
550 :
551 6375 : for ( i = 0; i < Loverlapp; i++ ) /* Windowing for overlapadd */
552 : {
553 6300 : synth[i + (int16_t) ( L - Loverlapp )] *= (float) sin( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
554 6300 : synth_subfr_bwe[i + (int16_t) ( L - Loverlapp ) - NS2SA( output_Fs, DELAY_CLDFB_NS )] *= (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) ) * (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
555 6300 : tmp_buf_switch[i + (int16_t) ( L - Loverlapp )] *= (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) ) * (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
556 : }
557 :
558 : /* overlap-add ACELP (tmp_buf_switch) + HQ (synth) */
559 4275 : for ( i = 0; i < NS2SA( output_Fs, DELAY_CLDFB_NS ); i++ )
560 : {
561 4200 : synth[i] += tmp_buf_switch[i];
562 : }
563 21075 : for ( i = NS2SA( output_Fs, DELAY_CLDFB_NS ); i < L; i++ )
564 : {
565 21000 : synth[i] += tmp_buf_switch[i] + synth_subfr_bwe[i - NS2SA( output_Fs, DELAY_CLDFB_NS )];
566 : }
567 :
568 75 : return;
569 : }
570 :
571 :
572 : /*-------------------------------------------------------------------*
573 : * sinq()
574 : *
575 : * Fast sinus generate sin(tmp*i+phi)
576 : *-------------------------------------------------------------------*/
577 :
578 711 : void sinq(
579 : const float tmp, /* i : sinus factor cos(tmp*i+phi) */
580 : const float phi, /* i : sinus phase cos(tmp*i+phi) */
581 : const int16_t N, /* i : size of output */
582 : float x[] /* o : output vector */
583 : )
584 : {
585 : float A;
586 : int16_t i;
587 :
588 711 : x[0] = (float) sin( phi );
589 711 : x[1] = (float) sin( tmp + phi );
590 711 : x[2] = (float) sin( 2 * tmp + phi );
591 :
592 711 : if ( fabs( (float) ( tmp ) ) > 0.0001f )
593 : {
594 711 : A = ( x[2] + x[0] ) / x[1];
595 : }
596 : else
597 : {
598 0 : A = 0;
599 : }
600 :
601 55383 : for ( i = 3; i < N; i++ )
602 : {
603 54672 : x[i] = A * x[i - 1] - x[i - 2];
604 : }
605 :
606 711 : return;
607 : }
|