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 50174 : 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 50174 : diff = sub( hLFE->lfe_prior_buf_len, hLFE->pWindow_state->fade_len ); // Q0
70 50174 : IF( diff < 0 )
71 : {
72 0 : loop_counter = 0;
73 : }
74 : ELSE
75 : {
76 50174 : loop_counter = diff;
77 : }
78 50174 : move16();
79 50174 : fade_len = hLFE->pWindow_state->fade_len; // Q0
80 50174 : move16();
81 50174 : dct_len = hLFE->pWindow_state->dct_len; // Q0
82 50174 : move16();
83 50174 : zero_pad_len = hLFE->pWindow_state->zero_pad_len; // Q0
84 50174 : move16();
85 :
86 50174 : 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 18336510 : FOR( i = 0; i < fade_len; i++ )
93 : {
94 18286336 : tmp_buffer[i + loop_counter] = L_add( hLFE->prior_out_buffer_fx[i + loop_counter], pInbuf[i] ); // Q9
95 18286336 : move32();
96 : }
97 50174 : loop_counter = add( loop_counter, fade_len );
98 :
99 22908094 : FOR( i = 0; i < fade_len + ( zero_pad_len << 1 ); i++ )
100 : {
101 22857920 : tmp_buffer[i + loop_counter] = pInbuf[i + fade_len];
102 22857920 : move32();
103 : }
104 :
105 18336510 : FOR( i = 0; i < hLFE->lfe_prior_buf_len; i++ )
106 : {
107 18286336 : hLFE->prior_out_buffer_fx[i] = tmp_buffer[i + dct_len];
108 18286336 : move32();
109 : }
110 :
111 22908094 : FOR( i = 0; i < dct_len; i++ )
112 : {
113 22857920 : output_lfe_ch[i] = tmp_buffer[i];
114 22857920 : move32();
115 : }
116 :
117 50174 : 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 50174 : 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 50174 : fade_len = hLFE->pWindow_state->fade_len;
138 50174 : move16();
139 50174 : zero_pad_len = hLFE->pWindow_state->zero_pad_len;
140 50174 : move16();
141 50174 : pWindow_coeffs = hLFE->pWindow_state->pWindow_coeffs_fx; // Q31
142 :
143 18336510 : FOR( i = 0; i < fade_len; i++ )
144 : {
145 18286336 : pInbuf[i] = Mpy_32_32( pInbuf[zero_pad_len + i], pWindow_coeffs[i] );
146 18286336 : pInbuf[i] = Mpy_32_32( pInbuf[zero_pad_len + i], pWindow_coeffs[i] ); // Q9
147 18286336 : move32();
148 : }
149 :
150 4621758 : FOR( i = 0; i < zero_pad_len * 2; i++ )
151 : {
152 4571584 : pInbuf[fade_len + i] = pInbuf[zero_pad_len + fade_len + i];
153 4571584 : move32();
154 : }
155 :
156 18336510 : FOR( i = 0; i < fade_len; i++ )
157 : {
158 18286336 : 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 18286336 : move32();
160 : }
161 :
162 50174 : 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 24961 : 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 24961 : all_zeros_dct = get_next_indice_fx( st0, 1 );
192 24961 : lfe_bits = st0->next_bit_pos;
193 24961 : move16();
194 24961 : shift_bits = IVAS_LFE_SHIFT_BITS;
195 24961 : move16();
196 24961 : min_shift_bits = 0;
197 24961 : move16();
198 24961 : shift = 0;
199 24961 : move16();
200 :
201 24961 : IF( EQ_16( all_zeros_dct, 1 ) )
202 : {
203 362916 : FOR( i = 0; i < IVAS_LFE_MAX_NUM_DCT_COEFFS; i++ )
204 : {
205 341568 : pOut_buf[i] = 0;
206 341568 : move32();
207 : }
208 : }
209 : ELSE
210 : {
211 : Word32 two_pow_shift_by_4;
212 : Tastat as;
213 : Word16 iii, extra_bits_read;
214 :
215 3613 : extra_bits_read = 0;
216 3613 : move16();
217 3613 : quant_strategy = get_next_indice_fx( st0, 1 );
218 3613 : *num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy];
219 3613 : move16();
220 3613 : num_dct_coeffs = shl( *num_dct_pass_bins, 1 );
221 3613 : num_groups = shr( num_dct_coeffs, 2 );
222 3613 : min_shift_bits = ivas_lfe_min_shift_tbl[quant_strategy];
223 3613 : move16();
224 3613 : shift = add( get_next_indice_fx( st0, shift_bits ), shl( min_shift_bits, 2 ) );
225 :
226 61421 : FOR( i = 0; i < num_dct_coeffs; i++ )
227 : {
228 57808 : sign_bits[i] = get_next_indice_fx( st0, 1 );
229 57808 : move16();
230 : }
231 :
232 3613 : coding_strategy = get_next_indice_fx( st0, 1 );
233 :
234 3613 : IF( coding_strategy )
235 : {
236 1940 : FOR( iii = 0; iii < num_groups; iii++ )
237 : {
238 1552 : base2_bit_size = hLFE->lfe_dec_indices_coeffs_tbl[quant_strategy][iii];
239 1552 : move16();
240 7760 : FOR( i = 0; i < 4; i++ )
241 : {
242 6208 : abs_values[iii * 4 + i] = get_next_indice_fx( st0, base2_bit_size );
243 6208 : move16();
244 : }
245 : }
246 : }
247 : ELSE
248 : {
249 16125 : FOR( iii = 0; iii < num_groups; iii++ )
250 : {
251 12900 : extra_bits_read = 0;
252 12900 : move16();
253 12900 : ivas_ari_start_decoding_14bits_ext_1_lfe( st0, &as, &extra_bits_read );
254 :
255 64500 : FOR( i = 0; i < 4; i++ )
256 : {
257 51600 : 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 51600 : move16();
259 : }
260 12900 : ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read );
261 : }
262 : }
263 :
264 61421 : FOR( i = 0; i < num_dct_coeffs; i++ )
265 : {
266 57808 : values[i] = shl( abs_values[i], 9 ); // Q9
267 57808 : move16();
268 57808 : IF( sign_bits[i] > 0 )
269 : {
270 18255 : values[i] = shl( sub( negate( abs_values[i] ), 1 ), 9 ); // Q9
271 18255 : move16();
272 : }
273 : }
274 :
275 3613 : two_pow_shift_by_4 = tbl_two_pow_shift_by_4[shift];
276 3613 : move32();
277 :
278 18065 : FOR( i = 0; i < num_groups; i++ )
279 : {
280 14452 : pOut_buf[2 * i] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i] ); // Q30 + Q9 >> 15 = Q24
281 14452 : move32();
282 14452 : pOut_buf[2 * i + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 1] ); // Q30 + Q9 >> 15 = Q24
283 14452 : move32();
284 :
285 14452 : 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 14452 : move32();
287 14452 : 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 14452 : move32();
289 : }
290 : }
291 :
292 24961 : lfe_bits = sub( st0->next_bit_pos, lfe_bits );
293 :
294 24961 : return lfe_bits;
295 : }
296 :
297 :
298 : /*-----------------------------------------------------------------------------------------*
299 : * Function ivas_lfe_dec_fx()
300 : *
301 : * LFE channel decoder
302 : *-----------------------------------------------------------------------------------------*/
303 :
304 25087 : void ivas_lfe_dec_fx(
305 : LFE_DEC_HANDLE hLFE, /* i/o: LFE decoder handle */
306 : Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/
307 : const Word16 output_frame, /* i : output frame length per channel */
308 : const Word16 bfi, /* i : BFI flag */
309 : Word32 output_lfe_ch[] /* o : output LFE synthesis Q9*/
310 : )
311 : {
312 : Word16 num_dct_pass_bins;
313 25087 : Word16 i, j, dct_len, q_out = 0;
314 25087 : move16();
315 : Word32 out[L_FRAME48k]; // Q9
316 : Word32 t_audio[L_FRAME48k]; // Q24
317 : Word32 lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS]; // Q24
318 :
319 25087 : dct_len = hLFE->pWindow_state->dct_len;
320 25087 : move16();
321 25087 : num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS;
322 25087 : move16();
323 :
324 25087 : IF( bfi == 0 )
325 : {
326 24961 : ivas_lfe_dec_dequant_fx( hLFE, st0, lfe_dct, &num_dct_pass_bins ); // Q24
327 :
328 24961 : set32_fx( t_audio, 0, dct_len );
329 24961 : Copy32( lfe_dct, t_audio, num_dct_pass_bins ); // Q24
330 24961 : q_out = Q24;
331 24961 : move16();
332 24961 : ivas_imdct_fx( t_audio, out, dct_len, &q_out ); // Q9
333 24961 : ivas_lfe_dec_windowing_fx( hLFE, out ); // Q9
334 24961 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch ); // Q9
335 :
336 24961 : set32_fx( t_audio, 0, dct_len );
337 24961 : Copy32( &lfe_dct[num_dct_pass_bins], t_audio, num_dct_pass_bins ); // Q24
338 24961 : q_out = Q24;
339 24961 : move16();
340 24961 : ivas_imdct_fx( t_audio, out, dct_len, &q_out ); // Q9
341 24961 : ivas_lfe_dec_windowing_fx( hLFE, out ); // Q9
342 24961 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch + dct_len ); // Q9
343 :
344 24961 : Copy32( hLFE->prevsynth_buf_fx + L_FRAME_1k6, hLFE->prevsynth_buf_fx, LFE_PLC_BUFLEN - L_FRAME_1k6 );
345 :
346 24961 : j = 0;
347 24961 : move16();
348 823713 : FOR( i = 0; i < L_FRAME_1k6; i++ )
349 : {
350 798752 : hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j]; // Q9
351 798752 : move32();
352 798752 : j = add( j, shr( output_frame, 5 ) );
353 : }
354 :
355 24961 : hLFE->bfi_count = 0;
356 24961 : move16();
357 : }
358 : ELSE
359 : {
360 : /* note: in BFI branch, buffer 't_audio' is in time-domain ('wtda' signal) */
361 126 : hLFE->bfi_count = add( hLFE->bfi_count, 1 );
362 126 : move16();
363 126 : ivas_lfe_tdplc_fx( hLFE, hLFE->prevsynth_buf_fx, t_audio, output_frame );
364 :
365 126 : ivas_itda_fx( t_audio, out, dct_len );
366 126 : ivas_lfe_dec_windowing_fx( hLFE, out );
367 126 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch );
368 :
369 126 : ivas_itda_fx( t_audio + dct_len, out, dct_len );
370 126 : ivas_lfe_dec_windowing_fx( hLFE, out );
371 126 : ivas_lfe_dec_delay_adjust_fx( hLFE, out, output_lfe_ch + dct_len );
372 :
373 126 : Copy32( hLFE->prevsynth_buf_fx + L_FRAME_1k6, hLFE->prevsynth_buf_fx, LFE_PLC_BUFLEN - L_FRAME_1k6 );
374 :
375 126 : j = 0;
376 126 : move16();
377 4158 : FOR( i = 0; i < L_FRAME_1k6; i++ )
378 : {
379 4032 : hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j];
380 4032 : move32();
381 4032 : j = add( j, shr( output_frame, 5 ) );
382 : }
383 : }
384 :
385 25087 : IF( hLFE->filter_state.order > 0 )
386 : {
387 : /* NOTE: this block is not getting hit by any stream present in pytest test suite */
388 : /* Low Pass Filter */
389 0 : ivas_filter_process_fx( &hLFE->filter_state, output_lfe_ch, output_frame, q_out );
390 : }
391 :
392 : /* add delay to make overall max(block_offset, 11.5) */
393 25087 : IF( hLFE->lfe_addl_delay > 0 )
394 : {
395 25087 : delay_signal32_fx( output_lfe_ch, output_frame, hLFE->lfe_delay_buf_fx, hLFE->lfe_addl_delay );
396 : }
397 :
398 25087 : return;
399 : }
400 :
401 :
402 : /*-------------------------------------------------------------------------
403 : * ivas_create_lfe_dec()
404 : *
405 : * Create, allocate and initialize IVAS decoder LFE handle
406 : *-------------------------------------------------------------------------*/
407 :
408 305 : ivas_error ivas_create_lfe_dec_fx(
409 : LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */
410 : const Word32 output_Fs, /* i : output sampling rate Q0*/
411 : const Word32 binauralization_delay_ns /* i : additional LFE delay to sync with binaural renderer */
412 : )
413 : {
414 : Word16 low_pass_delay_dec_out, block_offset_s;
415 : Word16 filt_order, output_frame;
416 : LFE_DEC_HANDLE hLFE;
417 : Word16 lfe_addl_delay_s;
418 : Word16 i, j;
419 : Word16 add_delay_sa;
420 : Word32 output_fs_fx;
421 :
422 305 : low_pass_delay_dec_out = 0;
423 305 : move16();
424 305 : block_offset_s = 0;
425 305 : move16();
426 :
427 305 : output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) );
428 :
429 : /*-----------------------------------------------------------------*
430 : * Allocate LFE handle
431 : *-----------------------------------------------------------------*/
432 :
433 305 : IF( ( hLFE = (LFE_DEC_HANDLE) malloc( sizeof( LFE_DEC_DATA ) ) ) == NULL )
434 : {
435 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE\n" ) );
436 : }
437 :
438 : /*-----------------------------------------------------------------*
439 : * LFE Window: allocate and initialize
440 : *-----------------------------------------------------------------*/
441 :
442 305 : IF( ( hLFE->pWindow_state = (LFE_WINDOW_HANDLE) malloc( sizeof( LFE_WINDOW_DATA ) ) ) == NULL )
443 : {
444 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE window structure\n" ) );
445 : }
446 :
447 305 : ivas_lfe_window_init_fx( hLFE->pWindow_state, output_Fs, output_frame );
448 :
449 : /* Initialization for entropy coding */
450 305 : hLFE->cum_freq_models[0][0] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg1;
451 305 : hLFE->cum_freq_models[0][1] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg2;
452 305 : hLFE->cum_freq_models[0][2] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg3;
453 305 : hLFE->cum_freq_models[0][3] = ivas_str_lfe_freq_models.entropy_coder_model_fine_sg4;
454 305 : hLFE->cum_freq_models[1][0] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg1;
455 305 : hLFE->cum_freq_models[1][1] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg2;
456 305 : hLFE->cum_freq_models[1][2] = ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg3;
457 305 : hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4;
458 :
459 : /* delay calculation */
460 305 : hLFE->lfe_block_delay_s_fx = add( IVAS_LFE_FADE_S_Q15, ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3] ); // Q15
461 305 : move16();
462 :
463 305 : block_offset_s = BLOCK_OFFSET_S_Q15; // Q15
464 305 : move16();
465 305 : filt_order = 0;
466 305 : move16();
467 305 : low_pass_delay_dec_out = 0; // Q15
468 305 : move16();
469 305 : hLFE->filter_state.order = filt_order;
470 305 : move16();
471 305 : hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, low_pass_delay_dec_out ); // Q15
472 305 : move16();
473 305 : hLFE->lfe_prior_buf_len = NS2SA_FX2( output_Fs, IVAS_LFE_FADE_NS ); // Q0
474 305 : move16();
475 :
476 305 : hLFE->bfi_count = 0;
477 305 : move16();
478 :
479 305 : IF( NE_32( output_Fs, 48000 ) )
480 : {
481 71 : IF( NE_32( output_Fs, 32000 ) )
482 : {
483 67 : output_fs_fx = FS_16K_IN_NS_Q31; // Q31
484 : }
485 : ELSE
486 : {
487 4 : output_fs_fx = FS_32K_IN_NS_Q31;
488 : }
489 : }
490 : ELSE
491 : {
492 234 : output_fs_fx = FS_48K_IN_NS_Q31;
493 : }
494 305 : move32();
495 :
496 305 : lfe_addl_delay_s = sub( block_offset_s, hLFE->lfe_block_delay_s_fx ); // Q15
497 305 : lfe_addl_delay_s = s_max( 0, lfe_addl_delay_s );
498 305 : add_delay_sa = (Word16) W_round64_L( W_mult0_32_32( L_shl( binauralization_delay_ns, 1 ), output_fs_fx ) ); // Q0
499 305 : move16();
500 305 : hLFE->lfe_addl_delay = add( (Word16) L_shr( imult3216( output_Fs, lfe_addl_delay_s ), 15 ), add_delay_sa ); // Q0
501 305 : move16();
502 305 : IF( add_delay_sa == 0 )
503 : {
504 163 : hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, lfe_addl_delay_s );
505 : }
506 : ELSE
507 : {
508 142 : hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, add( lfe_addl_delay_s, idiv1616( add_delay_sa, extract_l( output_Fs ) ) ) );
509 : }
510 305 : move16();
511 :
512 305 : IF( hLFE->lfe_addl_delay > 0 )
513 : {
514 305 : IF( ( hLFE->lfe_delay_buf_fx = (Word32 *) malloc( hLFE->lfe_addl_delay * sizeof( Word32 ) ) ) == NULL )
515 : {
516 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE additional delay buffer\n" ) );
517 : }
518 305 : set32_fx( (Word32 *) hLFE->lfe_delay_buf_fx, 0, hLFE->lfe_addl_delay );
519 : }
520 : ELSE
521 : {
522 0 : hLFE->lfe_delay_buf_fx = NULL;
523 : }
524 :
525 : /* Initialization base2 bits for each subgroup for no entropy coding */
526 915 : FOR( i = 0; i < IVAS_MAX_NUM_QUANT_STRATS; i++ )
527 : {
528 3050 : FOR( j = 0; j < IVAS_MAX_NUM_DCT_COEF_GROUPS; j++ )
529 : {
530 2440 : hLFE->lfe_dec_indices_coeffs_tbl[i][j] = ivas_lfe_log2_num_ele_in_coder_models_fx[i][j];
531 2440 : move16();
532 : }
533 : }
534 :
535 305 : *hLFE_out = hLFE;
536 :
537 305 : return IVAS_ERR_OK;
538 : }
539 :
540 :
541 : /*-------------------------------------------------------------------------
542 : * ivas_lfe_dec_close_fx()
543 : *
544 : * Destroy IVAS decoder LFE handle
545 : *-------------------------------------------------------------------------*/
546 :
547 1100 : void ivas_lfe_dec_close_fx(
548 : LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */
549 : )
550 : {
551 1100 : test();
552 1100 : IF( hLFE == NULL || *hLFE == NULL )
553 : {
554 795 : return;
555 : }
556 :
557 305 : free( ( *hLFE )->pWindow_state );
558 305 : ( *hLFE )->pWindow_state = NULL;
559 :
560 305 : IF( ( *hLFE )->lfe_delay_buf_fx != NULL )
561 : {
562 305 : free( ( *hLFE )->lfe_delay_buf_fx );
563 305 : ( *hLFE )->lfe_delay_buf_fx = NULL;
564 : }
565 :
566 305 : free( ( *hLFE ) );
567 305 : ( *hLFE ) = NULL;
568 :
569 305 : return;
570 : }
|