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"
35 : #include "prot_fx.h"
36 : #include "ivas_prot_fx.h"
37 : #include "ivas_rom_com.h"
38 : #include "rom_com.h"
39 : #include "math.h"
40 : #include "wmc_auto.h"
41 :
42 :
43 : /*------------------------------------------------------------------------------------------*
44 : * Local constants
45 : *------------------------------------------------------------------------------------------*/
46 :
47 : /* Delay handling of LFE: overall_lfe_delay = max(11.5, BLOCK_OFFSET_MS); */
48 : #define BLOCK_OFFSET_MS 12
49 : #define BLOCK_OFFSET_S_Q15 393
50 :
51 :
52 : /*-----------------------------------------------------------------------------------------*
53 : * Function ivas_lfe_dec_delay_adjust_fx()
54 : *
55 : * Adjusts the input to be passed to filtering block taking into consideration
56 : * LFE delay calculated during initialization time
57 : *-----------------------------------------------------------------------------------------*/
58 :
59 53744 : static void ivas_lfe_dec_delay_adjust_fx(
60 : LFE_DEC_HANDLE hLFE,
61 : Word32 *pInbuf, // Q9
62 : Word32 output_lfe_ch[] // Q9
63 : )
64 : {
65 : Word16 i, diff, loop_counter;
66 : Word16 fade_len, dct_len, zero_pad_len;
67 : Word32 tmp_buffer[L_FRAME48k];
68 :
69 53744 : diff = sub( hLFE->lfe_prior_buf_len, hLFE->pWindow_state->fade_len ); // Q0
70 53744 : IF( diff < 0 )
71 : {
72 0 : loop_counter = 0;
73 : }
74 : ELSE
75 : {
76 53744 : loop_counter = diff;
77 : }
78 53744 : move16();
79 53744 : fade_len = hLFE->pWindow_state->fade_len; // Q0
80 53744 : move16();
81 53744 : dct_len = hLFE->pWindow_state->dct_len; // Q0
82 53744 : move16();
83 53744 : zero_pad_len = hLFE->pWindow_state->zero_pad_len; // Q0
84 53744 : move16();
85 :
86 53744 : FOR( i = 0; i < loop_counter; i++ )
87 : {
88 0 : tmp_buffer[i] = hLFE->prior_out_buffer_fx[i]; // Q9
89 0 : move32();
90 : }
91 :
92 19648752 : FOR( i = 0; i < fade_len; i++ )
93 : {
94 19595008 : tmp_buffer[i + loop_counter] = L_add( hLFE->prior_out_buffer_fx[i + loop_counter], pInbuf[i] ); // Q9
95 19595008 : move32();
96 : }
97 53744 : loop_counter = add( loop_counter, fade_len );
98 :
99 24547504 : FOR( i = 0; i < fade_len + ( zero_pad_len << 1 ); i++ )
100 : {
101 24493760 : tmp_buffer[i + loop_counter] = pInbuf[i + fade_len];
102 24493760 : move32();
103 : }
104 :
105 19648752 : FOR( i = 0; i < hLFE->lfe_prior_buf_len; i++ )
106 : {
107 19595008 : hLFE->prior_out_buffer_fx[i] = tmp_buffer[i + dct_len];
108 19595008 : move32();
109 : }
110 :
111 24547504 : FOR( i = 0; i < dct_len; i++ )
112 : {
113 24493760 : output_lfe_ch[i] = tmp_buffer[i];
114 24493760 : move32();
115 : }
116 :
117 53744 : return;
118 : }
119 :
120 :
121 : /*-----------------------------------------------------------------------------------------*
122 : * Function ivas_lfe_dec_windowing_fx()
123 : *
124 : * LFE windowing block, input is passed through Fielder window
125 : *-----------------------------------------------------------------------------------------*/
126 :
127 53744 : static void ivas_lfe_dec_windowing_fx(
128 : LFE_DEC_HANDLE hLFE,
129 : Word32 *pInbuf // Q9
130 : )
131 : {
132 : Word16 i;
133 : Word16 fade_len;
134 : Word16 zero_pad_len;
135 : const Word32 *pWindow_coeffs;
136 :
137 53744 : fade_len = hLFE->pWindow_state->fade_len;
138 53744 : move16();
139 53744 : zero_pad_len = hLFE->pWindow_state->zero_pad_len;
140 53744 : move16();
141 53744 : pWindow_coeffs = hLFE->pWindow_state->pWindow_coeffs_fx; // Q31
142 :
143 19648752 : FOR( i = 0; i < fade_len; i++ )
144 : {
145 19595008 : pInbuf[i] = Mpy_32_32( pInbuf[zero_pad_len + i], pWindow_coeffs[i] );
146 19595008 : pInbuf[i] = Mpy_32_32( pInbuf[zero_pad_len + i], pWindow_coeffs[i] ); // Q9
147 19595008 : move32();
148 : }
149 :
150 4952496 : FOR( i = 0; i < zero_pad_len * 2; i++ )
151 : {
152 4898752 : pInbuf[fade_len + i] = pInbuf[zero_pad_len + fade_len + i];
153 4898752 : move32();
154 : }
155 :
156 19648752 : FOR( i = 0; i < fade_len; i++ )
157 : {
158 19595008 : pInbuf[zero_pad_len * 2 + fade_len + i] = Mpy_32_32( pInbuf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1] ); // Q9
159 19595008 : move32();
160 : }
161 :
162 53744 : return;
163 : }
164 :
165 :
166 : /*-----------------------------------------------------------------------------------------*
167 : * Function ivas_lfe_dec_dequant_fx()
168 : *
169 : * LDE de-quatization block, calls arithmetic deccoding block inside
170 : *-----------------------------------------------------------------------------------------*/
171 :
172 26721 : static Word16 ivas_lfe_dec_dequant_fx(
173 : LFE_DEC_HANDLE hLFE,
174 : Decoder_State *st0,
175 : Word32 *pOut_buf, // Q24
176 : Word16 *num_dct_pass_bins )
177 : {
178 : Word16 shift_bits, i;
179 : Word16 quant_strategy;
180 : Word16 coding_strategy;
181 : Word16 base2_bit_size;
182 : Word16 lfe_bits;
183 : Word16 all_zeros_dct;
184 : Word16 min_shift_bits;
185 : Word16 shift;
186 : Word16 sign_bits[IVAS_LFE_MAX_NUM_DCT_COEFFS];
187 : Word16 abs_values[IVAS_LFE_MAX_NUM_DCT_COEFFS];
188 : Word16 values[IVAS_LFE_MAX_NUM_DCT_COEFFS];
189 : Word16 num_dct_coeffs, num_groups;
190 :
191 26721 : all_zeros_dct = get_next_indice_fx( st0, 1 );
192 26721 : lfe_bits = st0->next_bit_pos;
193 26721 : move16();
194 26721 : shift_bits = IVAS_LFE_SHIFT_BITS;
195 26721 : move16();
196 26721 : min_shift_bits = 0;
197 26721 : move16();
198 26721 : shift = 0;
199 26721 : move16();
200 :
201 26721 : IF( EQ_16( all_zeros_dct, 1 ) )
202 : {
203 387515 : FOR( i = 0; i < IVAS_LFE_MAX_NUM_DCT_COEFFS; i++ )
204 : {
205 364720 : pOut_buf[i] = 0;
206 364720 : move32();
207 : }
208 : }
209 : ELSE
210 : {
211 : Word32 two_pow_shift_by_4;
212 : Tastat as;
213 : Word16 iii, extra_bits_read;
214 :
215 3926 : extra_bits_read = 0;
216 3926 : move16();
217 3926 : quant_strategy = get_next_indice_fx( st0, 1 );
218 3926 : *num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy];
219 3926 : move16();
220 3926 : num_dct_coeffs = shl( *num_dct_pass_bins, 1 );
221 3926 : num_groups = shr( num_dct_coeffs, 2 );
222 3926 : min_shift_bits = ivas_lfe_min_shift_tbl[quant_strategy];
223 3926 : move16();
224 3926 : shift = add( get_next_indice_fx( st0, shift_bits ), shl( min_shift_bits, 2 ) );
225 :
226 66742 : FOR( i = 0; i < num_dct_coeffs; i++ )
227 : {
228 62816 : sign_bits[i] = get_next_indice_fx( st0, 1 );
229 62816 : move16();
230 : }
231 :
232 3926 : coding_strategy = get_next_indice_fx( st0, 1 );
233 :
234 3926 : IF( coding_strategy )
235 : {
236 2035 : FOR( iii = 0; iii < num_groups; iii++ )
237 : {
238 1628 : base2_bit_size = hLFE->lfe_dec_indices_coeffs_tbl[quant_strategy][iii];
239 1628 : move16();
240 8140 : FOR( i = 0; i < 4; i++ )
241 : {
242 6512 : abs_values[iii * 4 + i] = get_next_indice_fx( st0, base2_bit_size );
243 6512 : move16();
244 : }
245 : }
246 : }
247 : ELSE
248 : {
249 17595 : FOR( iii = 0; iii < num_groups; iii++ )
250 : {
251 14076 : extra_bits_read = 0;
252 14076 : move16();
253 14076 : ivas_ari_start_decoding_14bits_ext_1_lfe( st0, &as, &extra_bits_read );
254 :
255 70380 : FOR( i = 0; i < 4; i++ )
256 : {
257 56304 : abs_values[iii * 4 + i] = ivas_ari_decode_14bits_bit_ext_1_lfe( st0, &as, hLFE->cum_freq_models[quant_strategy][iii], &extra_bits_read );
258 56304 : move16();
259 : }
260 14076 : ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read );
261 : }
262 : }
263 :
264 66742 : FOR( i = 0; i < num_dct_coeffs; i++ )
265 : {
266 62816 : values[i] = shl( abs_values[i], 9 ); // Q9
267 62816 : move16();
268 62816 : IF( sign_bits[i] > 0 )
269 : {
270 19792 : values[i] = shl( sub( negate( abs_values[i] ), 1 ), 9 ); // Q9
271 19792 : move16();
272 : }
273 : }
274 :
275 3926 : two_pow_shift_by_4 = tbl_two_pow_shift_by_4[shift];
276 3926 : move32();
277 :
278 19630 : FOR( i = 0; i < num_groups; i++ )
279 : {
280 15704 : pOut_buf[2 * i] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i] ); // Q30 + Q9 >> 15 = Q24
281 15704 : move32();
282 15704 : pOut_buf[2 * i + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 1] ); // Q30 + Q9 >> 15 = Q24
283 15704 : move32();
284 :
285 15704 : pOut_buf[2 * i + *num_dct_pass_bins] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 2] ); // Q30 + Q9 >> 15 = Q24
286 15704 : move32();
287 15704 : pOut_buf[2 * i + *num_dct_pass_bins + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 3] ); // Q30 + Q9 >> 15 = Q24
288 15704 : move32();
289 : }
290 : }
291 :
292 26721 : lfe_bits = sub( st0->next_bit_pos, lfe_bits );
293 :
294 26721 : return lfe_bits;
295 : }
296 :
297 :
298 : /*-------------------------------------------------------------------------
299 : * ivas_create_lfe_lpf_dec_fx()
300 : *
301 : * Create, allocate and initialize IVAS decoder LFE low pass filter state handle
302 : *-------------------------------------------------------------------------*/
303 :
304 8 : static void ivas_create_lfe_lpf_dec_fx(
305 : ivas_filters_process_state_t *hLfeLpf, /* o : LFE LPF handle */
306 : const Word32 input_Fs /* i : input sampling rate */
307 : )
308 : {
309 : const Word32 *filt_coeff; // 31 - filt_coeff_e
310 8 : const Word16 *filt_coeff_e = NULL;
311 :
312 8 : ivas_lfe_lpf_select_filt_coeff_fx( input_Fs, IVAS_FILTER_ORDER_4, &filt_coeff, &filt_coeff_e );
313 8 : ivas_filters_init_fx( hLfeLpf, filt_coeff, filt_coeff_e, IVAS_FILTER_ORDER_4 );
314 :
315 8 : return;
316 : }
317 :
318 : /*-----------------------------------------------------------------------------------------*
319 : * Function ivas_lfe_dec_fx()
320 : *
321 : * LFE channel decoder
322 : *-----------------------------------------------------------------------------------------*/
323 :
324 26872 : void ivas_lfe_dec_fx(
325 : LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */
326 : Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/
327 : const Word16 output_frame, /* i : output frame length per channel */
328 : const Word16 bfi, /* i : BFI flag */
329 : Word32 output_lfe_ch[] /* o : output LFE synthesis Q9*/
330 : )
331 : {
332 : Word16 num_dct_pass_bins;
333 26872 : Word16 i, j, dct_len, q_out = 0;
334 26872 : move16();
335 : Word32 out[L_FRAME48k]; // Q9
336 : Word32 t_audio[L_FRAME48k]; // Q24
337 : Word32 lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS]; // Q24
338 :
339 26872 : dct_len = hLFE->pWindow_state->dct_len;
340 26872 : move16();
341 26872 : num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS;
342 26872 : move16();
343 :
344 26872 : IF( bfi == 0 )
345 : {
346 26721 : ivas_lfe_dec_dequant_fx( hLFE, st0, lfe_dct, &num_dct_pass_bins ); // Q24
347 :
348 26721 : set32_fx( t_audio, 0, dct_len );
349 26721 : Copy32( lfe_dct, t_audio, num_dct_pass_bins ); // Q24
350 26721 : q_out = Q24;
351 26721 : move16();
352 26721 : ivas_imdct_fx( t_audio, out, dct_len, &q_out ); // Q9
353 26721 : ivas_lfe_dec_windowing_fx( hLFE, out ); // Q9
354 26721 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch ); // Q9
355 :
356 26721 : set32_fx( t_audio, 0, dct_len );
357 26721 : Copy32( &lfe_dct[num_dct_pass_bins], t_audio, num_dct_pass_bins ); // Q24
358 26721 : q_out = Q24;
359 26721 : move16();
360 26721 : ivas_imdct_fx( t_audio, out, dct_len, &q_out ); // Q9
361 26721 : ivas_lfe_dec_windowing_fx( hLFE, out ); // Q9
362 26721 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch + dct_len ); // Q9
363 :
364 26721 : Copy32( hLFE->prevsynth_buf_fx + L_FRAME_1k6, hLFE->prevsynth_buf_fx, LFE_PLC_BUFLEN - L_FRAME_1k6 );
365 :
366 26721 : j = 0;
367 26721 : move16();
368 881793 : FOR( i = 0; i < L_FRAME_1k6; i++ )
369 : {
370 855072 : hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j]; // Q9
371 855072 : move32();
372 855072 : j = add( j, shr( output_frame, 5 ) );
373 : }
374 :
375 26721 : hLFE->bfi_count = 0;
376 26721 : move16();
377 : }
378 : ELSE
379 : {
380 : /* note: in BFI branch, buffer 't_audio' is in time-domain ('wtda' signal) */
381 151 : hLFE->bfi_count = add( hLFE->bfi_count, 1 );
382 151 : move16();
383 151 : ivas_lfe_tdplc_fx( hLFE, hLFE->prevsynth_buf_fx, t_audio, output_frame );
384 :
385 151 : ivas_itda_fx( t_audio, out, dct_len );
386 151 : ivas_lfe_dec_windowing_fx( hLFE, out );
387 151 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch );
388 :
389 151 : ivas_itda_fx( t_audio + dct_len, out, dct_len );
390 151 : ivas_lfe_dec_windowing_fx( hLFE, out );
391 151 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch + dct_len );
392 :
393 151 : Copy32( hLFE->prevsynth_buf_fx + L_FRAME_1k6, hLFE->prevsynth_buf_fx, LFE_PLC_BUFLEN - L_FRAME_1k6 );
394 :
395 151 : j = 0;
396 151 : move16();
397 4983 : FOR( i = 0; i < L_FRAME_1k6; i++ )
398 : {
399 4832 : hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j];
400 4832 : move32();
401 4832 : j = add( j, shr( output_frame, 5 ) );
402 : }
403 151 : q_out = Q9;
404 : }
405 :
406 26872 : IF( hLFE->filter_state.order > 0 )
407 : {
408 : /* Low Pass Filter */
409 330 : ivas_filter_process_fx( &hLFE->filter_state, output_lfe_ch, output_frame, q_out );
410 : }
411 :
412 : /* add delay to make overall max(block_offset, 11.5) */
413 26872 : IF( hLFE->lfe_addl_delay > 0 )
414 : {
415 26872 : delay_signal32_fx( output_lfe_ch, output_frame, hLFE->lfe_delay_buf_fx, hLFE->lfe_addl_delay );
416 : }
417 :
418 26872 : return;
419 : }
420 :
421 :
422 : /*-------------------------------------------------------------------------
423 : * ivas_create_lfe_dec()
424 : *
425 : * Create, allocate and initialize IVAS decoder LFE handle
426 : *-------------------------------------------------------------------------*/
427 :
428 354 : ivas_error ivas_create_lfe_dec_fx(
429 : LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */
430 : const Word32 output_Fs, /* i : output sampling rate Q0*/
431 : const Word32 delay_ns /* i : additional LFE delay to sync other channel outputs */
432 : )
433 : {
434 : Word16 low_pass_delay_dec_out, block_offset_s;
435 : Word16 filt_order, output_frame;
436 : LFE_DEC_HANDLE hLFE;
437 : Word16 i, j;
438 : Word16 lfe_block_delay_s_fx;
439 : Word16 block_offset_samples, lfe_block_delay_samples;
440 : Word16 lfe_addl_delay_samples;
441 : Word32 output_fs_fx;
442 :
443 354 : low_pass_delay_dec_out = 0;
444 354 : move16();
445 354 : block_offset_s = 0;
446 354 : move16();
447 :
448 354 : output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) );
449 :
450 : /*-----------------------------------------------------------------*
451 : * Allocate LFE handle
452 : *-----------------------------------------------------------------*/
453 :
454 354 : IF( ( hLFE = (LFE_DEC_HANDLE) malloc( sizeof( LFE_DEC_DATA ) ) ) == NULL )
455 : {
456 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) );
457 : }
458 :
459 : /*-----------------------------------------------------------------*
460 : * LFE Window: allocate and initialize
461 : *-----------------------------------------------------------------*/
462 :
463 354 : IF( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL )
464 : {
465 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) );
466 : }
467 :
468 354 : ivas_lfe_window_init_fx( hLFE->pWindow_state, output_Fs, output_frame );
469 :
470 : /* Initialization for entropy coding */
471 354 : hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1;
472 354 : hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2;
473 354 : hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3;
474 354 : hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4;
475 354 : hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1;
476 354 : hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2;
477 354 : hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3;
478 354 : hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4;
479 :
480 : /* delay calculation */
481 354 : lfe_block_delay_s_fx = add( IVAS_LFE_FADE_S_Q15, ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3] ); // Q15
482 354 : move16();
483 :
484 354 : block_offset_s = BLOCK_OFFSET_S_Q15; // Q15
485 354 : move16();
486 354 : filt_order = 0;
487 354 : move16();
488 354 : low_pass_delay_dec_out = 0; // Q15
489 354 : move16();
490 :
491 354 : if ( delay_ns > ivas_lfe_lpf_delay_ns[IVAS_FILTER_ORDER_4 - 3] )
492 : {
493 8 : filt_order = 4;
494 8 : low_pass_delay_dec_out = ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3];
495 8 : ivas_create_lfe_lpf_dec_fx( &( hLFE->filter_state ), output_Fs );
496 : }
497 :
498 354 : hLFE->filter_state.order = filt_order;
499 354 : move16();
500 354 : lfe_block_delay_s_fx = add( lfe_block_delay_s_fx, low_pass_delay_dec_out ); // Q15
501 354 : hLFE->lfe_prior_buf_len = NS2SA_FX2( output_Fs, IVAS_LFE_FADE_NS ); // Q0
502 354 : move16();
503 :
504 354 : hLFE->bfi_count = 0;
505 354 : move16();
506 :
507 354 : IF( NE_32( output_Fs, 48000 ) )
508 : {
509 82 : IF( NE_32( output_Fs, 32000 ) )
510 : {
511 70 : output_fs_fx = FS_16K_IN_NS_Q31; // Q31
512 : }
513 : ELSE
514 : {
515 12 : output_fs_fx = FS_32K_IN_NS_Q31;
516 : }
517 : }
518 : ELSE
519 : {
520 272 : output_fs_fx = FS_48K_IN_NS_Q31;
521 : }
522 354 : move32();
523 :
524 354 : block_offset_samples = (Word16) L_shr( imult3216( output_Fs, block_offset_s ), 15 ); // Q0
525 354 : block_offset_samples = add( block_offset_samples, (Word16) W_round64_L( W_mult0_32_32( L_shl( delay_ns, 1 ), output_fs_fx ) ) ); // Q0
526 354 : lfe_block_delay_samples = (Word16) L_shr( imult3216( output_Fs, lfe_block_delay_s_fx ), 15 ); // Q0
527 354 : lfe_addl_delay_samples = sub( block_offset_samples, lfe_block_delay_samples );
528 354 : lfe_addl_delay_samples = s_max( 0, lfe_addl_delay_samples );
529 354 : hLFE->lfe_addl_delay = lfe_addl_delay_samples;
530 354 : move16();
531 354 : hLFE->delay_ns = delay_ns;
532 354 : move32();
533 :
534 354 : IF( hLFE->lfe_addl_delay > 0 )
535 : {
536 354 : IF( ( hLFE->lfe_delay_buf_fx = (Word32 *) malloc( hLFE->lfe_addl_delay * sizeof( Word32 ) ) ) == NULL )
537 : {
538 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE additional delay buffer\n" ) );
539 : }
540 354 : set32_fx( (Word32 *) hLFE->lfe_delay_buf_fx, 0, hLFE->lfe_addl_delay );
541 : }
542 : ELSE
543 : {
544 0 : hLFE->lfe_delay_buf_fx = NULL;
545 : }
546 :
547 : /* Initialization base2 bits for each subgroup for no entropy coding */
548 1062 : FOR( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ )
549 : {
550 3540 : FOR( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ )
551 : {
552 2832 : hLFE->lfe_dec_indices_coeffs_tbl[i][j] = ivas_lfe_log2_num_ele_in_coder_models_fx[i][j];
553 2832 : move16();
554 : }
555 : }
556 :
557 354 : *hLFE_out = hLFE;
558 :
559 354 : return IVAS_ERR_OK;
560 : }
561 :
562 :
563 : /*-------------------------------------------------------------------------
564 : * ivas_lfe_dec_close_fx()
565 : *
566 : * Destroy IVAS decoder LFE handle
567 : *-------------------------------------------------------------------------*/
568 :
569 1210 : void ivas_lfe_dec_close_fx(
570 : LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */
571 : )
572 : {
573 1210 : test();
574 1210 : IF( hLFE == NULL || *hLFE == NULL )
575 : {
576 856 : return;
577 : }
578 :
579 354 : free( ( *hLFE )->pWindow_state );
580 354 : ( *hLFE )->pWindow_state = NULL;
581 :
582 354 : IF( ( *hLFE )->lfe_delay_buf_fx != NULL )
583 : {
584 354 : free( ( *hLFE )->lfe_delay_buf_fx );
585 354 : ( *hLFE )->lfe_delay_buf_fx = NULL;
586 : }
587 :
588 354 : free( ( *hLFE ) );
589 354 : ( *hLFE ) = NULL;
590 :
591 354 : return;
592 : }
|