From 6eb0e7e56bdaeb48f4224d3f5e1b2a655508ae6c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 28 Jun 2024 14:44:23 +0530 Subject: [PATCH] BASOP and instrumentation changes added for swb_*, ivas-ism files --- lib_com/ivas_prot.h | 8 +- lib_dec/ivas_entropy_decoder.c | 80 +- lib_dec/ivas_init_dec.c | 1133 ++++++++++++++++-------- lib_dec/ivas_init_dec_fx.c | 108 ++- lib_dec/ivas_ism_dec.c | 93 +- lib_dec/ivas_ism_dtx_dec.c | 10 +- lib_dec/ivas_ism_metadata_dec.c | 85 +- lib_dec/ivas_ism_param_dec.c | 282 ++++-- lib_dec/ivas_ism_renderer.c | 94 +- lib_dec/ivas_mc_param_dec_fx.c | 3 + lib_dec/ivas_mct_dec.c | 10 +- lib_dec/ivas_mdct_core_dec.c | 534 ++++++++--- lib_dec/ivas_mono_dmx_renderer.c | 60 +- lib_dec/ivas_objectRenderer_internal.c | 52 +- lib_dec/ivas_omasa_dec.c | 119 ++- lib_dec/ivas_osba_dec.c | 49 +- lib_dec/ivas_output_config.c | 19 +- lib_dec/jbm_jb4sb.c | 4 +- lib_dec/rst_dec_fx.c | 4 +- lib_dec/stat_noise_uv_dec_fx.c | 24 +- lib_dec/swb_bwe_dec.c | 84 +- lib_dec/swb_bwe_dec_fx.c | 108 ++- lib_dec/swb_bwe_dec_hr_fx.c | 116 ++- lib_dec/swb_bwe_dec_lr_fx.c | 33 +- lib_dec/swb_tbe_dec.c | 540 +++++++---- lib_dec/swb_tbe_dec_fx.c | 886 ++++++++++++------ lib_dec/syn_outp_fx.c | 7 +- lib_dec/tcq_core_dec_fx.c | 68 +- lib_dec/tcx_utils_dec_fx.c | 784 ++++++++-------- 29 files changed, 3546 insertions(+), 1851 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 99dff9b37..766ec38de 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -932,11 +932,13 @@ void dtx_read_padding_bits( const int16_t num_bits ); -void ivas_apply_non_diegetic_panning( +#ifndef IVAS_FLOAT_FIXED +void ivas_apply_non_diegetic_panning( float *output_f[], /* i/o: core-coder transport mono channel/stereo output */ const float non_diegetic_pan_gain, /* i : non-diegetic panning gain */ const int16_t output_frame /* i : output frame length per channel */ ); +#endif /*----------------------------------------------------------------------------------* @@ -7014,11 +7016,13 @@ void ivas_mono_downmix_render_passive( const int16_t output_frame /* i : output frame length */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_mono_stereo_downmix_mcmasa( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output_f[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ int16_t output_frame /* i : output frame length per channel */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_filters_fx( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ @@ -7393,11 +7397,13 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( float *output_f[] /* o : rendered time signal */ ); #endif +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_rearrange_channels( float *output[], /* o : output synthesis signal */ const int16_t nchan_transport_ism, /* i : number of ISM TCs */ const int16_t output_frame /* i : output frame length per channel */ ); +#endif #ifndef IVAS_FLOAT_FIXED void ivas_omasa_dirac_rend_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder.c index af8e4082a..9c769bf57 100644 --- a/lib_dec/ivas_entropy_decoder.c +++ b/lib_dec/ivas_entropy_decoder.c @@ -66,14 +66,16 @@ static void ivas_arith_decode_array( Word16 *pCum_freq = NULL; Tastat as; Word16 extra_bits_read = 0; + move16(); - IF( GT_16( in_len, 0 ) && GT_16( pArith->range, 1 ) ) + test(); + IF( ( in_len > 0 ) && GT_16( pArith->range, 1 ) ) { - IF( GT_16( pArith->dyn_model_bits, 0 ) ) + IF( pArith->dyn_model_bits > 0 ) { model_idx = get_next_indice( st0, pArith->dyn_model_bits ); - IF( GT_16( model_idx, 0 ) ) + IF( model_idx > 0 ) { pCum_freq = pArith->cum_freq[model_idx]; } @@ -94,15 +96,18 @@ static void ivas_arith_decode_array( ind = ivas_ari_decode_14bits_bit_ext_1_lfe( st0, &as, (const UWord16 *) pCum_freq, &extra_bits_read ); pSymbols[i] = pArith->vals[ind]; + move16(); } ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read ); } ELSE { + FOR( i = 0; i < in_len; i++ ) { pSymbols[i] = 0; + move16(); } } @@ -126,8 +131,9 @@ static void ivas_arithCoder_decode_array_diff( { Word16 n; Word16 offset = pArith->vals[0]; + move16(); - IF( GT_16( length, 0 ) ) + IF( length > 0 ) { ivas_arith_decode_array( pArith_diff, st0, length, pOutput_arr ); } @@ -135,6 +141,7 @@ static void ivas_arithCoder_decode_array_diff( FOR( n = 0; n < length; n++ ) { pOutput_arr[n] = add( sub( pSymbol_old[n], offset ), pOutput_arr[n] ); + move16(); } #ifndef IVAS_FLOAT_FIXED @@ -146,6 +153,7 @@ static void ivas_arithCoder_decode_array_diff( FOR( n = 0; n < length; n++ ) { pOutput_arr[n] = pArith->vals[pOutput_arr[n]]; + move16(); } return; @@ -166,19 +174,25 @@ static Word16 ivas_huffman_code_bits_present( { Word16 index = add( len, 1 ); Word16 i = 0; + move16(); Word16 ind_t, code_t, bits_t; WHILE( LT_16( i, len ) ) { ind_t = codebook[0]; + move16(); bits_t = codebook[1]; + move16(); code_t = codebook[2]; + move16(); + + test(); IF( ( EQ_16( code, code_t ) ) && ( EQ_16( bits, bits_t ) ) ) { return ind_t; } codebook = codebook + 3; - i++; + i = add( i, 1 ); } return index; @@ -200,6 +214,7 @@ ivas_error ivas_huffman_decode( code = get_next_indice( st0, huff_cfg->min_len ); num_bits_read = huff_cfg->min_len; + move16(); ind = ivas_huffman_code_bits_present( huff_cfg->codebook, code, num_bits_read, huff_cfg->sym_len ); @@ -207,7 +222,7 @@ ivas_error ivas_huffman_decode( { bit = get_next_indice( st0, 1 ); num_bits_read = add( num_bits_read, 1 ); - code = code << 1 | bit; + code = s_or( shl( code, 1 ), bit ); ind = ivas_huffman_code_bits_present( huff_cfg->codebook, code, num_bits_read, huff_cfg->sym_len ); IF( GT_16( num_bits_read, huff_cfg->max_len ) ) { @@ -215,6 +230,7 @@ ivas_error ivas_huffman_decode( } } *dec_out = ind; + move16(); return IVAS_ERR_OK; } @@ -234,11 +250,12 @@ static void arith_decode_cell_array( Word16 *pSymbol ) { Word16 total_symbol_len = 0; + move16(); Word16 i; FOR( i = 0; i < num_bands; i++ ) { - total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); + total_symbol_len = add( total_symbol_len, imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); } assert( LE_16( total_symbol_len, IVAS_MAX_INPUT_LEN ) ); @@ -265,11 +282,12 @@ static void arith_decode_cell_array_diff( Word16 *pSymbol_old ) { Word16 total_symbol_len = 0; + move16(); Word16 i; FOR( i = 0; i < num_bands; i++ ) { - total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); + total_symbol_len = add( total_symbol_len, imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ) ); } assert( LE_16( total_symbol_len, IVAS_MAX_INPUT_LEN ) ); @@ -300,16 +318,19 @@ void ivas_arith_decode_cmplx_cell_array( Word16 cell_arr_no_diff[IVAS_MAX_INPUT_LEN]; Word16 cell_arr_diff_out[IVAS_MAX_INPUT_LEN]; Word16 idx2 = 0; + move16(); FOR( i = 0; i < num_bands; i++ ) { - IF( NE_16( pDo_diff[i], 0 ) ) + IF( pDo_diff[i] != 0 ) { any_diff = 1; + move16(); } ELSE { all_diff = 0; + move16(); } } @@ -324,35 +345,49 @@ void ivas_arith_decode_cmplx_cell_array( ivas_cell_dim_t cell_dims[IVAS_MAX_NUM_BANDS]; ivas_cell_dim_t cell_dims_diff[IVAS_MAX_NUM_BANDS]; Word16 idx1 = 0, idx = 0; + move16(); + move16(); FOR( i = 0; i < num_bands; i++ ) { - len = pCell_dims[i].dim1 * pCell_dims[i].dim2; - IF( NE_16( pDo_diff[i], 0 ) ) + len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); + IF( pDo_diff[i] != 0 ) { cell_dims[i].dim1 = 0; + move16(); cell_dims[i].dim2 = 0; + move16(); FOR( j = 0; j < len; j++ ) { - cell_arr_diff[idx++] = pSymbol_re_old[idx1++]; + cell_arr_diff[idx] = pSymbol_re_old[idx1]; + move16(); + idx = add( idx, 1 ); + idx1 = add( idx1, 1 ); } cell_dims_diff[i].dim1 = pCell_dims[i].dim1; + move16(); cell_dims_diff[i].dim2 = pCell_dims[i].dim2; + move16(); } ELSE { FOR( j = 0; j < len; j++ ) { cell_arr_diff[idx] = 0; - idx1++; + move16(); + idx1 = add( idx1, 1 ); } cell_dims[i].dim1 = pCell_dims[i].dim1; + move16(); cell_dims[i].dim2 = pCell_dims[i].dim2; + move16(); cell_dims_diff[i].dim1 = 0; + move16(); cell_dims_diff[i].dim2 = 0; + move16(); } } @@ -361,21 +396,30 @@ void ivas_arith_decode_cmplx_cell_array( arith_decode_cell_array_diff( cell_dims_diff, st0, num_bands, pArith_re, pArith_re_diff, cell_arr_diff_out, cell_arr_diff ); idx = 0; + move16(); idx1 = 0; + move16(); + FOR( i = 0; i < num_bands; i++ ) { - IF( NE_16( pDo_diff[i], 0 ) ) + IF( pDo_diff[i] != 0 ) { - FOR( j = 0; j < cell_dims_diff[i].dim1 * cell_dims_diff[i].dim2; j++ ) + FOR( j = 0; j < imult1616( cell_dims_diff[i].dim1, cell_dims_diff[i].dim2 ); j++ ) { - pSymbol_re[idx++] = cell_arr_diff_out[idx2++]; + pSymbol_re[idx] = cell_arr_diff_out[idx2]; + move16(); + idx = add( idx, 1 ); + idx2 = add( idx2, 1 ); } } ELSE { - FOR( j = 0; j < cell_dims[i].dim1 * cell_dims[i].dim2; j++ ) + FOR( j = 0; j < imult1616( cell_dims[i].dim1, cell_dims[i].dim2 ); j++ ) { - pSymbol_re[idx++] = cell_arr_no_diff[idx1++]; + pSymbol_re[idx] = cell_arr_no_diff[idx1]; + move16(); + idx = add( idx, 1 ); + idx1 = add( idx1, 1 ); } } } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 214c004fa..294a97bf5 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -83,11 +83,14 @@ ivas_error ivas_dec_setup( ivas_error error; error = IVAS_ERR_OK; - + move32(); num_bits_read = 0; + move16(); element_mode_flag = 0; + move16(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move16(); /*-------------------------------------------------------------------* * Read IVAS format @@ -97,12 +100,13 @@ ivas_error ivas_dec_setup( Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src = 0; + move16(); /*-------------------------------------------------------------------* * Read other signling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ - IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) ) + IF( is_DTXrate( ivas_total_brate ) == 0 ) { /*-------------------------------------------------------------------* * Read IVAS format related signaling: @@ -112,45 +116,55 @@ ivas_error ivas_dec_setup( * - in MC : read LS setup *-------------------------------------------------------------------*/ - IF( st_ivas->ivas_format == STEREO_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { element_mode_flag = 1; + move16(); } - ELSE IF( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { /* read the number of objects */ st_ivas->nchan_transport = 1; + move16(); nchan_ism = 1; - k = (Word16) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + move16(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + k = extract_l( L_sub( res_dec, 1 ) ); + + test(); WHILE( st_ivas->bit_stream[k] && LT_16( nchan_ism, MAX_NUM_OBJECTS ) ) { - nchan_ism++; - k--; + nchan_ism = add( nchan_ism, 1 ); + k = sub( k, 1 ); } st_ivas->nchan_ism = nchan_ism; + move16(); - IF( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->ivas_format == SBA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { /* read Ambisonic (SBA) planar flag */ st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read]; - + move16(); num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); /* read Ambisonic (SBA) order */ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; - st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; - - + move16(); + st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + move16(); num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); - IF( GT_16( st_ivas->ini_frame, 0 ) && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) + test(); + test(); + IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - IF( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -159,36 +173,45 @@ ivas_error ivas_dec_setup( { /* set Ambisonic (SBA) order used for analysis and coding */ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); + move16(); ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); } } - ELSE IF( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { /* read number of MASA transport channels */ - IF( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + IF( st_ivas->bit_stream[res_dec - 1] ) { st_ivas->nchan_transport = 2; + move16(); element_mode_flag = 1; + move16(); } ELSE { st_ivas->nchan_transport = 1; + move16(); } - IF( GT_16( st_ivas->ini_frame, 0 ) ) + IF( st_ivas->ini_frame > 0 ) { /* reconfigure in case a change of operation mode is detected */ - IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) + test(); + test(); + IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || ( st_ivas->ini_active_frame == 0 ) ) { - IF( st_ivas->last_ivas_format == MASA_FORMAT ) + IF( EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) { - IF( EQ_16( st_ivas->ini_active_frame, 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) + IF( ( st_ivas->ini_active_frame == 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) { st_ivas->hCPE[0]->nchan_out = 1; + move16(); } ELSE { - IF( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -196,7 +219,7 @@ ivas_error ivas_dec_setup( } ELSE { - IF( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -204,52 +227,66 @@ ivas_error ivas_dec_setup( } } } - ELSE IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ - + move16(); /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata */ - st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; - st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism ); - move32(); - IF( GT_16( st_ivas->ini_frame, 0 ) ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[L_sub( res_dec, 1 )], 1 ), st_ivas->bit_stream[L_sub( res_dec, 2 )] ), 1 ); + move16(); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism ); + move16(); + IF( st_ivas->ini_frame > 0 ) { /* reconfigure in case a change of operation mode is detected */ - IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) + test(); + test(); + IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || ( st_ivas->ini_active_frame == 0 ) ) { - IF( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) ) { return error; } } } } - ELSE IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { /* the number of objects is written at the end of the bitstream, in the SBA metadata */ - st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[L_sub( res_dec, 1 )], 1 ), st_ivas->bit_stream[L_sub( res_dec, 2 )] ), 1 ); + move16(); + test(); IF( LT_32( ivas_total_brate, IVAS_24k4 ) || GE_32( ivas_total_brate, IVAS_256k ) ) { /* read Ambisonic (SBA) planar flag */ st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read]; + move16(); num_bits_read = add( num_bits_read, SBA_PLANAR_BITS ); } st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; - st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + move16(); + st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + move16(); num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); /* read Ambisonic (SBA) order */ IF( LT_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->sba_order = 3; + move16(); } - IF( GT_16( st_ivas->ini_frame, 0 ) && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ) + test(); + IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ) { - IF( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -258,40 +295,46 @@ ivas_error ivas_dec_setup( { /* set Ambisonic (SBA) order used for analysis and coding */ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); + move16(); ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); /*correct number of CPEs for discrete ISM coding*/ - IF( GT_16( st_ivas->ini_frame, 0 ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + IF( st_ivas->ini_frame > 0 && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - st_ivas->nCPE += add( st_ivas->nchan_ism, 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); + move16(); } } IF( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move32(); } ELSE { st_ivas->ism_mode = ISM_MODE_NONE; + move32(); } } - ELSE IF( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { /* read MC configuration */ idx = 0; + move16(); FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) { IF( st_ivas->bit_stream[num_bits_read + k] ) { - idx += 1 << ( MC_LS_SETUP_BITS - 1 - k ); + idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); } } num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); /* select MC format mode; reconfigure the MC format decoder */ - IF( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -301,7 +344,7 @@ ivas_error ivas_dec_setup( * Read element mode *-------------------------------------------------------------------*/ - IF( EQ_16( st_ivas->ini_frame, 0 ) && element_mode_flag ) + IF( st_ivas->ini_frame == 0 && element_mode_flag ) { /* read stereo technology info */ IF( LT_32( ivas_total_brate, MIN_BRATE_MDCT_STEREO ) ) @@ -310,15 +353,18 @@ ivas_error ivas_dec_setup( IF( st_ivas->bit_stream[num_bits_read] ) { st_ivas->element_mode_init = add( 1, IVAS_CPE_DFT ); + move16(); } ELSE { st_ivas->element_mode_init = add( 0, IVAS_CPE_DFT ); + move16(); } } ELSE { st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); } } } @@ -328,101 +374,140 @@ ivas_error ivas_dec_setup( { case SID_DFT_STEREO: st_ivas->element_mode_init = IVAS_CPE_DFT; + move16(); BREAK; case SID_MDCT_STEREO: st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); BREAK; case SID_ISM: st_ivas->element_mode_init = IVAS_SCE; + move16(); BREAK; case SID_MASA_1TC: st_ivas->element_mode_init = IVAS_SCE; + move16(); st_ivas->nchan_transport = 1; + move16(); BREAK; case SID_MASA_2TC: - IF( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 ) + move16(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + IF( EQ_16( st_ivas->bit_stream[L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS )], 1 ) ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); } ELSE { st_ivas->element_mode_init = IVAS_CPE_DFT; + move16(); } st_ivas->nchan_transport = 2; + move16(); BREAK; case SID_SBA_1TC: st_ivas->element_mode_init = IVAS_SCE; + move16(); BREAK; case SID_SBA_2TC: st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); BREAK; } - IF( GT_16( st_ivas->ini_frame, 0 ) && st_ivas->ivas_format == SBA_FORMAT ) + test(); + IF( st_ivas->ini_frame > 0 && EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { Word16 nchan_transport_old, nchan_transport; nchan_transport_old = st_ivas->nchan_transport; - nchan_transport = ( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) ? 2 : 1; + move16(); + IF( ( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) ) + { + nchan_transport = 2; + } + ELSE + { + nchan_transport = 1; + } + move16(); - IF( ( nchan_transport_old != nchan_transport ) ) + IF( NE_16( nchan_transport_old, nchan_transport ) ) { /*Setting the default bitrate for the reconfig function*/ IF( EQ_16( st_ivas->sid_format, SID_SBA_2TC ) ) { st_ivas->hDecoderConfig->ivas_total_brate = IVAS_48k; + move16(); } ELSE { st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4; + move16(); } - IF( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->last_active_ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; + move32(); } } - IF( st_ivas->ivas_format == ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { ISM_MODE last_ism_mode = st_ivas->ism_mode; - + move32(); /* read the number of objects */ st_ivas->nchan_transport = 1; + move16(); nchan_ism = 1; - k = (Word16) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ) - SID_FORMAT_NBITS; + move16(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + k = extract_l( L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS ) ); + move16(); + test(); WHILE( st_ivas->bit_stream[k] && LT_16( nchan_ism, MAX_NUM_OBJECTS ) ) { - nchan_ism++; - k--; + nchan_ism = add( nchan_ism, 1 ); + k = sub( k, 1 ); } - k--; + k = sub( k, 1 ); + test(); if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" ); } st_ivas->nchan_ism = nchan_ism; - + move16(); /* read ism_mode */ st_ivas->ism_mode = ISM_MODE_DISC; - IF( GT_16( nchan_ism, 2 ) ) + move32(); + if ( GT_16( nchan_ism, 2 ) ) { k -= nchan_ism; /* SID metadata flags */ + move16(); idx = st_ivas->bit_stream[k]; + move16(); st_ivas->ism_mode = (ISM_MODE) add( idx, 1 ); + move32(); } IF( st_ivas->ini_frame == 0 ) { last_ism_mode = st_ivas->ism_mode; + move32(); } - IF( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -434,14 +519,14 @@ ivas_error ivas_dec_setup( * and number of transport channels *-------------------------------------------------------------------*/ - IF( EQ_16( st_ivas->ini_frame, 0 ) && st_ivas->ivas_format != UNDEFINED_FORMAT ) + IF( st_ivas->ini_frame == 0 && NE_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) { - IF( ( error = doSanityChecks_IVAS( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = doSanityChecks_IVAS( st_ivas ) ), IVAS_ERR_OK ) ) { return IVAS_ERROR( error, "Sanity checks failed" ); } - IF( ( error = ivas_init_decoder_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_init_decoder_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -457,11 +542,21 @@ ivas_error ivas_dec_setup( reset_elements( st_ivas ); /* update bitstream buffer pointer -> take into account already read bits */ - IF( ( GT_16( st_ivas->nSCE, 0 ) ) || ( GT_16( st_ivas->nCPE, 0 ) ) ) + test(); + IF( ( st_ivas->nSCE > 0 ) || ( st_ivas->nCPE > 0 ) ) { - st = GT_16( st_ivas->nSCE, 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( st_ivas->nSCE > 0 ) + { + st = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st = st_ivas->hCPE[0]->hCoreCoder[0]; + } st->next_bit_pos = num_bits_read; + move16(); st->total_brate = ACELP_8k00; /* only temporary initialization - this is needed for get_next_indice() in the frame following NO_DATA frame */ + move32(); } return error; @@ -865,7 +960,6 @@ ivas_error ivas_dec_setup( #endif -// ivas_param_ism_dec /*-------------------------------------------------------------------* * ivas_read_format() * @@ -883,129 +977,162 @@ static ivas_error ivas_read_format( ivas_error error; error = IVAS_ERR_OK; + move32(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); *num_bits_read = 0; move16(); - + test(); IF( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 ) { /* read IVAS format */ k = 0; + move16(); IF( st_ivas->bit_stream[*num_bits_read] ) { k = 1; + move16(); } - k <<= 1; - ( *num_bits_read )++; - + k = shl( k, 1 ); + ( *num_bits_read ) = add( ( *num_bits_read ), 1 ); + move16(); IF( st_ivas->bit_stream[*num_bits_read] ) { - k += 1; + k = add( k, 1 ); } - ( *num_bits_read )++; - + ( *num_bits_read ) = add( ( *num_bits_read ), 1 ); + move16(); SWITCH( k ) { case 0: st_ivas->ivas_format = STEREO_FORMAT; + move32(); BREAK; case 1: st_ivas->ivas_format = MC_FORMAT; + move32(); BREAK; case 2: st_ivas->ivas_format = ISM_FORMAT; + move32(); - IF( ivas_total_brate >= IVAS_24k4 ) + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) { IF( st_ivas->bit_stream[*num_bits_read] ) { - ( *num_bits_read )++; + ( *num_bits_read ) = add( ( *num_bits_read ), 1 ); + move16(); IF( st_ivas->bit_stream[*num_bits_read] ) { st_ivas->ivas_format = SBA_ISM_FORMAT; + move32(); } ELSE { st_ivas->ivas_format = MASA_ISM_FORMAT; + move32(); } } - ( *num_bits_read )++; + ( *num_bits_read ) = add( ( *num_bits_read ), 1 ); + move16(); } BREAK; case 3: IF( st_ivas->bit_stream[*num_bits_read] ) { st_ivas->ivas_format = MASA_FORMAT; + move32(); } ELSE { st_ivas->ivas_format = SBA_FORMAT; + move32(); /* read Ambisonic (SBA) planar flag */ - st_ivas->sba_planar = st_ivas->bit_stream[( *num_bits_read ) + 1]; + st_ivas->sba_planar = st_ivas->bit_stream[add( ( *num_bits_read ), 1 )]; + move16(); /* read Ambisonic (SBA) order */ - st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS]; - st_ivas->sba_order += 2 * st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS]; + st_ivas->sba_order = st_ivas->bit_stream[add( add( ( *num_bits_read ), 2 ), SBA_PLANAR_BITS )]; + move16(); + st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[add( add( ( *num_bits_read ), 1 ), SBA_PLANAR_BITS )], 1 ) ); + move16(); IF( st_ivas->sba_order == 0 ) { st_ivas->ivas_format = SBA_ISM_FORMAT; + move32(); } } - ( *num_bits_read )++; + ( *num_bits_read ) = add( ( *num_bits_read ), 1 ); + move16(); BREAK; } } - ELSE IF( EQ_16( st_ivas->bfi, 0 ) && ivas_total_brate == IVAS_SID_5k2 ) + ELSE IF( ( st_ivas->bfi == 0 ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { /* read IVAS format in SID frame */ idx = 0; + move16(); FOR( k = 0; k < SID_FORMAT_NBITS; k++ ) { - idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k ); + idx = add( idx, shl( st_ivas->bit_stream[k], sub( sub( SID_FORMAT_NBITS, 1 ), k ) ) ); } ( *num_bits_read ) = add( *num_bits_read, SID_FORMAT_NBITS ); + move16(); st_ivas->sid_format = idx; + move16(); SWITCH( idx ) { case SID_DFT_STEREO: case SID_MDCT_STEREO: st_ivas->ivas_format = STEREO_FORMAT; + move32(); BREAK; case SID_ISM: st_ivas->ivas_format = ISM_FORMAT; - + move32(); BREAK; case SID_MULTICHANNEL: st_ivas->ivas_format = MC_FORMAT; + move32(); BREAK; case SID_SBA_1TC: st_ivas->ivas_format = SBA_FORMAT; + move32(); st_ivas->element_mode_init = IVAS_SCE; + move16(); BREAK; case SID_SBA_2TC: st_ivas->ivas_format = SBA_FORMAT; + move32(); st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); BREAK; case SID_MASA_1TC: st_ivas->ivas_format = MASA_FORMAT; + move32(); st_ivas->element_mode_init = IVAS_SCE; + move16(); BREAK; case SID_MASA_2TC: st_ivas->ivas_format = MASA_FORMAT; - IF( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] == 1 ) + move32(); + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + IF( st_ivas->bit_stream[res_dec - 1] == 1 ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); } ELSE { st_ivas->element_mode_init = IVAS_CPE_DFT; + move16(); } BREAK; default: @@ -1013,17 +1140,19 @@ static ivas_error ivas_read_format( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format ); } - IF( st_ivas->ivas_format == SBA_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { IF( st_ivas->sba_analysis_order == 0 ) { st_ivas->sba_analysis_order = SBA_FOA_ORDER; + move16(); } } /* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */ - st_ivas->bit_stream += ( *num_bits_read ); + st_ivas->bit_stream = st_ivas->bit_stream + ( *num_bits_read ); ( *num_bits_read ) = 0; + move16(); } ELSE { @@ -1211,27 +1340,31 @@ Word16 getNumChanSynthesis( Word16 n; n = add( st_ivas->nSCE, imult1616( CPE_CHANNELS, st_ivas->nCPE ) ); - + test(); + test(); + test(); IF( st_ivas->sba_dirac_stereo_flag ) { n = CPE_CHANNELS; + move16(); } - ELSE IF( ( st_ivas->hMCT != NULL || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( ( st_ivas->hMCT != NULL || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { n = st_ivas->nchan_transport; + move16(); } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { n = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); } ELSE { n = st_ivas->nchan_transport; + move16(); } } - move16(); return n; } @@ -1336,7 +1469,7 @@ ivas_error ivas_init_decoder_front( ivas_error error; error = IVAS_ERR_OK; - + move32(); /*-----------------------------------------------------------------* * Resets *-----------------------------------------------------------------*/ @@ -1347,10 +1480,10 @@ ivas_error ivas_init_decoder_front( move16(); st_ivas->nchan_transport = -1; move16(); - st_ivas->ism_mode = ISM_MODE_NONE; + move32(); st_ivas->mc_mode = MC_MODE_NONE; - + move32(); st_ivas->sba_dirac_stereo_flag = 0; move32(); @@ -1385,12 +1518,12 @@ ivas_error ivas_init_decoder_front( IF( st_ivas->hDecoderConfig->Opt_Headrotation ) { - IF( ( error = ivas_headTrack_open_fx( &( st_ivas->hHeadTrackData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_headTrack_open_fx( &( st_ivas->hHeadTrackData ) ) ), IVAS_ERR_OK ) ) { return error; } error = ivas_orient_trk_SetTrackingType_fx( st_ivas->hHeadTrackData->OrientationTracker, st_ivas->hDecoderConfig->orientation_tracking ); - IF( ( error ) != IVAS_ERR_OK ) + IF( NE_32( ( error ), IVAS_ERR_OK ) ) { return error; } @@ -1401,7 +1534,7 @@ ivas_error ivas_init_decoder_front( IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_external_orientation_open( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) ) { return error; } @@ -1420,10 +1553,10 @@ ivas_error ivas_init_decoder_front( /*-------------------------------------------------------------------* * Allocate and initialize combined orientation handle *--------------------------------------------------------------------*/ - + test(); IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_combined_orientation_open( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ) ), IVAS_ERR_OK ) ) { return error; } @@ -1448,22 +1581,22 @@ ivas_error ivas_init_decoder_front( IF( st_ivas->hDecoderConfig->Opt_HRTF_binary ) { - IF( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_HRTF_CRend_binary_open_fx( &( st_ivas->hSetOfHRTF ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_HRTF_CRend_binary_open_fx( &( st_ivas->hSetOfHRTF ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_HRTF_parambin_binary_open_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_HRTF_parambin_binary_open_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -1475,19 +1608,19 @@ ivas_error ivas_init_decoder_front( IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - IF( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_render_config_init_from_rom_fx( &st_ivas->hRenderConfig ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &st_ivas->hRenderConfig ) ), IVAS_ERR_OK ) ) { return error; } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED /*FLOAT CODE*/ - IF( ( error = ivas_render_config_init_from_rom( &st_ivas->hRenderConfig ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_render_config_init_from_rom( &st_ivas->hRenderConfig ) ), IVAS_ERR_OK ) ) { return error; } @@ -1644,36 +1777,43 @@ ivas_error ivas_init_decoder_fx( Word32 ism_total_brate; error = IVAS_ERR_OK; - + move32(); output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); hDecoderConfig = st_ivas->hDecoderConfig; output_config = hDecoderConfig->output_config; ivas_total_brate = hDecoderConfig->ivas_total_brate; - + move32(); hDecoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); st_ivas->last_active_ivas_total_brate = ivas_total_brate; - + move32(); /*-----------------------------------------------------------------* * Set number of output channels for EXTERNAL output config. *-----------------------------------------------------------------*/ - IF( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { hDecoderConfig->nchan_out = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 ); - hDecoderConfig->nchan_out += st_ivas->nchan_ism; + move16(); + hDecoderConfig->nchan_out = add( hDecoderConfig->nchan_out, st_ivas->nchan_ism ); + move16(); } - ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - hDecoderConfig->nchan_out = st_ivas->nchan_transport + st_ivas->nchan_ism; + hDecoderConfig->nchan_out = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); + move16(); } - ELSE IF( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) + ELSE IF( !EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport; + move32(); } st_ivas->hOutSetup.nchan_out_woLFE = hDecoderConfig->nchan_out; + move32(); } /*-----------------------------------------------------------------* @@ -1681,32 +1821,40 @@ ivas_error ivas_init_decoder_fx( *-----------------------------------------------------------------*/ st_ivas->intern_config = output_config; - + move32(); ivas_output_init( &( st_ivas->hOutSetup ), output_config ); - - IF( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; + move32(); st_ivas->intern_config = IVAS_AUDIO_CONFIG_7_1_4; + move32(); st_ivas->hOutSetup.output_config = st_ivas->intern_config; + move32(); st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( st_ivas->intern_config ); } - - IF( st_ivas->ivas_format == SBA_ISM_FORMAT && output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; + move32(); st_ivas->intern_config = IVAS_AUDIO_CONFIG_HOA3; + move32(); st_ivas->hOutSetup.output_config = IVAS_AUDIO_CONFIG_HOA3; + move32(); st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( IVAS_AUDIO_CONFIG_HOA3 ); + move16(); } /* Only initialize transport setup if it is used */ - IF( st_ivas->transport_config != IVAS_AUDIO_CONFIG_INVALID ) + IF( NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_INVALID ) ) { ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config ); } - IF( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); @@ -1715,14 +1863,18 @@ ivas_error ivas_init_decoder_fx( ivas_renderer_select( st_ivas ); - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { IF( ( error = ivas_ls_custom_output_init_fx( st_ivas ) ) == IVAS_ERR_OK ) { st_ivas->hOutSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; + move32(); st_ivas->hOutSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; + move32(); st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; + move32(); st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; + move32(); } ELSE { @@ -1732,19 +1884,23 @@ ivas_error ivas_init_decoder_fx( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - IF( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); - IF( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled ) + test(); + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled ) { st_ivas->hLsSetupCustom->separate_ch_found = 0; - IF( st_ivas->hOutSetup.nchan_out_woLFE >= MCMASA_MIN_SPEAKERS_SEPARATE_CENTER ) + move16(); + IF( GE_16( st_ivas->hOutSetup.nchan_out_woLFE, MCMASA_MIN_SPEAKERS_SEPARATE_CENTER ) ) { /* check for a speaker at (0, 0) if minimum speaker count is available */ FOR( i = 0; i < st_ivas->hOutSetup.nchan_out_woLFE; i++ ) { - IF( L_shr( st_ivas->hOutSetup.ls_azimuth_fx[i], Q22 ) == 0 && L_shr( st_ivas->hOutSetup.ls_elevation_fx[i], Q22 ) == 0 ) + test(); + IF( ( L_shr( st_ivas->hOutSetup.ls_azimuth_fx[i], Q22 ) == 0 ) && ( L_shr( st_ivas->hOutSetup.ls_elevation_fx[i], Q22 ) == 0 ) ) { st_ivas->hIntSetup.separateChannelIndex = i; move16(); @@ -1765,36 +1921,36 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ - st_ivas->nCPE = 0; - st_ivas->nchan_transport = 1; - sce_id = 0; move16(); + st_ivas->nCPE = 0; move16(); + st_ivas->nchan_transport = 1; move16(); + sce_id = 0; move16(); - IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - ELSE IF( st_ivas->ivas_format == STEREO_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { st_ivas->nchan_transport = CPE_CHANNELS; + move16(); st_ivas->intern_config = IVAS_AUDIO_CONFIG_STEREO; + move32(); st_ivas->nSCE = 0; - st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ - cpe_id = 0; - move16(); - move16(); move16(); + st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ move16(); + cpe_id = 0; move16(); - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -1805,9 +1961,9 @@ ivas_error ivas_init_decoder_fx( } /* init EFAP for custom LS output and set hTransSetup */ - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hOutSetup.ls_azimuth_fx, st_ivas->hOutSetup.ls_elevation_fx, st_ivas->hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hOutSetup.ls_azimuth_fx, st_ivas->hOutSetup.ls_elevation_fx, st_ivas->hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } @@ -1815,40 +1971,39 @@ ivas_error ivas_init_decoder_fx( ivas_output_init( &( st_ivas->hTransSetup ), IVAS_AUDIO_CONFIG_STEREO ); } } - ELSE IF( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { Word32 element_brate_tmp[MAX_NUM_OBJECTS]; st_ivas->nSCE = st_ivas->nchan_transport; /* "st_ivas->nchan_transport" is known from ivas_dec_setup */ - st_ivas->nCPE = 0; - st_ivas->ism_extmeta_active = -1; - st_ivas->ism_extmeta_cnt = 0; - move16(); + st_ivas->nCPE = 0; move16(); + st_ivas->ism_extmeta_active = -1; move16(); + st_ivas->ism_extmeta_cnt = 0; move16(); - IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; move16(); st_ivas->nSCE = MAX_PARAM_ISM_WAVE; move16(); - IF( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nSCE, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nSCE, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) ) { return error; } @@ -1856,6 +2011,7 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); st_ivas->hSCE[sce_id]->hCoreCoder[0]->is_ism_format = 1; + move16(); } st_ivas->hISMDTX.sce_id_dtx = 0; @@ -1869,18 +2025,19 @@ ivas_error ivas_init_decoder_fx( { FOR( sce_id = 0; sce_id < st_ivas->nSCE; ++sce_id ) { - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = 2 + sce_id; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2 = add( 2, sce_id ); + move16(); } } } ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1888,50 +2045,69 @@ ivas_error ivas_init_decoder_fx( set_f( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 0.f, CLDFB_NO_COL_MAX ); set_s( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 0, CLDFB_NO_COL_MAX ); #endif - - IF( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup ) { - IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + Word16 hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); + IF( hodirac_flag ) { - return error; + IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) + { + return error; + } } + ELSE + { + IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + - IF( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) + test(); + test(); + IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + move16(); } ELSE { Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; - st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + move16(); IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; - + move16(); set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands; + move16(); } - ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ), st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - + move16(); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -1941,7 +2117,9 @@ ivas_error ivas_init_decoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, (res_dec) *CPE_CHANNELS ) ), IVAS_ERR_OK ) ) { return error; } @@ -1953,9 +2131,13 @@ ivas_error ivas_init_decoder_fx( } /* create CPE element for DFT Stereo like upmix */ - IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) + test(); + IF( st_ivas->sba_dirac_stereo_flag && ( st_ivas->nCPE == 0 ) ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); + + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -1964,9 +2146,9 @@ ivas_error ivas_init_decoder_fx( st_ivas->hCPE[0]->hCoreCoder[1] = NULL; } - IF( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1975,26 +2157,30 @@ ivas_error ivas_init_decoder_fx( /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } - ELSE IF( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */ st_ivas->ism_extmeta_active = -1; - st_ivas->ism_extmeta_cnt = 0; move16(); + st_ivas->ism_extmeta_cnt = 0; move16(); - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } @@ -2002,7 +2188,9 @@ ivas_error ivas_init_decoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2012,7 +2200,9 @@ ivas_error ivas_init_decoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2026,7 +2216,7 @@ ivas_error ivas_init_decoder_fx( /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } - ELSE IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { Word32 temp_brate[MAX_SCE]; st_ivas->ism_extmeta_active = -1; @@ -2035,59 +2225,79 @@ ivas_error ivas_init_decoder_fx( move16(); st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup ) { - IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + Word16 hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); + IF( hodirac_flag ) { - return error; + IF( NE_32( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) + { + return error; + } } - IF( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) + + test(); + test(); + test(); + IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + move16(); } ELSE { Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; - st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; - + move16(); set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands; + move16(); } - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ), st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2095,15 +2305,19 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2117,7 +2331,9 @@ ivas_error ivas_init_decoder_fx( /* create CPE element for DFT Stereo like upmix */ IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2126,22 +2342,22 @@ ivas_error ivas_init_decoder_fx( st_ivas->hCPE[0]->hCoreCoder[1] = NULL; } - IF( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_osba_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -2150,52 +2366,60 @@ ivas_error ivas_init_decoder_fx( /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } - ELSE IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { st_ivas->ism_extmeta_active = -1; + move16(); st_ivas->ism_extmeta_cnt = 0; + move16(); - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } k = 0; + move16(); ism_total_brate = 0; + move16(); + test(); WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { k++; + move16(); } - - IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { /* one separated object */ st_ivas->nSCE = 1; - + move16(); ism_total_brate = sep_object_brate[k - 2][0]; - IF( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ) != IVAS_ERR_OK ) + move32(); + IF( NE_32( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ), IVAS_ERR_OK ) ) { return error; } reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { Word32 temp_brate[MAX_SCE]; st_ivas->nSCE = st_ivas->nchan_ism; /* number of objects */ - + move16(); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1]; - ism_total_brate += temp_brate[sce_id]; + move16(); + ism_total_brate = L_add( ism_total_brate, temp_brate[sce_id] ); - IF( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ), IVAS_ERR_OK ) ) { return error; } @@ -2203,31 +2427,34 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_omasa_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -2237,32 +2464,36 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] ); } } - ELSE IF( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { - IF( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { /* init EFAP for custom LS setup */ - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { /*float2fix block: to be removed*/ floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); /*float2fix block end*/ - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } } st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) ); + move16(); st_ivas->nSCE = 0; - st_ivas->nCPE = st_ivas->nchan_transport / CPE_CHANNELS; - + move16(); + st_ivas->nCPE = shr( st_ivas->nchan_transport, 1 ); + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; - + move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2273,33 +2504,34 @@ ivas_error ivas_init_decoder_fx( } } - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { /* init EFAP for custom LS setup */ - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { /*float2fix block: to be removed*/ floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_azimuth, st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); floatToFixed_arrL( st_ivas->hLsSetupCustom->ls_elevation, st_ivas->hLsSetupCustom->ls_elevation_fx, Q22, st_ivas->hLsSetupCustom->num_spk ); /*float2fix block end*/ - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } } st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / CPE_CHANNELS; - st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; move16(); + st_ivas->nCPE = shr( MC_PARAMUPMIX_MAX_TRANSPORT_CHANS, 1 ); move16(); + st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; move16(); - IF( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + + IF( NE_32( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -2308,7 +2540,9 @@ ivas_error ivas_init_decoder_fx( move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2319,22 +2553,22 @@ ivas_error ivas_init_decoder_fx( } } - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* init EFAP for custom LS setup */ - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hLsSetupCustom->ls_azimuth_fx, st_ivas->hLsSetupCustom->ls_elevation_fx, st_ivas->hLsSetupCustom->num_spk, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -2343,7 +2577,10 @@ ivas_error ivas_init_decoder_fx( move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); + + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2356,56 +2593,60 @@ ivas_error ivas_init_decoder_fx( IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - ELSE IF( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { Word32 brate_sce, brate_cpe; ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - - IF( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) + move16(); + test(); + IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found ) + test(); + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found ) { /* If no speaker matching the separated channel, compute panning gains for the separated channel. */ IF( st_ivas->hVBAPdata == NULL ) { /* Distribute signal to all channels if VBAP is not properly initialized. */ Word16 inv_sqr, sqr, exp = 15, exp_sqr; + move16(); IF( EQ_16( st_ivas->hLsSetupCustom->num_spk, 1 ) ) { inv_sqr = 32767; + move16(); } ELSE { sqr = Sqrt16( st_ivas->hLsSetupCustom->num_spk, &exp ); inv_sqr = BASOP_Util_Divide1616_Scale( 32767, sqr, &exp_sqr ); exp_sqr = sub( exp_sqr, exp ); - IF( LT_16( exp, 0 ) ) + IF( ( exp < 0 ) ) { inv_sqr = shr( inv_sqr, exp ); } @@ -2423,7 +2664,7 @@ ivas_error ivas_init_decoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ), IVAS_ERR_OK ) ) { return error; } @@ -2434,8 +2675,8 @@ ivas_error ivas_init_decoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ - - IF( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) ) { return error; } @@ -2449,7 +2690,9 @@ ivas_error ivas_init_decoder_fx( /* create CPE element for DFT Stereo like upmix */ IF( st_ivas->sba_dirac_stereo_flag ) { - IF( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2462,7 +2705,9 @@ ivas_error ivas_init_decoder_fx( IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + move16(); st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + move16(); } } } @@ -2475,7 +2720,7 @@ ivas_error ivas_init_decoder_fx( /* set number of output channels used for synthesis/decoding */ n = getNumChanSynthesis( st_ivas ); - IF( GT_16( n, 0 ) ) + IF( n > 0 ) { IF( ( st_ivas->mem_hp20_out_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) { @@ -2499,43 +2744,51 @@ ivas_error ivas_init_decoder_fx( /*-------------------------------------------------------------------* * Allocate and initialize rendering handles *--------------------------------------------------------------------*/ - - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) - { - IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - /* ParamISM is handled separately from other common config */ - ELSE IF( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) ) { - IF( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) + IF( NE_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) { return error; } Word16 nchan_rend = num_src; - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + move16(); + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - nchan_rend--; /* Skip LFE channel -- added to the others */ + nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */ } FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { @@ -2543,69 +2796,77 @@ ivas_error ivas_init_decoder_fx( IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; + move16(); } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; SrcSpatial_p->q_Pos_p = Q31; + move16(); } IF( EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } } granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - + move16(); n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->renderer_type == RENDERER_MC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - IF( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { - IF( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { - IF( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM && st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, - st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, + st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; + move32(); - IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) + test(); + IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); - + move16(); n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ), IVAS_ERR_OK ) ) { return error; } @@ -2613,31 +2874,35 @@ ivas_error ivas_init_decoder_fx( ELSE { granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - + move16(); n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ), IVAS_ERR_OK ) ) { return error; } } } - IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - IF( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate TD renderer for the objects in DISC mode */ Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) { return error; } Word16 nchan_rend = num_src; - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + move16(); + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - nchan_rend--; /* Skip LFE channel -- added to the others */ + nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */ + move16(); } FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { @@ -2645,61 +2910,83 @@ ivas_error ivas_init_decoder_fx( IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; + move16(); } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; SrcSpatial_p->q_Pos_p = Q31; + move16(); } /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - IF( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && - ( st_ivas->ism_mode == ISM_MODE_DISC || st_ivas->ism_mode == ISM_SBA_MODE_DISC ) && - ( st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) - { - IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && + ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) && + ( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || + EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) || + EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || + EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) ) + { + IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF( ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { /* Allocate TD renderer for the objects in DISC mode */ Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) { return error; } Word16 nchan_rend = num_src; - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + move16(); + + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - nchan_rend--; /* Skip LFE channel -- added to the others */ + nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */ } FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { @@ -2707,9 +2994,11 @@ ivas_error ivas_init_decoder_fx( IF( Src_p->SrcSpatial_p != NULL ) { Src_p->SrcSpatial_p->q_Pos_p = Q31; + move16(); } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; SrcSpatial_p->q_Pos_p = Q31; + move16(); } } } @@ -2717,10 +3006,11 @@ ivas_error ivas_init_decoder_fx( /*-----------------------------------------------------------------* * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay *-----------------------------------------------------------------*/ - - IF( st_ivas->mc_mode == MC_MODE_MCT || st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + test(); + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { binauralization_delay_ns = st_ivas->binaural_latency_ns; + move32(); IF( st_ivas->hBinRenderer != NULL ) { IF( st_ivas->hBinRenderer->render_lfe ) @@ -2737,7 +3027,7 @@ ivas_error ivas_init_decoder_fx( } } - IF( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, output_Fs, binauralization_delay_ns ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, output_Fs, binauralization_delay_ns ) ), IVAS_ERR_OK ) ) { return error; } @@ -2754,7 +3044,7 @@ ivas_error ivas_init_decoder_fx( FOR( i = 0; i < numCldfbAnalyses; i++ ) { - IF( ( error = openCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -2766,7 +3056,7 @@ ivas_error ivas_init_decoder_fx( FOR( i = 0; i < numCldfbSyntheses; i++ ) { - IF( ( error = openCldfb_ivas( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -2777,11 +3067,15 @@ ivas_error ivas_init_decoder_fx( } /* CLDFB Interpolation weights */ - IF( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 ) + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !st_ivas->sba_dirac_stereo_flag && st_ivas->hDecoderConfig->nchan_out != 1 ) { #ifdef IVAS_FLOAT_FIXED #if 1 Word16 Q_cldfbSynDec = Q11; + move16(); #ifndef MSAN_FIX IF( st_ivas->hSpar ) { @@ -2793,11 +3087,19 @@ ivas_error ivas_init_decoder_fx( ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); #if 1 FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 + { + st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 + move16(); + } st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11; + move16(); FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21 - Q_cldfbSynDec ); // Scaling down from 21 to Q_cldfbSynDec + { + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], sub( 21, Q_cldfbSynDec ) ); // Scaling down from 21 to Q_cldfbSynDec + move16(); + } st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11; + move16(); IF( st_ivas->hSpar ) { fixedToFloat_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16 ); @@ -2812,7 +3114,7 @@ ivas_error ivas_init_decoder_fx( * Allocate and initialize limiter struct *-----------------------------------------------------------------*/ - IF( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_limiter_open( &st_ivas->hLimiter, hDecoderConfig->nchan_out, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -2827,16 +3129,17 @@ ivas_error ivas_init_decoder_fx( /* no module has yet open the TC buffer, open a default one */ n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) ) { return error; } + move16(); // For NS2SA } IF( st_ivas->hTcBuffer == NULL ) { /* we need the handle anyway, but without the buffer*/ - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_NONE, 0, 0, 0, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_NONE, 0, 0, 0, 1 ) ), IVAS_ERR_OK ) ) { return error; } @@ -2844,9 +3147,9 @@ ivas_error ivas_init_decoder_fx( IF( st_ivas->hJbmMetadata == NULL ) { - IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - IF( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_metadata_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -2857,7 +3160,7 @@ ivas_error ivas_init_decoder_fx( * Allocate floating-point output audio buffers *-----------------------------------------------------------------*/ st_ivas->p_out_len = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - + move16(); FOR( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { /* note: these are intra-frame heap memories */ @@ -4547,7 +4850,7 @@ void ivas_destroy_dec_fx( ivas_ism_renderer_close( &( st_ivas->hIsmRendererData ) ); /* DirAC handle */ - IF( st_ivas->ivas_format == ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); } @@ -4933,85 +5236,119 @@ void ivas_init_dec_get_num_cldfb_instances( { IVAS_FORMAT ivas_format; *numCldfbAnalyses = st_ivas->nchan_transport; + move16(); *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out; + move16(); - ivas_format = ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_NONE ) ? SBA_FORMAT : st_ivas->ivas_format; /* treat ISM_SBA_MODE_NONE just like SBA_FORMAT */ + test(); + IF( ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) ) + { + ivas_format = SBA_FORMAT; + move32(); + } + ELSE + { + ivas_format = st_ivas->ivas_format; + move32(); + } SWITCH( st_ivas->renderer_type ) { case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: case RENDERER_STEREO_PARAMETRIC: - IF( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { - *numCldfbAnalyses = st_ivas->nchan_transport + 1; + *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } - IF( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hOutSetup.separateChannelEnabled ) + test(); + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hOutSetup.separateChannelEnabled ) { - *numCldfbAnalyses = st_ivas->nchan_transport + 1; + *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } IF( ivas_format == SBA_ISM_FORMAT ) { - IF( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - *numCldfbAnalyses += st_ivas->nchan_ism; + *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism ); + move16(); } } - IF( ivas_format == MASA_ISM_FORMAT ) + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - IF( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - *numCldfbAnalyses += st_ivas->nchan_ism; + *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism ); + move16(); } - ELSE IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - *numCldfbAnalyses = st_ivas->nchan_transport + 1; + *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } } IF( st_ivas->hDiracDecBin->useTdDecorr ) { - *numCldfbAnalyses += 2; + *numCldfbAnalyses = add( *numCldfbAnalyses, 2 ); + move16(); } BREAK; case RENDERER_NON_DIEGETIC_DOWNMIX: case RENDERER_MONO_DOWNMIX: - IF( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == SBA_ISM_FORMAT ) + test(); + test(); + IF( EQ_32( ivas_format, ISM_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } BREAK; case RENDERER_DIRAC: - IF( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + move16(); - IF( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) + test(); + IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE; + move16(); } - ELSE IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) + ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + move16(); } ELSE { *numCldfbSyntheses = MAX_OUTPUT_CHANNELS; + move16(); } } - IF( ivas_format != SBA_FORMAT ) + IF( NE_32( ivas_format, SBA_FORMAT ) ) { - IF( GT_16( st_ivas->nchan_transport, 2 ) && NE_16( st_ivas->sba_planar, 0 ) ) + test(); + test(); + IF( GT_16( st_ivas->nchan_transport, 2 ) && ( st_ivas->sba_planar != 0 ) ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } - ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } } BREAK; @@ -5020,11 +5357,14 @@ void ivas_init_dec_get_num_cldfb_instances( { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } ELSE { *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas ); + move16(); } BREAK; case RENDERER_PARAM_ISM: @@ -5033,7 +5373,9 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_DISABLE: /* CLDFB not used */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); BREAK; case RENDERER_MC: case RENDERER_SBA_LINEAR_DEC: @@ -5047,37 +5389,46 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_OSBA_STEREO: case RENDERER_OSBA_AMBI: case RENDERER_OSBA_LS: - IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) + test(); + IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) ) + IF( st_ivas->sba_dirac_stereo_flag != 0 ) { *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } ELSE { *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + move16(); - IF( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) + test(); + IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE; + move16(); } - ELSE IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) + ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + move16(); } ELSE { *numCldfbSyntheses = MAX_OUTPUT_CHANNELS; + move16(); } - - IF( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - *numCldfbAnalyses = st_ivas->nchan_ism + st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + *numCldfbAnalyses = add( st_ivas->nchan_ism, st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans ); + move16(); } } } - ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* do nothing for ParamMC */ } @@ -5085,45 +5436,59 @@ void ivas_init_dec_get_num_cldfb_instances( { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } BREAK; case RENDERER_SBA_LINEAR_ENC: - IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_fx( st_ivas ); + move16(); } - ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - *numCldfbSyntheses = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + move16(); } - ELSE IF( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { *numCldfbAnalyses = st_ivas->nchan_transport; - *numCldfbSyntheses = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + move16(); + *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + move16(); } ELSE { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } BREAK; default: assert( 0 && "Renderer not handled for CLDFB reservation." ); } - - IF( st_ivas->mc_mode == MC_MODE_PARAMUPMIX && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) + test(); + test(); + IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - *numCldfbAnalyses = max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses ); + *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses ); + move16(); } ELSE { - *numCldfbAnalyses = max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbAnalyses ); + *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbAnalyses ); + move16(); } - *numCldfbSyntheses = max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbSyntheses ); + *numCldfbSyntheses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbSyntheses ); + move16(); } return; @@ -5354,12 +5719,12 @@ static ivas_error doSanityChecks_IVAS( output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); output_config = st_ivas->hDecoderConfig->output_config; - + move32(); /*-----------------------------------------------------------------* * Sanity checks *-----------------------------------------------------------------*/ - IF( output_Fs == 8000 ) + IF( EQ_32( output_Fs, 8000 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz output sampling rate is not supported in IVAS." ); } @@ -5368,46 +5733,56 @@ static ivas_error doSanityChecks_IVAS( assert( st_ivas->ivas_format != MONO_FORMAT && "\n Wrong IVAS format: MONO" ); /* Verify output configuration compatible with non-diegetic panning */ + test(); + test(); IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && ( st_ivas->ivas_format != MONO_FORMAT ) && ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_ISM1 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" ); } /* Verify stereo output configuration */ - IF( st_ivas->ivas_format == STEREO_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { - IF( output_config != IVAS_AUDIO_CONFIG_MONO && output_config != IVAS_AUDIO_CONFIG_STEREO && output_config != IVAS_AUDIO_CONFIG_5_1 && output_config != IVAS_AUDIO_CONFIG_7_1 && output_config != IVAS_AUDIO_CONFIG_5_1_2 && output_config != IVAS_AUDIO_CONFIG_5_1_4 && output_config != IVAS_AUDIO_CONFIG_7_1_4 && output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( NE_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) && NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Wrong output configuration specified for Stereo!" ); } } - ELSE IF( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { /* Verify ISM output configuration */ - IF( output_config == IVAS_AUDIO_CONFIG_INVALID ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for ISM" ); } } - ELSE IF( st_ivas->ivas_format == SBA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { /* Verify SBA output coniguration */ - IF( output_config == IVAS_AUDIO_CONFIG_INVALID ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for SBA" ); } } - ELSE IF( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { - IF( output_config == IVAS_AUDIO_CONFIG_INVALID ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for MASA!" ); } } - ELSE IF( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { /* Verify MC output configuration */ - IF( output_config == IVAS_AUDIO_CONFIG_INVALID || output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_INVALID ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for Multi-channel" ); } @@ -5416,7 +5791,10 @@ static ivas_error doSanityChecks_IVAS( IF( st_ivas->hDecoderConfig->Opt_Headrotation ) { - IF( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + test(); + test(); + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { return IVAS_ERROR( IVAS_ERR_HEAD_ROTATION_NOT_SUPPORTED, "Wrong set-up: Head-rotation not supported in this configuration" ); } @@ -5424,7 +5802,10 @@ static ivas_error doSanityChecks_IVAS( IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - IF( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + test(); + test(); + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { return IVAS_ERROR( IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED, "Wrong set-up: External orientation not supported in this configuration" ); } @@ -5432,7 +5813,8 @@ static ivas_error doSanityChecks_IVAS( IF( st_ivas->hDecoderConfig->Opt_dpid_on ) { - IF( !( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { return IVAS_ERROR( IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED, "Wrong set-up: Directivity is not supported in this output configuration." ); } @@ -5446,9 +5828,10 @@ static ivas_error doSanityChecks_IVAS( } } - IF( st_ivas->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - IF( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + test(); + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); } diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 7d4820c14..1d56a3412 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -8,12 +8,17 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( { IVAS_FORMAT ivas_format; *numCldfbAnalyses = st_ivas->nchan_transport; + move16(); *numCldfbSyntheses = st_ivas->hDecoderConfig->nchan_out; - + move16(); ivas_format = st_ivas->ivas_format; + move32(); + + test(); IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MODE_NONE ) ) { ivas_format = SBA_FORMAT; /* treat ISM_SBA_MODE_NONE just like SBA_FORMAT */ + move32(); } SWITCH( st_ivas->renderer_type ) @@ -24,73 +29,94 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } - + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->hOutSetup.separateChannelEnabled ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } - IF( EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism ); + move16(); } } - IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + test(); + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { *numCldfbAnalyses = add( *numCldfbAnalyses, st_ivas->nchan_ism ); + move16(); } - ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } } IF( st_ivas->hDiracDecBin->useTdDecorr ) { *numCldfbAnalyses = add( *numCldfbAnalyses, 2 ); + move16(); } BREAK; case RENDERER_NON_DIEGETIC_DOWNMIX: case RENDERER_MONO_DOWNMIX: - IF( EQ_16( ivas_format, ISM_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + test(); + test(); + test(); + IF( EQ_32( ivas_format, ISM_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } BREAK; case RENDERER_DIRAC: - IF( EQ_16( ivas_format, SBA_FORMAT ) ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; - - IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) ) + move16(); + test(); + IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE; + move16(); } - ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) + ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + move16(); } ELSE { *numCldfbSyntheses = MAX_OUTPUT_CHANNELS; + move16(); } } - IF( NE_16( ivas_format, SBA_FORMAT ) ) + IF( NE_32( ivas_format, SBA_FORMAT ) ) { - IF( GT_16( st_ivas->nchan_transport, 2 ) && NE_16( st_ivas->sba_planar, 0 ) ) + test(); + test(); + IF( GT_16( st_ivas->nchan_transport, 2 ) && ( st_ivas->sba_planar != 0 ) ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } - ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { *numCldfbAnalyses = add( st_ivas->nchan_transport, 1 ); + move16(); } } BREAK; @@ -99,11 +125,14 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } ELSE { *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_ivas_fx( st_ivas ); + move16(); } BREAK; case RENDERER_PARAM_ISM: @@ -112,7 +141,9 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( case RENDERER_DISABLE: /* CLDFB not used */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); BREAK; case RENDERER_MC: case RENDERER_SBA_LINEAR_DEC: @@ -126,37 +157,47 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( case RENDERER_OSBA_STEREO: case RENDERER_OSBA_AMBI: case RENDERER_OSBA_LS: - IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) + test(); + IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) ) + IF( st_ivas->sba_dirac_stereo_flag != 0 ) { *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } ELSE { *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + move16(); - IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) ) + test(); + IF( st_ivas->hOutSetup.is_loudspeaker_setup && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { *numCldfbSyntheses = st_ivas->hOutSetup.nchan_out_woLFE; + move16(); } - ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) + ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) { *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + move16(); } ELSE { *numCldfbSyntheses = MAX_OUTPUT_CHANNELS; + move16(); } - IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { *numCldfbAnalyses = add( st_ivas->nchan_ism, st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans ); + move16(); } } } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* do nothing for ParamMC */ } @@ -164,45 +205,60 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } BREAK; case RENDERER_SBA_LINEAR_ENC: - IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { *numCldfbSyntheses = param_mc_get_num_cldfb_syntheses_ivas_fx( st_ivas ); + move16(); } - ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + move16(); } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { *numCldfbAnalyses = st_ivas->nchan_transport; + move16(); *numCldfbSyntheses = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); + move16(); } ELSE { /* CLDFB not used in rendering */ *numCldfbAnalyses = 0; + move16(); *numCldfbSyntheses = 0; + move16(); } BREAK; default: assert( 0 && "Renderer not handled for CLDFB reservation." ); } - IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + test(); + IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MAX_INPUT_CHANS, *numCldfbAnalyses ); + move16(); } ELSE { *numCldfbAnalyses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbAnalyses ); + move16(); } *numCldfbSyntheses = s_max( MC_PARAMUPMIX_MIN_CLDFB, *numCldfbSyntheses ); + move16(); } return; diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index e15b3a421..b806bc79c 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -73,7 +73,9 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( error = IVAS_ERR_OK; nCPE_old = st_ivas->nCPE; + move16(); nSCE_old = st_ivas->nSCE; + move16(); /* temporarily set the ism mode back to the old one, otherwise this can give wrong results*/ ism_mode = st_ivas->ism_mode; @@ -85,7 +87,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( move16(); nchan_out_buff_old = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); - IF( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -97,7 +99,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ), IVAS_ERR_OK ) ) { return error; } @@ -105,7 +107,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ - IF( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_transport_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_transport_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -155,7 +157,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -163,7 +165,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -181,27 +183,30 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( *-----------------------------------------------------------------*/ /* switching from ParamISM to DiscISM */ + test(); IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) { /* Deallocate the ParamISM struct */ ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + test(); IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* close the parametric binaural renderer */ ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open the TD Binaural renderer */ + test(); IF( st_ivas->hHrtfTD == NULL || st_ivas->hBinRendererTd == NULL ) { Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hDecoderConfig->output_config, NULL, st_ivas->hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -212,19 +217,19 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( { /* close the ISM renderer and reinitialize */ ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); - IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - IF( EQ_16( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { /* close the parametric binaural renderer */ ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open Crend Binaural renderer */ - IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -235,23 +240,25 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( } /* switching from Discrete ISM to ParamISM */ + test(); IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_32( last_ism_mode, ISM_MODE_DISC ) ) { /* Allocate and initialize the ParamISM struct */ - IF( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } + test(); IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* open the parametric binaural renderer */ - IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -262,7 +269,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; - IF( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { ivas_reverb_close( &st_ivas->hReverb ); } @@ -277,12 +284,12 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { /* open the parametric binaural renderer */ - IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs_fx( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -296,7 +303,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( * CLDFB instances *-----------------------------------------------------------------*/ - IF( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -308,12 +315,12 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } #if 1 /* TODO: remove float code */ - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } @@ -335,6 +342,8 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( tc_nchan_full_new = tc_nchan_tc_new; move16(); + test(); + test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; @@ -343,6 +352,10 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( move16(); } + test(); + test(); + test(); + test(); IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { tc_nchan_full_new = 0; @@ -350,10 +363,13 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( } /* reconfigure buffer */ + test(); + test(); + test(); IF( NE_32( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) ) { - IF( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) { return error; } @@ -701,34 +717,42 @@ ivas_error ivas_ism_dec_config_fx( error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - + move32(); /* Assumes that num of input objects are constant */ nchan_transport_old = st_ivas->nchan_ism; + move16(); - IF( EQ_16( last_ism_mode, ISM_MODE_PARAM ) ) + if ( EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) { nchan_transport_old = MAX_PARAM_ISM_WAVE; + move16(); } + test(); IF( !st_ivas->bfi && NE_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) ) { /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->nchan_ism, ivas_total_brate ); - + move32(); st_ivas->nchan_transport = st_ivas->nchan_ism; - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + move16(); + + if ( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + move16(); + if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { st_ivas->hDecoderConfig->nchan_out = st_ivas->nchan_ism; + move16(); } } - IF( NE_16( st_ivas->ini_active_frame, 0 ) ) + if ( st_ivas->ini_active_frame != 0 ) { /* ISM bit-rate switching */ { + test(); IF( ( NE_16( st_ivas->ism_mode, last_ism_mode ) ) || ( NE_32( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) { IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, @@ -744,17 +768,20 @@ ivas_error ivas_ism_dec_config_fx( ELSE IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { st_ivas->nchan_transport = st_ivas->nchan_ism; - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + move16(); + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { st_ivas->hDecoderConfig->nchan_out = st_ivas->nchan_ism; + move16(); } } /* ISM mode switching */ - IF( NE_16( st_ivas->ism_mode, last_ism_mode ) ) + IF( NE_32( st_ivas->ism_mode, last_ism_mode ) ) { IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, data ) ), @@ -769,21 +796,25 @@ ivas_error ivas_ism_dec_config_fx( { case 1: st_ivas->transport_config = IVAS_AUDIO_CONFIG_ISM1; + move32(); BREAK; case 2: st_ivas->transport_config = IVAS_AUDIO_CONFIG_ISM2; + move32(); BREAK; case 3: st_ivas->transport_config = IVAS_AUDIO_CONFIG_ISM3; + move32(); BREAK; case 4: st_ivas->transport_config = IVAS_AUDIO_CONFIG_ISM4; + move32(); BREAK; default: st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID; + move32(); BREAK; } - return error; } #else diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index 2fd8bf77b..d891ccfca 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -65,6 +65,7 @@ void ivas_ism_dtx_dec_fx( nchan_ism_prev = st_ivas->nchan_ism; move16(); + test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { /* 'nchan_ism' was read in ivas_dec_setup() */ @@ -82,6 +83,7 @@ void ivas_ism_dtx_dec_fx( ivas_ism_metadata_sid_dec_fx( st_ivas->hSCE, ivas_total_brate, st_ivas->bfi, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, &flag_noisy_speech, &sce_id_dtx, st_ivas->hIsmMetaData, nb_bits_metadata ); + test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && !st_ivas->bfi ) { IF( st_ivas->hParamIsmDec != NULL ) @@ -96,7 +98,7 @@ void ivas_ism_dtx_dec_fx( set16_fx( md_diff_flag, 1, nchan_ism ); - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { FOR( ch = 0; ch < nchan_ism; ch++ ) { @@ -107,7 +109,7 @@ void ivas_ism_dtx_dec_fx( } } /* synch common seed between SCEs */ - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) ) { FOR( ch = 0; ch < nchan_ism; ++ch ) { @@ -121,6 +123,7 @@ void ivas_ism_dtx_dec_fx( st_ivas->hISMDTX.ism_dtx_hangover_cnt = 0; move16(); + test(); IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) && !st_ivas->bfi ) { FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) @@ -137,10 +140,11 @@ void ivas_ism_dtx_dec_fx( st = st_ivas->hSCE[ch]->hCoreCoder[0]; st->bit_stream = st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream; st->next_bit_pos = 0; /* note: needed in paramISM -> discISM switching */ - st->cng_ism_flag = 1; move16(); + st->cng_ism_flag = 1; move16(); st->L_frame = s_min( st->L_frame, L_FRAME16k ); /* note: needed for switching from active frame with L_frame=640 to CNG in object with no SID */ + move16(); } } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 0543b1519..2c2e61b70 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -161,6 +161,7 @@ static void ism_metadata_smooth_fx( { diff_fx = L_sub( diff_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); hIsmMetaData->last_azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); + move32(); } ELSE IF( LT_32( diff_fx, ISM_AZIMUTH_MIN_FX ) ) { @@ -174,9 +175,19 @@ static void ism_metadata_smooth_fx( } ELSE IF( GT_32( L_abs( diff_fx ), L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ) ) ) { - hIsmMetaData->azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, ( GE_32( diff_fx, 0 ) ? 1 : -1 ) * L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ) ); + Word32 temp; + IF( ( diff_fx > 0 ) ) + { + temp = L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ); + } + ELSE + { + temp = L_negate( L_shl( CNG_MD_MAX_DIFF_AZIMUTH, Q22 ) ); + } + hIsmMetaData->azimuth_fx = L_add( hIsmMetaData->last_azimuth_fx, temp ); + move32(); } - ELSE IF( NE_32( diff_fx, 0 ) ) + ELSE IF( diff_fx != 0 ) { hIsmMetaData->azimuth_fx = hIsmMetaData->last_true_azimuth_fx; move32(); @@ -185,6 +196,7 @@ static void ism_metadata_smooth_fx( IF( GT_32( hIsmMetaData->azimuth_fx, ISM_AZIMUTH_MAX_FX ) ) { hIsmMetaData->azimuth_fx = L_sub( hIsmMetaData->azimuth_fx, ( ISM_AZIMUTH_MAX_FX - ISM_AZIMUTH_MIN_FX ) ); + move32(); } /* smooth elevation */ @@ -197,7 +209,17 @@ static void ism_metadata_smooth_fx( } ELSE IF( GT_32( L_abs( diff_fx ), L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ) ) ) { - hIsmMetaData->elevation_fx = L_add( hIsmMetaData->last_elevation_fx, ( GE_32( diff_fx, 0 ) ? 1 : -1 ) * L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ) ); + Word32 temp; + IF( ( diff_fx > 0 ) ) + { + temp = L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ); + } + ELSE + { + temp = L_negate( L_shl( CNG_MD_MAX_DIFF_ELEVATION, Q22 ) ); + } + hIsmMetaData->elevation_fx = L_add( hIsmMetaData->last_elevation_fx, temp ); + move32(); } } @@ -753,6 +775,7 @@ ivas_error ivas_ism_metadata_dec_fx( Word16 nbands, nblocks; Word16 md_diff_flag[MAX_NUM_OBJECTS]; ivas_error error; + Word32 res_dec, res_frac; move16(); push_wmops( "ism_meta_dec" ); @@ -762,10 +785,9 @@ ivas_error ivas_ism_metadata_dec_fx( move16(); nchan_transport_prev = *nchan_transport; move16(); - - last_bit_pos = extract_l( L_sub( ( ism_total_brate / FRAMES_PER_SEC ), 1 ) ); + iDiv_and_mod_32( ism_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + last_bit_pos = extract_l( L_sub( res_dec, 1 ) ); bstr_orig = st0->bit_stream; - move16(); next_bit_pos_orig = st0->next_bit_pos; move16(); st0->next_bit_pos = 0; @@ -780,7 +802,7 @@ ivas_error ivas_ism_metadata_dec_fx( /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_ISM_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st0->bit_stream[last_bit_pos - i]; + bstr_meta[i] = st0->bit_stream[sub( last_bit_pos, i )]; move16(); } st0->bit_stream = bstr_meta; @@ -797,13 +819,16 @@ ivas_error ivas_ism_metadata_dec_fx( { /* number of objects was read in ivas_dec_setup() */ st0->next_bit_pos = add( st0->next_bit_pos, NO_BITS_MASA_ISM_NO_OBJ ); + move32(); } ELSE IF( NE_32( ism_mode, ISM_MASA_MODE_DISC ) && NE_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /* number of objects was read in ivas_dec_setup() */ st0->next_bit_pos = add( st0->next_bit_pos, nchan_ism ); + move16(); ism_mode = ivas_ism_mode_select( nchan_ism, ism_total_brate ); + move16(); } IF( EQ_32( ism_mode, ISM_MODE_PARAM ) ) @@ -932,7 +957,7 @@ ivas_error ivas_ism_metadata_dec_fx( lowrate_metadata_flag[ch] = hIsmMeta[ch]->ism_md_lowrate_flag; move16(); - IF( EQ_16( null_metadata_flag[ch], 0 ) ) + IF( null_metadata_flag[ch] == 0 ) { ism_metadata_flag_global = s_or( ism_metadata_flag_global, lowrate_metadata_flag[ch] ); } @@ -1072,7 +1097,7 @@ ivas_error ivas_ism_metadata_dec_fx( } ELSE { - IF( EQ_16( *ism_extmeta_active, 0 ) ) + IF( *ism_extmeta_active == 0 ) { hIsmMetaData->yaw_fx = 0; move32(); @@ -1187,6 +1212,7 @@ ivas_error ivas_ism_metadata_dec_fx( { ism_metadata_smooth_fx( hIsmMeta, ism_total_brate, nchan_ism ); hISMDTX.ism_dtx_hangover_cnt = add( hISMDTX.ism_dtx_hangover_cnt, 1 ); + move16(); } IF( EQ_32( ism_mode, ISM_SBA_MODE_DISC ) ) @@ -1481,7 +1507,7 @@ static void decode_angle_indices_fx( sgn = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 0 ) ) + IF( get_next_indice_fx( st0, 1 ) == 0 ) { nbits_diff_angle1 = 1; move16(); @@ -1497,19 +1523,19 @@ static void decode_angle_indices_fx( move16(); } - nbits_diff_angle1++; + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); /* read until the stop bit */ WHILE( LT_16( nbits_diff_angle1, sub( ISM_AZIMUTH_NBITS, 1 ) ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) { - diff++; - nbits_diff_angle1++; + diff = add( diff, 1 ); + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); } IF( LT_16( nbits_diff_angle1, sub( ISM_AZIMUTH_NBITS, 1 ) ) ) { /* count stop bit */ - nbits_diff_angle1++; + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); } } idx_angle1 = add( angle->last_angle1_idx, i_mult2( sgn, diff ) ); @@ -1520,7 +1546,7 @@ static void decode_angle_indices_fx( { idx_angle1 = sub( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ); /* +180° -> -180° */ } - ELSE IF( LT_16( idx_angle1, 0 ) ) + ELSE IF( idx_angle1 < 0 ) { idx_angle1 = add( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ); /* -180° -> +180° */ } @@ -1534,7 +1560,7 @@ static void decode_angle_indices_fx( /* sanity check in case of FER or BER */ test(); - IF( LT_16( idx_angle1, 0 ) || GT_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) + IF( ( idx_angle1 < 0 ) || GT_16( idx_angle1, sub( shl( 1, ISM_AZIMUTH_NBITS ), 1 ) ) ) { idx_angle1 = angle->last_angle1_idx; move16(); @@ -1544,11 +1570,11 @@ static void decode_angle_indices_fx( * Elevation/pitch decoding and dequantization *----------------------------------------------------------------*/ - IF( EQ_16( non_diegetic_flag, 0 ) ) + IF( non_diegetic_flag == 0 ) { /* Decode elevation/pitch index */ test(); - IF( EQ_16( *flag_abs_angle1, 0 ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* elevation_abs_flag */ + IF( ( *flag_abs_angle1 == 0 ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) /* elevation_abs_flag */ { idx_angle2 = get_next_indice_fx( st0, ISM_ELEVATION_NBITS ); } @@ -1559,7 +1585,7 @@ static void decode_angle_indices_fx( sgn = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 0 ) ) + IF( get_next_indice_fx( st0, 1 ) == 0 ) { nbits_diff_angle2 = 1; move16(); @@ -1596,7 +1622,7 @@ static void decode_angle_indices_fx( /* sanity check in case of FER or BER */ test(); - IF( LT_16( idx_angle2, 0 ) || GT_16( idx_angle2, sub( shl( 1, ISM_ELEVATION_NBITS ), 1 ) ) ) + IF( ( idx_angle2 < 0 ) || GT_16( idx_angle2, sub( shl( 1, ISM_ELEVATION_NBITS ), 1 ) ) ) { idx_angle2 = angle->last_angle2_idx; move16(); @@ -1798,7 +1824,7 @@ static Word16 decode_radius_fx( sgn = 1; move16(); - IF( EQ_16( get_next_indice_fx( st0, 1 ), 0 ) ) + IF( get_next_indice_fx( st0, 1 ) == 0 ) { nbits_diff_radius = 1; move16(); @@ -1814,19 +1840,19 @@ static Word16 decode_radius_fx( move16(); } - nbits_diff_radius++; + nbits_diff_radius = add( nbits_diff_radius, 1 ); /* read until the stop bit */ WHILE( LT_16( nbits_diff_radius, ISM_RADIUS_NBITS ) && EQ_16( get_next_indice_fx( st0, 1 ), 1 ) ) { - diff++; - nbits_diff_radius++; + diff = add( diff, 1 ); + nbits_diff_radius = add( nbits_diff_radius, 1 ); } IF( LT_16( nbits_diff_radius, ISM_RADIUS_NBITS ) ) { /* count stop bit */ - nbits_diff_radius++; + nbits_diff_radius = add( nbits_diff_radius, 1 ); } } idx_radius = add( *last_radius_idx, i_mult2( sgn, diff ) ); @@ -1834,7 +1860,7 @@ static Word16 decode_radius_fx( /* sanity check in case of FER or BER */ test(); - IF( LT_16( idx_radius, 0 ) || GT_16( idx_radius, sub( shl( 1, ISM_RADIUS_NBITS ), 1 ) ) ) + IF( ( idx_radius < 0 ) || GT_16( idx_radius, sub( shl( 1, ISM_RADIUS_NBITS ), 1 ) ) ) { idx_radius = *last_radius_idx; move16(); @@ -2197,7 +2223,8 @@ void ivas_ism_metadata_sid_dec_fx( } idx = get_next_indice_fx( st0, nBits_coh ); - hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, ( ( 1 << nBits_coh ) - 1 ) ); + hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = div_s( idx, sub( ( shl( 1, nBits_coh ) ), 1 ) ); + move16(); } } @@ -2245,7 +2272,9 @@ void ivas_ism_metadata_sid_dec_fx( } /* take into account padding bits as metadata bits to keep later bitrate checks valid */ - nb_bits_metadata[*sce_id_dtx] = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; + Word32 res_dec, res_frac; + iDiv_and_mod_32( sub( IVAS_SID_5k2, SID_2k40 ), FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + nb_bits_metadata[*sce_id_dtx] = (Word16) res_dec; move16(); /* set the bitstream pointer to its original position */ diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 3124f80a5..5aad96908 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -70,9 +70,9 @@ static void ivas_param_ism_dec_dequant_DOA_fx( FOR( i = 0; i < nchan_ism; i++ ) { hParamIsmDec->azimuth_values_fx[i] = ism_dequant_meta_fx( hParamIsm->azi_index[i], ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); - move32(); + move16(); hParamIsmDec->elevation_values_fx[i] = ism_dequant_meta_fx( hParamIsm->ele_index[i], ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); - move32(); + move16(); } return; @@ -198,14 +198,14 @@ static void ivas_ism_get_proto_matrix_fx( { FOR( idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) { - IF( GT_32( hOutSetup.ls_azimuth_fx[idx], 0 ) ) + IF( hOutSetup.ls_azimuth_fx[idx] > 0 ) { proto_matrix[idx] = shl_sat( ONE_IN_Q14, 1 ); move16(); - proto_matrix[idx + hOutSetup.nchan_out_woLFE] = 0; + proto_matrix[add( idx, hOutSetup.nchan_out_woLFE )] = 0; move16(); } - ELSE IF( LT_32( hOutSetup.ls_azimuth_fx[idx], 0 ) ) + ELSE IF( hOutSetup.ls_azimuth_fx[idx] < 0 ) { proto_matrix[idx] = 0; move16(); @@ -307,7 +307,7 @@ static void ivas_param_ism_collect_slot_fx( Word16 exp_ref_power_buf[CLDFB_NO_CHANNELS_MAX]; Word16 exp_cx_diag_buf[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; set16_fx( exp_ref_power_buf, *exp_ref_power, CLDFB_NO_CHANNELS_MAX ); - for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { set16_fx( exp_cx_diag_buf[i], *exp_cx_diag, PARAM_ISM_MAX_DMX ); } @@ -320,17 +320,21 @@ static void ivas_param_ism_collect_slot_fx( FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { tmp_fx = 0; + move32(); exp_tmp = 0; + move32(); Word32 var1 = Mpy_32_32( Cldfb_RealBuffer_in_fx[bin_idx], Cldfb_RealBuffer_in_fx[bin_idx] ); // 2 * exp_real Word32 var2 = Mpy_32_32( Cldfb_ImagBuffer_in_fx[bin_idx], Cldfb_ImagBuffer_in_fx[bin_idx] ); // 2 * exp_imag tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var1, add( exp_real, exp_real ), &exp_tmp ); tmp_fx = BASOP_Util_Add_Mant32Exp( tmp_fx, exp_tmp, var2, add( exp_imag, exp_imag ), &exp_tmp ); Word16 exp_cx_diag_new = 0, exp_ref_power_new = 0; + move16(); + move16(); cx_diag_fx[bin_idx][ch] = BASOP_Util_Add_Mant32Exp( cx_diag_fx[bin_idx][ch], exp_cx_diag_buf[bin_idx][ch], tmp_fx, exp_tmp, &exp_cx_diag_new ); - move32(); + move16(); ref_power_fx[bin_idx] = BASOP_Util_Add_Mant32Exp( ref_power_fx[bin_idx], exp_ref_power_buf[bin_idx], tmp_fx, exp_tmp, &exp_ref_power_new ); - move32(); + move16(); exp_cx_diag_buf[bin_idx][ch] = exp_cx_diag_new; move16(); exp_ref_power_buf[bin_idx] = exp_ref_power_new; @@ -340,6 +344,8 @@ static void ivas_param_ism_collect_slot_fx( /*make common exponent*/ Word16 max_exp_cx_diag = exp_cx_diag_buf[0][0], max_exp_ref_power = exp_ref_power_buf[0]; + move16(); + move16(); FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { FOR( j = 0; j < PARAM_ISM_MAX_DMX; j++ ) @@ -354,12 +360,16 @@ static void ivas_param_ism_collect_slot_fx( FOR( j = 0; j < PARAM_ISM_MAX_DMX; j++ ) { cx_diag_fx[i][j] = L_shr_r( cx_diag_fx[i][j], sub( max_exp_cx_diag, exp_cx_diag_buf[i][j] ) ); + move16(); } ref_power_fx[i] = L_shr_r( ref_power_fx[i], sub( max_exp_ref_power, exp_ref_power_buf[i] ) ); + move16(); } *exp_cx_diag = max_exp_cx_diag; + move16(); *exp_ref_power = max_exp_ref_power; + move16(); return; } @@ -429,28 +439,34 @@ static void ivas_param_ism_compute_mixing_matrix_fx( assert( ( nchan_ism == 3 ) || ( nchan_ism == 4 ) ); assert( nchan_transport == 2 ); + test(); IF( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag ) { num_wave = nchan_ism; + move16(); } ELSE { num_wave = MAX_PARAM_ISM_WAVE; + move16(); } set32_fx( response_matrix_fx, 0, PARAM_ISM_MAX_CHAN * MAX_NUM_OBJECTS ); response_matrix_e = 0; + move16(); /* loop over parameter bands to compute the mixing matrix */ FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) { brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; + move16(); brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; + move16(); /* Compute covaraince matrix from direct response*/ FOR( w = 0; w < num_wave; w++ ) { set32_fx( cy_diag_tmp_fx[w], 0, nchan_out_woLFE ); - + test(); IF( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag ) { dir_res_ptr_fx = direct_response_fx[w]; @@ -458,11 +474,14 @@ static void ivas_param_ism_compute_mixing_matrix_fx( ELSE { obj_indx = hParamIsmDec->hParamIsm->obj_indices[band_idx][0][w]; + move16(); dir_res_ptr_fx = direct_response_fx[obj_indx]; } Copy32( dir_res_ptr_fx, response_matrix_fx + w * nchan_out_woLFE, nchan_out_woLFE ); // Q30 dir_res_ptr_e = 1; + move16(); response_matrix_e = 1; + move16(); /* we only need the diagonal of Cy*/ matrix_product_diag_fx( dir_res_ptr_fx, dir_res_ptr_e, nchan_out_woLFE, 1, 0, dir_res_ptr_fx, dir_res_ptr_e, 1, nchan_out_woLFE, 0, cy_diag_tmp_fx[w], &cy_diag_tmp_e[w] ); } @@ -474,6 +493,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( set16_fx( cy_diag_e_arr, 0, nchan_out_woLFE ); FOR( w = 0; w < num_wave; w++ ) { + test(); IF( hParamIsmDec->hParamIsm->flag_noisy_speech || hISMDTX.dtx_flag ) { // direct_power[w] = ( 1.0f / nchan_ism ) * ref_power[bin_idx]; @@ -495,7 +515,8 @@ static void ivas_param_ism_compute_mixing_matrix_fx( direct_power_fx[w] = Mpy_32_16_1( ref_power_fx[bin_idx], hParamIsmDec->power_ratios_fx[band_idx][0][w] ); } direct_power_e = ref_power_e; - IF( NE_32( direct_power_fx[w], 0 ) ) + move16(); + IF( direct_power_fx[w] != 0 ) { FOR( i = 0; i < nchan_out_woLFE; i++ ) { @@ -503,9 +524,11 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } } temp_e[w] = direct_power_e; + move16(); direct_power_fx[w] = Sqrt32( direct_power_fx[w], &temp_e[w] ); } cy_diag_e = cy_diag_e_arr[0]; + move16(); FOR( i = 1; i < nchan_out_woLFE; i++ ) { cy_diag_e = s_max( cy_diag_e, cy_diag_e_arr[i] ); @@ -516,6 +539,7 @@ static void ivas_param_ism_compute_mixing_matrix_fx( } direct_power_e = temp_e[0]; + move16(); FOR( w = 1; w < num_wave; w++ ) { direct_power_e = s_max( direct_power_e, temp_e[w] ); @@ -653,12 +677,12 @@ static void ivas_param_ism_render_slot_fx( tmp_1_fx = L_deposit_h( hParamIsmDec->hParamIsmRendering->interpolator_fx[interpolator_idx] ); /* Q31 */ Word16 res_exp = 0; - Word16 real_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp; - Word16 imag_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp; - Word16 i, j, k; move16(); + Word16 real_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp; move16(); + Word16 imag_buf_exp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp; move16(); + Word16 i, j, k; /*exponent buffers to handle variable exp*/ Word16 exp_buf_real[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; @@ -696,7 +720,6 @@ static void ivas_param_ism_render_slot_fx( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx] = BASOP_Util_Add_Mant32Exp( Cldfb_ImagBuffer_fx[outchIdx][out_slot_idx][bin_idx], imag_buf_exp, tmp_5, res_exp + hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp, &imag_buf_exp ); move32(); - exp_buf_real[outchIdx][out_slot_idx][bin_idx] = real_buf_exp; move16(); exp_buf_imag[outchIdx][out_slot_idx][bin_idx] = imag_buf_exp; @@ -932,7 +955,6 @@ static void ivas_param_ism_update_mixing_matrix_fx( } Copy( mixing_matrix_exp, hParamIsmDec->hParamIsmRendering->exp_mixing_matrix_lin_old_fx, CLDFB_NO_CHANNELS_MAX ); - move16(); return; } @@ -987,7 +1009,7 @@ ivas_error ivas_param_ism_dec_open_fx( ivas_error error; error = IVAS_ERR_OK; - + move32(); push_wmops( "ivas_param_ism_dec_open" ); /*-----------------------------------------------------------------* @@ -1018,7 +1040,7 @@ ivas_error ivas_param_ism_dec_open_fx( output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); output_config = st_ivas->hDecoderConfig->output_config; - + move32(); ivas_param_ism_config_fx( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); // assuming Q14 for gains; /*-----------------------------------------------------------------* @@ -1036,11 +1058,13 @@ ivas_error ivas_param_ism_dec_open_fx( hSpatParamRendCom->slots_rendered = 0; move16(); hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + move16(); /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); move16(); hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; + move16(); FOR( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ ) { @@ -1059,12 +1083,13 @@ ivas_error ivas_param_ism_dec_open_fx( *-----------------------------------------------------------------*/ /* hIntSetup and hOutSetup differs only for Binaural rendering */ - IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { /* nchan_out is essential for memory initialization for CLDFB Synthesis */ st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism; move16(); st_ivas->hIntSetup.is_loudspeaker_setup = 1; + move16(); } hOutSetup = st_ivas->hIntSetup; @@ -1094,8 +1119,8 @@ ivas_error ivas_param_ism_dec_open_fx( test(); test(); test(); - IF( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || - output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Initialize efap handle */ IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) @@ -1150,7 +1175,7 @@ ivas_error ivas_param_ism_dec_open_fx( IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { nchan_full = nchan_transport; - + move16(); hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; } @@ -1183,7 +1208,8 @@ ivas_error ivas_param_ism_dec_open_fx( IF( st_ivas->hTcBuffer == NULL ) { - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + move16(); // NS2SA + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) ) { return error; @@ -1198,7 +1224,8 @@ ivas_error ivas_param_ism_dec_open_fx( { Word16 nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; move16(); - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + move16(); // NS2SA + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1426,6 +1453,7 @@ void ivas_param_ism_dec_close_fx( AUDIO_CONFIG output_config /* i : output audio configuration */ ) { + test(); IF( hParamIsmDec_out != NULL && *hParamIsmDec_out != NULL ) { PARAM_ISM_DEC_HANDLE hParamIsmDec; @@ -1438,7 +1466,8 @@ void ivas_param_ism_dec_close_fx( hParamIsmDec->hParamIsm = NULL; } - IF( !( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) + test(); + IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Param ISM Rendering */ IF( hParamIsmDec->hParamIsmRendering->interpolator_fx != NULL ) @@ -1472,9 +1501,12 @@ void ivas_param_ism_dec_close_fx( *hParamIsmDec_out = NULL; } + test(); IF( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL ) { - IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 1 ); ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 2 ); @@ -1839,9 +1871,11 @@ void ivas_ism_dec_digest_tc_fx( /* we have a full frame interpolator, adapt it */ /* for BE testing */ - IF( EQ_16( extract_l( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available ) ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + IF( EQ_32( extract_l( res_dec ), st_ivas->hTcBuffer->n_samples_available ) ) { - Word16 interpolator_length = extract_l( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + Word16 interpolator_length = extract_l( res_dec ); test(); test(); @@ -1870,6 +1904,7 @@ void ivas_ism_dec_digest_tc_fx( ELSE { ivas_jbm_dec_get_adapted_linear_interpolator_fx( (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ), st_ivas->hTcBuffer->n_samples_available, st_ivas->hIsmRendererData->interpolator_fx ); + move16(); } /* also get the gains here */ @@ -1879,14 +1914,14 @@ void ivas_ism_dec_digest_tc_fx( { Copy32( st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIsmRendererData->prev_gains_fx[i], MAX_OUTPUT_CHANNELS ); - IF( st_ivas->intern_config == IVAS_AUDIO_CONFIG_STEREO ) + IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_STEREO ) ) { Word16 gains_fx[2]; ivas_ism_get_stereo_gains_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &gains_fx[0], &gains_fx[1] ); st_ivas->hIsmRendererData->gains_fx[i][0] = L_shr( L_deposit_h( gains_fx[0] ), 1 ); - move32(); + move16(); st_ivas->hIsmRendererData->gains_fx[i][1] = L_shr( L_deposit_h( gains_fx[1] ), 1 ); - move32(); + move16(); } ELSE { @@ -2040,9 +2075,14 @@ void ivas_param_ism_dec_digest_tc_fx( { Word16 exp_ref_power = 31, exp_cx_diag = 31; Word16 exp_real_tmp = 0, exp_imag_tmp = 0; + move16(); + move16(); + move16(); + move16(); Word32 ref_power_fx[CLDFB_NO_CHANNELS_MAX]; Word32 cx_diag_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX]; Word16 q_tc = q_tc_in; + move16(); Word16 ch, nchan_transport, nchan_out, nchan_out_woLFE, i; Word16 slot_idx, bin_idx; Word32 ivas_total_brate; @@ -2062,20 +2102,28 @@ void ivas_param_ism_dec_digest_tc_fx( fade_len = shr( output_frame, 2 ); nchan_transport = st_ivas->nchan_transport; + move16(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp = 25; + move16(); hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = 25; - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + move16(); + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out = st_ivas->nchan_ism; + move16(); nchan_out_woLFE = nchan_out; + move16(); st_ivas->hDecoderConfig->nchan_out = nchan_out; + move16(); } ELSE { - nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + move16(); } push_wmops( "ivas_param_ism_dec" ); @@ -2091,24 +2139,29 @@ void ivas_param_ism_dec_digest_tc_fx( set_zero_fx( cx_diag_fx[bin_idx], PARAM_ISM_MAX_DMX ); } exp_cx_diag = 0; + move16(); set_zero_fx( ref_power_fx, CLDFB_NO_CHANNELS_MAX ); exp_ref_power = 0; + move16(); /* Frame-level Processing */ /* De-quantization */ + test(); IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) ) { ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); st_ivas->hISMDTX.dtx_flag = 0; + move16(); } ELSE { st_ivas->hISMDTX.dtx_flag = 1; + move16(); } /* obtain the direct response using EFAP */ - IF( !( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) ) + IF( !( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) ) { FOR( i = 0; i < st_ivas->nchan_ism; i++ ) { @@ -2126,10 +2179,12 @@ void ivas_param_ism_dec_digest_tc_fx( IF( EQ_16( i, j ) ) { direct_response_fx[i][j] = ONE_IN_Q30; + move32(); } ELSE { direct_response_fx[i][j] = 0; + move32(); } } } @@ -2139,19 +2194,25 @@ void ivas_param_ism_dec_digest_tc_fx( IF( GT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) { hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 32767; + move16(); hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 0; + move16(); } ELSE { IF( LT_32( hParamIsmDec->azimuth_values_fx[j], 0 ) ) { hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = 0; + move16(); hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = 32767; + move16(); } ELSE /* == 0.0f */ { hParamIsmDec->hParamIsmRendering->proto_matrix_fx[j] = ONE_IN_Q14; + move16(); hParamIsmDec->hParamIsmRendering->proto_matrix_fx[nchan_out_woLFE + j] = ONE_IN_Q14; + move16(); } } } @@ -2168,6 +2229,7 @@ void ivas_param_ism_dec_digest_tc_fx( scale_sig32( transport_channels[i], output_frame, sub( q_tc_in, q_tc ) ); } q_tc = q_tc_in; + move16(); } } @@ -2181,6 +2243,7 @@ void ivas_param_ism_dec_digest_tc_fx( Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX]; Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX]; q_tc = q_tc_in; + move16(); cldfbAnalysis_ts_fx_fixed_q( &( transport_channels[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_tc ); Copy32( RealBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); Copy32( ImagBuffer_fx, &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); @@ -2188,27 +2251,30 @@ void ivas_param_ism_dec_digest_tc_fx( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp = sub( 31, q_tc ); } Word16 scale_factor_real, scale_factor_imag; - + Word16 current_idx; exp_real_tmp = hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_exp; + move16(); exp_imag_tmp = hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_exp; - scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); - scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, scale_factor_real ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); - exp_real_tmp -= scale_factor_real; - exp_imag_tmp -= scale_factor_imag; + move16(); + current_idx = add( imult1616( imult1616( slot_idx, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) ); + scale_factor_real = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands ); + scale_factor_imag = getScaleFactor32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_real ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, scale_factor_imag ); + exp_real_tmp = sub( exp_real_tmp, scale_factor_real ); + exp_imag_tmp = sub( exp_imag_tmp, scale_factor_imag ); ivas_param_ism_collect_slot_fx( hParamIsmDec, - &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], + &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], exp_real_tmp, - &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], + &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], exp_imag_tmp, ch, ref_power_fx, &exp_ref_power, cx_diag_fx, &exp_cx_diag ); - exp_real_tmp += scale_factor_real; - exp_imag_tmp += scale_factor_imag; - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); - scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); + exp_real_tmp = add( exp_real_tmp, scale_factor_real ); + exp_imag_tmp = add( exp_imag_tmp, scale_factor_imag ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_real ); + scale_sig32( &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[current_idx], hSpatParamRendCom->num_freq_bands, -scale_factor_imag ); } } /* Obtain Mixing Matrix on a frame-level */ @@ -2493,9 +2559,13 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( FOR( i = 0; i < nSamples; i++ ) { ch0_e = 0; + move16(); ch1_e = 0; + move16(); ch0 = transport_channels_f[0][i]; + move16(); ch1 = transport_channels_f[1][i]; + move16(); ch0 = BASOP_Util_Add_Mant32Exp( ch0, ch0_e, 0, 0, &ch0_e ); ch1 = BASOP_Util_Add_Mant32Exp( ch1, ch1_e, 0, 0, &ch1_e ); @@ -2591,7 +2661,7 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( move16(); *Q_tc = sub( *Q_tc, tmp_e1 ); - + move16(); return; } #endif @@ -2627,8 +2697,9 @@ static void ivas_ism_param_dec_render_sf_fx( hParamIsmDec = st_ivas->hParamIsmDec; hSpatParamRendCom = st_ivas->hSpatParamRendCom; slot_idx_start = hSpatParamRendCom->slots_rendered; + move16(); subframe_idx = hSpatParamRendCom->subframes_rendered; - + move16(); /* Set some memories to zero */ FOR( ch = 0; ch < nchan_out_woLFE; ch++ ) { @@ -2645,16 +2716,20 @@ static void ivas_ism_param_dec_render_sf_fx( FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { index_slot = slot_idx_start + slot_idx; + move16(); FOR( ch = 0; ch < nchan_transport; ch++ ) { - Cldfb_RealBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; // Q11 - Cldfb_ImagBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; // Q11 + Word16 cldfb_idx = add( imult1616( imult1616( index_slot, hSpatParamRendCom->num_freq_bands ), nchan_transport ), imult1616( ch, hSpatParamRendCom->num_freq_bands ) ); + Cldfb_RealBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx[cldfb_idx]; // Q11 + Cldfb_ImagBuffer_in_fx[ch] = &hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx[cldfb_idx]; // Q11 } /* Compute bandwise rendering to target LS using covariance rendering */ real_exp[slot_idx] = 0; + move16(); imag_exp[slot_idx] = 0; + move16(); ivas_param_ism_render_slot_fx( hParamIsmDec, hSpatParamRendCom, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &real_exp[slot_idx], &imag_exp[slot_idx], hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_fx, @@ -2663,20 +2738,22 @@ static void ivas_ism_param_dec_render_sf_fx( /* CLDFB Synthesis */ idx_in = 0; + move16(); idx_lfe = 0; + move16(); // Word16 tmp_buff_Q[MAX_OUTPUT_CHANNELS]; FOR( ch = 0; ch < nchan_out; ch++ ) { - IF( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) + test(); + IF( ( hSetup.num_lfe > 0 ) && EQ_16( hSetup.index_lfe[idx_lfe], ch ) ) { set32_fx( output_f_fx[ch], 0, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); - IF( idx_lfe < sub( hSetup.num_lfe, 1 ) ) + IF( LT_16( idx_lfe, sub( hSetup.num_lfe, 1 ) ) ) { idx_lfe = add( idx_lfe, 1 ); } - // tmp_buff_Q[ch] = 0; } ELSE { @@ -2685,6 +2762,7 @@ static void ivas_ism_param_dec_render_sf_fx( Word32 *ImagBuffer_fx[16]; Word16 Q_real = 31; + move16(); FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { @@ -2703,30 +2781,38 @@ static void ivas_ism_param_dec_render_sf_fx( } Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q_real, 1 ), Q11 ) ); - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q_real - 1; + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q_real, 1 ); + move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, output_f_fx[ch], hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); Scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( Q11, sub( Q_real, 1 ) ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); /*scaling the output_f buffer to have common Q accross the buffer*/ - samplesProcessed = hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx]; + samplesProcessed = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); no_col_cldfb = st_ivas->cldfbSynDec[ch]->no_col; + move16(); IF( GT_16( samplesProcessed, -1 ) ) { - no_col_cldfb = min( no_col_cldfb, ( samplesProcessed + st_ivas->cldfbSynDec[ch]->no_channels - 1 ) / st_ivas->cldfbSynDec[ch]->no_channels ); + Word32 res_dec, res_frac; + iDiv_and_mod_32( sub( add( samplesProcessed, st_ivas->cldfbSynDec[ch]->no_channels ), 1 ), st_ivas->cldfbSynDec[ch]->no_channels, &res_dec, &res_frac, 0 ); + no_col_cldfb = s_min( no_col_cldfb, extract_l( res_dec ) ); move16(); } - size_cldfb = st_ivas->cldfbSynDec[ch]->no_channels * no_col_cldfb; + size_cldfb = imult1616( st_ivas->cldfbSynDec[ch]->no_channels, no_col_cldfb ); Scale_sig32( output_f_fx[ch], size_cldfb, sub( Q11, sub( Q_real, 1 ) ) ); Q_output[ch] = sub( Q_real, 1 ); + move16(); idx_in = add( idx_in, 1 ); } } hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + move16(); hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); + move16(); return; } @@ -2851,25 +2937,37 @@ void ivas_param_ism_dec_render_fx( hSpatParamRendCom = st_ivas->hSpatParamRendCom; hSetup = st_ivas->hIntSetup; nchan_transport = st_ivas->nchan_transport; + move16(); - IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { nchan_out = st_ivas->nchan_ism; + move16(); nchan_out_woLFE = nchan_out; + move16(); st_ivas->hDecoderConfig->nchan_out = nchan_out; + move16(); } ELSE { nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + move16(); nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + move16(); } slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - + move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size ); - *nSamplesRendered = slots_to_render * slot_size; + Word32 res_dec, res_frac; + iDiv_and_mod_32( nSamplesAsked, slot_size, &res_dec, &res_frac, 0 ); + + slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), extract_l( res_dec ) ); + *nSamplesRendered = imult1616( slots_to_render, extract_l( slot_size ) ); + move16(); first_sf = hSpatParamRendCom->subframes_rendered; + move16(); last_sf = first_sf; + move16(); WHILE( slots_to_render > 0 ) { @@ -2893,7 +2991,7 @@ void ivas_param_ism_dec_render_fx( } } - IF( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) + IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) { /* copy the memories */ /* store mixing matrix for next subframe */ @@ -2902,20 +3000,24 @@ void ivas_param_ism_dec_render_fx( /* store MetaData parameters */ FOR( ch = 0; ch < st_ivas->nchan_ism; ch++ ) { - IF( st_ivas->hParamIsmDec->azimuth_values_fx[ch] > 754974720 /*180.f in Q22*/ ) + IF( GT_32( st_ivas->hParamIsmDec->azimuth_values_fx[ch], 754974720 ) /*180.f in Q22*/ ) { st_ivas->hIsmMetaData[ch]->azimuth_fx = L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[ch], 1509949440 ) /*360.0F in Q22*/; + move32(); } ELSE { st_ivas->hIsmMetaData[ch]->azimuth_fx = st_ivas->hParamIsmDec->azimuth_values_fx[ch]; + move32(); } st_ivas->hIsmMetaData[ch]->elevation_fx = st_ivas->hParamIsmDec->elevation_values_fx[ch]; + move32(); } } - *nSamplesAvailableNext = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size; + *nSamplesAvailableNext = imult1616( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), (Word16) slot_size ); + move16(); return; } @@ -3031,11 +3133,11 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( hParamIsmDec = st_ivas->hParamIsmDec; hSpatParamRendCom = st_ivas->hSpatParamRendCom; nBins = hSpatParamRendCom->num_freq_bands; - move16(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); + test(); IF( !( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) ) { ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); @@ -3058,24 +3160,24 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( hSpatParamRendCom->numSimultaneousDirections = 1; move16(); - azimuth[0] = (Word16) L_shr( ( hParamIsmDec->azimuth_values_fx[0] + ( 1 << 21 ) ), 22 ); - elevation[0] = (Word16) L_shr( ( hParamIsmDec->elevation_values_fx[0] + ( 1 << 21 ) ), 22 ); + azimuth[0] = (Word16) L_shr( L_add( hParamIsmDec->azimuth_values_fx[0], ONE_IN_Q21 ), 22 ); + move16(); + elevation[0] = (Word16) L_shr( L_add( hParamIsmDec->elevation_values_fx[0], ONE_IN_Q21 ), 22 ); + move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + move16(); hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; - - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = energy_ratio_fx; - - hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; - hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); + hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = energy_ratio_fx; move16(); - move32(); + hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; move16(); + hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); } } @@ -3087,19 +3189,21 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( FOR( band_idx = 0; band_idx < hParamIsmDec->hParamIsm->nbands; band_idx++ ) { brange[0] = hParamIsmDec->hParamIsm->band_grouping[band_idx]; - brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; - move16(); + brange[1] = hParamIsmDec->hParamIsm->band_grouping[band_idx + 1]; move16(); + azimuth[0] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); + move16(); elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][0]] + ( 1 << 21 ), 22 ); - + move16(); power_ratio_fx[0] = hParamIsmDec->power_ratios_fx[band_idx][0][0]; move16(); azimuth[1] = (Word16) L_shr( hParamIsmDec->azimuth_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + move16(); elevation[1] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[hParamIsmDec->hParamIsm->obj_indices[band_idx][0][1]] + ( 1 << 21 ), 22 ); + move16(); power_ratio_fx[1] = hParamIsmDec->power_ratios_fx[band_idx][0][1]; - move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) @@ -3107,16 +3211,16 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( FOR( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + move16(); hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; + move16(); hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); + move32(); hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1]; - hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; - hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); - move16(); - move16(); move16(); + hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; move16(); - move32(); + hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); move32(); } } @@ -3127,10 +3231,10 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; - hSpatParamRendCom->spreadCoherence2_fx[sf_idx][bin_idx] = 0; - hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); + hSpatParamRendCom->spreadCoherence2_fx[sf_idx][bin_idx] = 0; move16(); + hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); } } @@ -3141,21 +3245,23 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( hSpatParamRendCom->numSimultaneousDirections = 1; move16(); azimuth[0] = (Word16) L_shr( ( hParamIsmDec->azimuth_values_fx[0] + ( 1 << 21 ) ), 22 ); + move16(); elevation[0] = (Word16) L_shr( hParamIsmDec->elevation_values_fx[0] + ( 1 << 21 ), 22 ); + move16(); FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) { FOR( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; - hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = ONE_IN_Q30; /* 1.0f in Q30 */ - hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; - hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; move16(); + hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = ONE_IN_Q30; /* 1.0f in Q30 */ move32(); + hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; move16(); + hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); } } diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index f766a5b95..11fd356f4 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -34,6 +34,7 @@ #include "options.h" #include "ivas_cnst.h" #include "prot.h" +#include "prot_fx1.h" #include "prot_fx2.h" #include "ivas_prot.h" #include "ivas_prot_fx.h" @@ -127,9 +128,12 @@ ivas_error ivas_ism_renderer_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer\n" ) ); } + test(); + test(); + test(); IF( st_ivas->hIntSetup.is_loudspeaker_setup && st_ivas->hIntSetup.ls_azimuth_fx != NULL && st_ivas->hIntSetup.ls_elevation_fx != NULL && st_ivas->hEFAPdata == NULL ) { - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } @@ -143,14 +147,18 @@ ivas_error ivas_ism_renderer_open_fx( IF( st_ivas->hDecoderConfig->Opt_tsm ) { + Word32 res_dec, res_frac; init_interpolator_length = NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_CLDFB_TIMESLOTS * CLDFB_SLOT_NS ); move16(); - interpolator_length = (UWord16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + interpolator_length = (UWord16) ( res_dec ); move16(); } ELSE { - init_interpolator_length = (UWord16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); + init_interpolator_length = (UWord16) ( res_dec ); move16(); interpolator_length = init_interpolator_length; move16(); @@ -163,11 +171,13 @@ ivas_error ivas_ism_renderer_open_fx( st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; move16(); - FOR( i = 0; i < interpolator_length - 1; i++ ) + FOR( i = 0; i < sub( interpolator_length, 1 ); i++ ) { st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, sub( interpolator_length, 1 ) ); + move16(); } - st_ivas->hIsmRendererData->interpolator_fx[interpolator_length - 1] = 32767; + st_ivas->hIsmRendererData->interpolator_fx[sub( interpolator_length, 1 )] = 32767; + move16(); return IVAS_ERR_OK; } @@ -205,6 +215,7 @@ void ivas_ism_renderer_close( ISM_RENDERER_HANDLE *hIsmRendererData /* i/o: ISM renderer handle */ ) { + test(); IF( hIsmRendererData == NULL || *hIsmRendererData == NULL ) { return; @@ -378,7 +389,7 @@ void ivas_ism_render_sf_fx( num_objects = st_ivas->nchan_transport; move16(); - IF( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { num_objects = st_ivas->nchan_ism; move16(); @@ -397,7 +408,6 @@ void ivas_ism_render_sf_fx( FOR( i = 0; i < num_objects; i++ ) { p_tc_fx[i] = &st_ivas->hTcBuffer->tc_fx[i][tc_offset]; - move16(); } } ELSE @@ -406,7 +416,6 @@ void ivas_ism_render_sf_fx( { mvl2l( &output_fx[i][tc_offset], tc_local_fx[i], n_samples_to_render ); p_tc_fx[i] = tc_local_fx[i]; - move16(); } } @@ -415,7 +424,8 @@ void ivas_ism_render_sf_fx( set32_fx( output_fx[i], 0, n_samples_to_render ); } - IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) + test(); + IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx], 1 ) ) { ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx ); interp_offset = 0; @@ -425,11 +435,12 @@ void ivas_ism_render_sf_fx( FOR( i = 0; i < num_objects; i++ ) { /* Combined rotation: rotate the object positions depending the head and external orientations */ - IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) + test(); + IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx], 1 ) ) { rotateAziEle_fx( (Word16) L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, 22 ), (Word16) L_shr( st_ivas->hIsmMetaData[i]->elevation_fx, 22 ), &azimuth, &elevation, st_ivas->hCombinedOrientationData->Rmat_fx[0], st_ivas->hIntSetup.is_planar_setup ); - move32(); - move32(); + move16(); + move16(); IF( st_ivas->hEFAPdata != NULL ) { @@ -441,18 +452,27 @@ void ivas_ism_render_sf_fx( move16(); FOR( ( j = 0, j2 = 0 ); j < nchan_out_woLFE; ( j++, j2++ ) ) { - IF( ( st_ivas->hIntSetup.num_lfe > 0 ) && ( st_ivas->hIntSetup.index_lfe[lfe_index] == j ) ) + test(); + IF( ( st_ivas->hIntSetup.num_lfe > 0 ) && EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) { - ( lfe_index < ( st_ivas->hIntSetup.num_lfe - 1 ) ) ? ( lfe_index++, j2++ ) : j2++; - move16(); - move16(); + IF( LE_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) ) + { + lfe_index = add( lfe_index, 1 ); + j2 = add( j2, 1 ); + } + ELSE + { + j2 = add( j2, 1 ); + } } gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j]; move32(); prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); - IF( GT_32( L_abs( gain_fx ), 0 ) || GT_32( L_abs( prev_gain_fx ), 0 ) ) + + test(); + IF( ( L_abs( gain_fx ) > 0 ) || ( L_abs( prev_gain_fx ) > 0 ) ) { g1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; tc_fx = p_tc_fx[i]; @@ -460,10 +480,12 @@ void ivas_ism_render_sf_fx( { g2_fx = sub( 32767, *g1_fx ); output_fx[j2][k] = L_add( output_fx[j2][k], L_shl( Mpy_32_32( L_add( Mpy_32_16_1( gain_fx, *( g1_fx++ ) ), Mpy_32_16_1( prev_gain_fx, g2_fx ) ), *( tc_fx++ ) ), 1 ) ); + move16(); } } /* update here only in case of head rotation */ + test(); IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] == 1 ) { st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; @@ -593,7 +615,6 @@ void ivas_ism_get_stereo_gains( } #endif - /*-------------------------------------------------------------------------* * ivas_masa_oism_separate_object_renderer_open() * @@ -675,9 +696,11 @@ ivas_error ivas_omasa_separate_object_renderer_open( { set32_fx( st_ivas->hIsmRendererData->prev_gains_fx[i], 0, MAX_OUTPUT_CHANNELS ); } - - init_interpolator_length = (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); - move32(); + Word32 res_dec1, res_frac1; + Word32 res_dec2, res_frac2; + iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec1, &res_frac1, 0 ); + iDiv_and_mod_32( res_dec1, MAX_PARAM_SPATIAL_SUBFRAMES, &res_dec2, &res_frac2, 0 ); + init_interpolator_length = extract_l( res_dec2 ); interpolator_length = init_interpolator_length; move16(); @@ -685,18 +708,21 @@ ivas_error ivas_omasa_separate_object_renderer_open( #if 1 /*TODO: To be removed later: Stores length of interpolator_fx*/ st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; + move16(); #endif FOR( i = 0; i < interpolator_length; i++ ) { st_ivas->hIsmRendererData->interpolator_fx[i] = div_s( i, interpolator_length ); + move16(); } st_ivas->hIsmRendererData->interpolator_len = interpolator_length; move16(); - st_ivas->hMasaIsmData->delayBuffer_size = (Word16) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); + st_ivas->hMasaIsmData->delayBuffer_size = extract_l( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); - IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { st_ivas->hMasaIsmData->delayBuffer_nchan = 1; move16(); @@ -1000,22 +1026,25 @@ void ivas_omasa_separate_object_render_jbm_fx( lfe_index = hDirACRend->hOutSetup.index_lfe[0]; move16(); - IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { single_separated = 1; + move16(); num_objects = 1; move16(); } ELSE { single_separated = 0; + move16(); num_objects = st_ivas->nchan_ism; move16(); } offsetSamples = i_mult( slots_rendered, hSpatParamRendCom->slot_size ); - FOR( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) + FOR( j = 0; j < add( nchan_out_woLFE, num_lfe ); j++ ) { output_fx_local[j] = output_fx[j]; } @@ -1035,8 +1064,7 @@ void ivas_omasa_separate_object_render_jbm_fx( } } - slots_to_render = nSamplesRendered / hSpatParamRendCom->slot_size; - move16(); + slots_to_render = idiv1616( nSamplesRendered, hSpatParamRendCom->slot_size ); first_sf = subframes_rendered; move16(); last_sf = first_sf; @@ -1059,6 +1087,7 @@ void ivas_omasa_separate_object_render_jbm_fx( delay_signal_fx( input_fx[obj], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[obj], st_ivas->hMasaIsmData->delayBuffer_size ); } offsetSamples = 0; + move16(); FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { @@ -1091,7 +1120,7 @@ void ivas_omasa_separate_object_render_jbm_fx( move16(); } - IF( st_ivas->hOutSetup.is_planar_setup ) + if ( st_ivas->hOutSetup.is_planar_setup ) { /* If no elevation support in output format, then rendering should be done with zero elevation */ elevation = 0; @@ -1109,7 +1138,7 @@ void ivas_omasa_separate_object_render_jbm_fx( FOR( j = 0; j < nchan_out_woLFE; j++ ) { - IF( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) + IF( hDirACRend->hOutSetup.num_lfe > 0 ) { j2 = add( j, (Word16) GE_16( j, lfe_index ) ); } @@ -1119,15 +1148,16 @@ void ivas_omasa_separate_object_render_jbm_fx( move16(); } - IF( GT_32( L_abs( gains_fx[j] ), 0 ) || GT_32( L_abs( hRendererData->prev_gains_fx[obj][j] ), 0 ) ) + test(); + IF( ( L_abs( gains_fx[j] ) > 0 ) || ( L_abs( hRendererData->prev_gains_fx[obj][j] ) > 0 ) ) { FOR( k = 0; k < n_samples_sf; k++ ) { g1_fx = hRendererData->interpolator_fx[k]; move16(); g2_fx = sub( 32767, g1_fx ); - move16(); - output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][k + offsetSamples], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); + + output_fx_local[j2][k + offsetSamples] = L_add( output_fx_local[j2][add( k, offsetSamples )], L_add( L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][k + offsetSamples], g1_fx ), gains_fx[j] ), 2 ), L_shl( Mpy_32_32( Mpy_32_16_1( input_fx[obj][add( k, offsetSamples )], g2_fx ), hRendererData->prev_gains_fx[obj][j] ), 2 ) ) ); } } hRendererData->prev_gains_fx[obj][j] = gains_fx[j]; diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index f3faac41b..56635af0d 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -8,6 +8,7 @@ Word16 param_mc_get_num_cldfb_syntheses_ivas_fx( Word16 num_cldfb_syntheses; num_cldfb_syntheses = 0; + move16(); /* sanity check*/ IF( st_ivas->hParamMC == NULL ) @@ -15,9 +16,11 @@ Word16 param_mc_get_num_cldfb_syntheses_ivas_fx( assert( 0 && "ParamMC handle does not exist!\n" ); } + test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { num_cldfb_syntheses = 2; + move16(); } ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index b8c544a57..d83e28576 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -314,7 +314,9 @@ ivas_error ivas_mct_dec_fx( Word32 *x_fx[CPE_CHANNELS][NB_DIV]; Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; - Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; + Word16 x_len[CPE_CHANNELS][NB_DIV]; + set16_fx( x_len[0], 0, NB_DIV ); + set16_fx( x_len[1], 0, NB_DIV ); Decoder_State **sts; Word16 synth_fx[CPE_CHANNELS][L_FRAME_PLUS]; int32_t ivas_total_brate; @@ -517,7 +519,11 @@ ivas_error ivas_mct_dec_fx( } ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 }; + Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV]; + FOR( i = 0; i < MAX_CICP_CHANNELS; i++ ) + { + set16_fx( x_all_e[i], 0, NB_DIV ); + } Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 61c5be3b1..72c1985d8 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -64,36 +64,57 @@ void mdct_read_IGF_bits_fx( Decoder_State *st0 /* i : pointer to handle where bitstream is read */ ) { - int16_t k, start; + Word16 k, start, temp; start = st0->next_bit_pos; + move16(); - IF( st->core == TCX_20_CORE ) + IF( EQ_16( st->core, TCX_20_CORE ) ) { + IF( st->last_core == ACELP_CORE ) + { + temp = IGF_GRID_LB_TRAN; + move16(); + } + ELSE + { + temp = IGF_GRID_LB_NORM; + move16(); + } /* read IGF payload */ - IGFDecReadLevel( st->hIGFDec, st0, ( st->last_core == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + IGFDecReadLevel( st->hIGFDec, st0, temp, 1 ); - IGFDecReadData_ivas_fx( st->hIGFDec, st0, ( st->last_core == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + IGFDecReadData_ivas_fx( st->hIGFDec, st0, temp, 1 ); } - IF( st->core == TCX_10_CORE ) + IF( EQ_16( st->core, TCX_10_CORE ) ) { FOR( k = 0; k < 2; k++ ) { - IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, k == 0 ? 1 : 0 ); + IF( k == 0 ) + { + temp = 1; + move16(); + } + ELSE + { + temp = 0; + move16(); + } + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); - IGFDecReadData_ivas_fx( st->hIGFDec, st0, IGF_GRID_LB_SHORT, k == 0 ? 1 : 0 ); + IGFDecReadData_ivas_fx( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); } } - st->side_bits_frame_channel += ( st0->next_bit_pos - start ); + st->side_bits_frame_channel = add( st->side_bits_frame_channel, sub( st0->next_bit_pos, start ) ); + move16(); return; } -#endif -#ifndef IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED void mdct_read_IGF_bits( Decoder_State *st, /* i/o: Decoder state handle */ Decoder_State *st0 /* i : pointer to handle where bitstream is read */ @@ -157,10 +178,13 @@ static void dec_prm_tcx_sidebits_fx( hm_cfg.indexBuffer = NULL; start_bit_pos = st0->next_bit_pos; + move16(); /* Init LTP data */ st->hTcxDec->tcx_hm_LtpPitchLag = -1; + move16(); st->hTcxLtpDec->tcxltp_gain = 0; + move16(); /*--------------------------------------------------------------------------------* * Header @@ -170,57 +194,85 @@ static void dec_prm_tcx_sidebits_fx( getTCXMode_ivas_fx( st, st0, MCT_flag ); st->flagGuidedAcelp = 0; + move16(); - IF( st->dec_glr ) + if ( st->dec_glr ) { st->dec_glr_idx = -1; + move16(); } /* last_core for core switching and error concealment */ - IF( ( st->last_core == ACELP_CORE && st->last_total_brate == FRAME_NO_DATA ) || st->prev_bfi ) + test(); + test(); + IF( ( ( st->last_core == ACELP_CORE ) && ( st->last_total_brate == FRAME_NO_DATA ) ) || st->prev_bfi ) { /* needed for cases where first TCX frame after a certain transition (e.g. inactive SID/zero frame -> active or stereo switching) is lost */ st->last_core_from_bs = get_next_indice( st0, 1 ); + move16(); /* ACELP -> TCX_10 transitions are forbidden */ - IF( st->core == TCX_10_CORE && st->last_core == ACELP_CORE ) + test(); + if ( EQ_16( st->core, TCX_10_CORE ) && ( st->last_core == ACELP_CORE ) ) { st->last_core = TCX_20_CORE; + move16(); } } ELSE { st->last_core = get_next_indice( st0, 1 ); + move16(); st->last_core_from_bs = st->last_core; + move16(); } getTCXWindowing_ivas_fx( st->core, st->last_core, st->element_mode, st->hTcxCfg, st0 ); st->hTcxDec->kernel_type[0] = st->hTcxDec->kernel_type[1] = MDCT_IV; - st->hTcxDec->kernel_type[0] = get_next_indice( st0, st->last_core_from_bs != ACELP_CORE ? 2 : 1 ); - IF( st->core == TCX_10_CORE ) + move16(); + move16(); + IF( st->last_core_from_bs != ACELP_CORE ) { - st->hTcxDec->kernel_type[1] = 2 * ( st->hTcxDec->kernel_type[0] & 1 ) + get_next_indice( st0, 1 ); + st->hTcxDec->kernel_type[0] = get_next_indice( st0, 2 ); } - IF( st->core == TCX_20_CORE ) + ELSE + { + st->hTcxDec->kernel_type[0] = get_next_indice( st0, 1 ); + } + move16(); + IF( EQ_16( st->core, TCX_10_CORE ) ) + { + st->hTcxDec->kernel_type[1] = add( shl( s_and( st->hTcxDec->kernel_type[0], 1 ), 1 ), get_next_indice( st0, 1 ) ); + move16(); + } + IF( EQ_16( st->core, TCX_20_CORE ) ) { st->transform_type[0] = st->transform_type[1] = TCX_20; + move16(); + move16(); } ELSE { - IF( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) + IF( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { st->transform_type[0] = TCX_5; + move16(); st->transform_type[1] = TCX_10; + move16(); } - ELSE IF( st->hTcxCfg->tcx_last_overlap_mode == FULL_OVERLAP ) + ELSE IF( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) { st->transform_type[0] = TCX_10; + move16(); st->transform_type[1] = TCX_5; + move16(); } ELSE { st->transform_type[0] = st->transform_type[1] = TCX_5; + move16(); + move16(); } } @@ -228,9 +280,19 @@ static void dec_prm_tcx_sidebits_fx( * TCX20/TCX10 parameters *--------------------------------------------------------------------------------*/ - getTCXparam_fx( st, st0, hm_cfg, param, 0, 0, ( ( ch > 0 ) && ( tnsSize ) && ( tnsSize[0] + tnsSize[1] > 0 ) ? tnsSize : NULL ), p_param, nTnsBitsTCX10, 0 ); + test(); + test(); + IF( ( ch > 0 ) && tnsSize && ( add( tnsSize[0], tnsSize[1] ) > 0 ) ) + { + getTCXparam_fx( st, st0, hm_cfg, param, 0, 0, tnsSize, p_param, nTnsBitsTCX10, 0 ); + } + ELSE + { + getTCXparam_fx( st, st0, hm_cfg, param, 0, 0, NULL, p_param, nTnsBitsTCX10, 0 ); + } - st->side_bits_frame_channel = st0->next_bit_pos - start_bit_pos; + st->side_bits_frame_channel = sub( st0->next_bit_pos, start_bit_pos ); + move16(); return; } @@ -373,10 +435,18 @@ static void dec_prm_tcx_spec_fx( nbits_tcx = 0; move16(); - nSubframes = ( EQ_16( st->core, TCX_10_CORE ) ) ? NB_DIV : 1; + IF( EQ_16( st->core, TCX_10_CORE ) ) + { + nSubframes = NB_DIV; + } + ELSE + { + nSubframes = 1; + } move16(); /*calculate TCX10 target bits before to assure minimum amount is distributed between subframes*/ + test(); IF( EQ_16( st->core, TCX_10_CORE ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { Word16 nTnsBitsTCX10Tmp[NB_DIV]; @@ -386,7 +456,7 @@ static void dec_prm_tcx_spec_fx( move16(); /*compute target bits */ - tmp = i_mult2( nSubframes, add( NBITS_TCX_GAIN, i_mult2( NOISE_FILL_RANGES, NBITS_NOISE_FILL_LEVEL ) ) ); + tmp = i_mult2( nSubframes, NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); nbits_tcx = add( add( add( st->bits_frame_channel, nTnsBitsTCX10[0] ), nTnsBitsTCX10[1] ), tmp ); ivas_mdct_tcx10_bit_distribution_fx( target_bitsTCX10, nbits_tcx, nTnsBitsTCX10Tmp ); } @@ -397,13 +467,14 @@ static void dec_prm_tcx_spec_fx( getTCXparam_fx( st, st, hm_cfg, param, 0, 0, NULL, p_param, target_bitsTCX10, 1 ); - nf_bits = i_mult2( nSubframes, ( add( NBITS_TCX_GAIN, i_mult2( NOISE_FILL_RANGES, NBITS_NOISE_FILL_LEVEL ) ) ) ); + nf_bits = i_mult2( nSubframes, NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); IF( LT_16( add( sub( *total_nbbits, bitsRead[0] ), nf_bits ), sub( st->next_bit_pos, start_bit_pos ) ) ) { st->BER_detect = 1; move16(); st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + move16(); } bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); @@ -503,9 +574,10 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; + move16(); - set_s( total_nbbits, 0, MCT_MAX_CHANNELS ); - set_s( bitsRead, 0, MCT_MAX_CHANNELS ); + set16_fx( total_nbbits, 0, MCT_MAX_CHANNELS ); + set16_fx( bitsRead, 0, MCT_MAX_CHANNELS ); FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -515,6 +587,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( stereo_tcx_init_dec_fx( sts[ch], 1, hCPE->last_element_mode ); } sts[ch]->enablePlcWaveadjust = 0; + move16(); } IF( !bfi ) @@ -522,9 +595,10 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { /* disguard reading second channel of odd transport channels, mct_chan_mode is set by default*/ + test(); IF( odd_channel_cpe && ch == 1 ) { - continue; + CONTINUE; } st = sts[ch]; @@ -539,6 +613,7 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( { st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } + move16(); } } @@ -546,21 +621,33 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; - IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { sts[ch]->coder_type = INACTIVE; + move16(); sts[ch]->side_bits_frame_channel = 0; - continue; + move16(); + CONTINUE; } tmp = ch; - IF( ch == 1 && param_lpc[0][0] == 2 ) + move16(); + test(); + if ( EQ_16( ch, 1 ) && EQ_16( param_lpc[0][0], 2 ) ) { tmp = 3; + move16(); } - dec_prm_tcx_sidebits_fx( param[ch], st, ( ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) ? sts[0]->hTcxDec->tnsActive : NULL ), p_param[ch], nTnsBitsTCX10[ch], st0, MCT_flag, tmp ); - + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag ) + { + dec_prm_tcx_sidebits_fx( param[ch], st, sts[0]->hTcxDec->tnsActive, p_param[ch], nTnsBitsTCX10[ch], st0, MCT_flag, tmp ); + } + ELSE + { + dec_prm_tcx_sidebits_fx( param[ch], st, NULL, p_param[ch], nTnsBitsTCX10[ch], st0, MCT_flag, tmp ); + } assert( st->BER_detect != 1 ); } @@ -569,102 +656,159 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( *--------------------------------------------------------------------------------*/ sns_low_br_mode = 0; + move16(); skipped_first_channel = 0; - IF( !MCT_flag && sts[0]->sr_core == 25600 && ( ( hCPE->element_brate == IVAS_48k || hCPE->element_brate == IVAS_64k ) ) ) + move16(); + + test(); + test(); + test(); + IF( !MCT_flag && EQ_32( sts[0]->sr_core, 25600 ) && ( EQ_32( hCPE->element_brate, IVAS_48k ) || EQ_32( hCPE->element_brate, IVAS_64k ) ) ) { param_lpc[0][0] = SNS_STEREO_MODE_LR; + move16(); param_lpc[0][1] = SNS_STEREO_MODE_LR; + move16(); param_lpc[0][2] = 0; + move16(); param_lpc[0][3] = 0; - IF( sts[0]->core == sts[1]->core ) + move16(); + IF( EQ_16( sts[0]->core, sts[1]->core ) ) { Word16 nSubframes; - nSubframes = ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV; + IF( EQ_16( sts[0]->core, TCX_20_CORE ) ) + { + nSubframes = 1; + } + ELSE + { + nSubframes = NB_DIV; + } + move16(); - for ( Word16 n = 0; n < nSubframes; ++n ) + FOR( Word16 n = 0; n < nSubframes; ++n ) { param_lpc[0][n] = get_next_indice( st0, 1 ); + move16(); } /* zero side flags only get transmitted if needed */ - for ( Word16 n = 0; n < nSubframes; ++n ) + FOR( Word16 n = 0; n < nSubframes; ++n ) { - if ( param_lpc[0][n] == SNS_STEREO_MODE_MS ) + IF( EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ) { - param_lpc[0][n + SNS_STEREO_MODE_OFFSET_INDICES / 2] = get_next_indice( st0, 1 ); + param_lpc[0][n + ( SNS_STEREO_MODE_OFFSET_INDICES / 2 )] = get_next_indice( st0, 1 ); + move16(); } } } - for ( ch = 0; ch < CPE_CHANNELS; ++ch ) + FOR( ch = 0; ch < CPE_CHANNELS; ++ch ) { Word16 nSubframes; Word16 idxIndices; st = sts[ch]; - nSubframes = ( st->core == TCX_20_CORE ) ? 1 : NB_DIV; + IF( EQ_16( st->core, TCX_20_CORE ) ) + { + nSubframes = 1; + } + ELSE + { + nSubframes = NB_DIV; + } + move16(); idxIndices = 0; + move16(); - for ( Word16 n = 0; n < nSubframes; ++n ) + FOR( Word16 n = 0; n < nSubframes; ++n ) { - const Word16 is_side = ch == 1 && param_lpc[0][n] == SNS_STEREO_MODE_MS; - const Word16 *bits = ( nSubframes == 1 ) ? ivas_sns_cdbks_tcx20_bits : ivas_sns_cdbks_tcx10_bits; - Word16 nStages = ( ( nSubframes == 1 ) ? SNS_MSVQ_NSTAGES_TCX20 : SNS_MSVQ_NSTAGES_TCX10 ); - - if ( is_side ) + const Word16 is_side = (Word16) L_and( EQ_16( ch, 1 ), EQ_16( param_lpc[0][n], SNS_STEREO_MODE_MS ) ); + const Word16 *bits; + Word16 nStages; + IF( EQ_16( nSubframes, 1 ) ) + { + bits = ivas_sns_cdbks_tcx20_bits; + nStages = SNS_MSVQ_NSTAGES_TCX20; + } + ELSE + { + bits = ivas_sns_cdbks_tcx10_bits; + nStages = SNS_MSVQ_NSTAGES_TCX10; + } + move16(); + IF( is_side ) { /* check for zero-side flag */ - if ( param_lpc[0][n + SNS_STEREO_MODE_OFFSET_INDICES / 2] ) + IF( param_lpc[0][n + ( SNS_STEREO_MODE_OFFSET_INDICES / 2 )] ) { - continue; + CONTINUE; } nStages = SNS_MSVQ_NSTAGES_SIDE; - bits = ( nSubframes == 1 ) ? ivas_sns_cdbks_side_tcx20_bits : ivas_sns_cdbks_side_tcx10_bits; + move16(); + IF( EQ_16( nSubframes, 1 ) ) + { + bits = ivas_sns_cdbks_side_tcx20_bits; + } + ELSE + { + bits = ivas_sns_cdbks_side_tcx10_bits; + } } - for ( Word16 j = 0; j < nStages; ++j ) + FOR( Word16 j = 0; j < nStages; ++j ) { /* plus one in index for stereo mode storage! */ - param_lpc[ch][j + idxIndices + SNS_STEREO_MODE_OFFSET_INDICES] = get_next_indice_fx( st0, bits[j] ); + param_lpc[ch][add( add( j, idxIndices ), SNS_STEREO_MODE_OFFSET_INDICES )] = get_next_indice_fx( st0, bits[j] ); + move16(); } - idxIndices += nStages; + idxIndices = add( idxIndices, nStages ); } } } - else + ELSE { - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; - if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { skipped_first_channel = 1; - continue; + move16(); + CONTINUE; } start_bit_pos_sns = st0->next_bit_pos; - if ( ch == 0 || skipped_first_channel ) + test(); + IF( ( ch == 0 ) || skipped_first_channel ) { /* read SNS stereo mode */ - param_lpc[0][0] = get_next_indice( st0, 1 ) << 1; + param_lpc[0][0] = shl( (Word16) get_next_indice( st0, 1 ), 1 ); /* read low br mode flag (if it is possible to be non-zero) */ - if ( sts[0]->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) ) + test(); + test(); + IF( EQ_32( sts[0]->element_brate, IVAS_48k ) && !( EQ_16( sts[0]->core, TCX_20 ) && EQ_16( sts[1]->core, TCX_20 ) ) ) { sns_low_br_mode = get_next_indice( st0, 1 ); } } tmp = ch; - if ( ch == 1 && param_lpc[0][0] == 2 ) + move16(); + + test(); + if ( EQ_16( ch, 1 ) && EQ_16( param_lpc[0][0], 2 ) ) { tmp = 3; + move16(); } - getLPCparam_fx( st, ¶m_lpc[ch][0], st0, tmp, sns_low_br_mode && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ); + getLPCparam_fx( st, ¶m_lpc[ch][0], st0, tmp, sns_low_br_mode && !( EQ_16( sts[0]->core, TCX_20 ) && EQ_16( sts[1]->core, TCX_20 ) ) ); - st->side_bits_frame_channel += st0->next_bit_pos - start_bit_pos_sns; + st->side_bits_frame_channel = add( st->side_bits_frame_channel, sub( st0->next_bit_pos, start_bit_pos_sns ) ); + move16(); } } } @@ -917,20 +1061,27 @@ void ivas_mdct_core_invQ_fx( Word16 L_frame[CPE_CHANNELS], nSubframes[CPE_CHANNELS], L_frameTCX[CPE_CHANNELS]; Word16 tmp_concealment_method; Word16 gain_tcx = 0, gain_tcx_e = 0; + move16(); + move16(); Word16 nf_seed; const Word16 *prm_sqQ; Word16 L_frameTCX_global[CPE_CHANNELS]; Word16 tmp_ms_sig[CPE_CHANNELS][N_MAX]; Word16 tmp_ms_sig_e[CPE_CHANNELS]; Word32 concealment_noise_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 concealment_noise_e[CPE_CHANNELS] = { 0 }; + Word16 concealment_noise_e[CPE_CHANNELS]; + set16_fx( concealment_noise_e, 0, CPE_CHANNELS ); TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode_bfi; Word16 q_l = 0, q_r = 0; + move16(); + move16(); Word16 q_snsq = 0; + move16(); Word32 *spectralData_tmp[CPE_CHANNELS]; Word16 shift; Word16 common_exp = 0; + move16(); FOR( k = 0; k < CPE_CHANNELS; ++k ) { @@ -949,8 +1100,8 @@ void ivas_mdct_core_invQ_fx( move32(); set16_fx( xn_buf, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); - set_s( total_nbbits, 0, CPE_CHANNELS ); - set_s( bitsRead, 0, CPE_CHANNELS ); + set16_fx( total_nbbits, 0, CPE_CHANNELS ); + set16_fx( bitsRead, 0, CPE_CHANNELS ); tmp_concealment_method = 0; move16(); @@ -964,7 +1115,7 @@ void ivas_mdct_core_invQ_fx( test(); test(); test(); - IF( bfi && !MCT_flag && ( GT_16( hCPE->hStereoMdct->mdct_stereo_mode[0], SMDCT_DUAL_MONO ) || GT_16( hCPE->hStereoMdct->mdct_stereo_mode[1], SMDCT_DUAL_MONO ) ) ) + IF( bfi && !MCT_flag && ( ( hCPE->hStereoMdct->mdct_stereo_mode[0] > SMDCT_DUAL_MONO ) || ( hCPE->hStereoMdct->mdct_stereo_mode[1] > SMDCT_DUAL_MONO ) ) ) { L_frameTCX[0] = sts[0]->L_frameTCX_past; move16(); @@ -981,8 +1132,8 @@ void ivas_mdct_core_invQ_fx( common_exp = s_max( sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp, sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ); #ifdef MSAN_FIX - Copy_Scale_sig_16_32( sts[0]->hTonalMDCTConc->lastBlockData.spectralData, spectralData_tmp[0], L_frameTCX[0], 15 - ( common_exp - sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ) ); // 30 - spectral_exp1 - Copy_Scale_sig_16_32( sts[1]->hTonalMDCTConc->lastBlockData.spectralData, spectralData_tmp[1], L_frameTCX[1], 15 - ( common_exp - sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ) ); // 30 - spectral_exp2 + Copy_Scale_sig_16_32( sts[0]->hTonalMDCTConc->lastBlockData.spectralData, spectralData_tmp[0], L_frameTCX[0], sub( 15, sub( common_exp, sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ) ) ); // 30 - spectral_exp1 + Copy_Scale_sig_16_32( sts[1]->hTonalMDCTConc->lastBlockData.spectralData, spectralData_tmp[1], L_frameTCX[1], sub( 15, sub( common_exp, sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ) ) ); // 30 - spectral_exp2 #else Copy_Scale_sig_16_32( sts[0]->hTonalMDCTConc->lastBlockData.spectralData, spectralData_tmp[0], L_FRAME_MAX, 15 - ( common_exp - sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp ) ); // 30 - spectral_exp1 Copy_Scale_sig_16_32( sts[1]->hTonalMDCTConc->lastBlockData.spectralData, spectralData_tmp[1], L_FRAME_MAX, 15 - ( common_exp - sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp ) ); // 30 - spectral_exp2 @@ -1007,6 +1158,8 @@ void ivas_mdct_core_invQ_fx( #endif sts[0]->hTonalMDCTConc->lastBlockData.spectralData_exp = sub( 30, q_l ); sts[1]->hTonalMDCTConc->lastBlockData.spectralData_exp = sub( 30, q_r ); + move16(); + move16(); } IF( bfi ) @@ -1050,6 +1203,7 @@ void ivas_mdct_core_invQ_fx( move16(); sts[ch]->total_brate = L_mult0( add( sts[ch]->bits_frame_channel, add( sts[ch]->side_bits_frame_channel, i_mult( sts[ch]->core, NF_GAIN_BITS ) ) ), FRAMES_PER_SEC ); + move32(); } /* Framing parameters */ @@ -1068,14 +1222,16 @@ void ivas_mdct_core_invQ_fx( st->second_last_core = st->last_core; move16(); test(); - IF( EQ_16( hCPE->cpe_id, 0 ) && EQ_16( ch, 0 ) ) + IF( ( hCPE->cpe_id == 0 ) && ( ch == 0 ) ) { /* add mct and side bits to first handle bitrate to avoid false BER detection */ st->total_brate = L_add( st->total_brate, L_mult0( st->next_bit_pos, FRAMES_PER_SEC ) ); + move32(); dec_prm_tcx_spec_fx( st, param[ch], &total_nbbits[ch], &bitsRead[ch], p_param[ch], nTnsBitsTCX10[ch] ); /*revert to actual total bitrate assigned to ch0 */ sts[ch]->total_brate = L_mult0( add( add( sts[ch]->bits_frame_channel, sts[ch]->side_bits_frame_channel ), i_mult2( sts[ch]->core, NF_GAIN_BITS ) ), FRAMES_PER_SEC ); + move32(); } ELSE { @@ -1086,7 +1242,7 @@ void ivas_mdct_core_invQ_fx( } ELSE { - IF( GT_16( st->nbLostCmpt, 1 ) ) + if ( GT_16( st->nbLostCmpt, 1 ) ) { st->flagGuidedAcelp = 0; move16(); @@ -1100,10 +1256,11 @@ void ivas_mdct_core_invQ_fx( test(); test(); - IF( ( !st->bfi || st->hTcxCfg->psychParamsCurrent == NULL ) && GT_16( st->core, ACELP_CORE ) ) + IF( ( !st->bfi || st->hTcxCfg->psychParamsCurrent == NULL ) && ( st->core > ACELP_CORE ) ) { Word16 last_frame_was_concealed_cng; - last_frame_was_concealed_cng = ( EQ_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->last_core, st->last_core_from_bs ) ); + test(); + last_frame_was_concealed_cng = ( st->last_core == ACELP_CORE ) && NE_16( st->last_core, st->last_core_from_bs ); SetCurrentPsychParams( st->core, last_frame_was_concealed_cng, st->hTcxCfg ); } @@ -1135,14 +1292,14 @@ void ivas_mdct_core_invQ_fx( /* avoid using TD-PLC in only one channel when stereo mode isn't dual mono */ test(); test(); - IF( NE_16( sts[0]->core, sts[1]->core ) && ( EQ_16( sts[0]->core, ACELP_CORE ) || EQ_16( sts[1]->core, ACELP_CORE ) ) ) + IF( NE_16( sts[0]->core, sts[1]->core ) && ( ( sts[0]->core == ACELP_CORE ) || ( sts[1]->core == ACELP_CORE ) ) ) { - IF( EQ_16( sts[0]->core, ACELP_CORE ) ) + IF( sts[0]->core == ACELP_CORE ) { sts[0]->core = sts[0]->last_core; move16(); } - ELSE IF( EQ_16( sts[1]->core, ACELP_CORE ) ) + ELSE IF( sts[1]->core == ACELP_CORE ) { sts[1]->core = sts[1]->last_core; move16(); @@ -1161,7 +1318,7 @@ void ivas_mdct_core_invQ_fx( * LPC PARAMETERS *--------------------------------------------------------------------------------*/ - IF( EQ_16( bfi, 0 ) ) + IF( bfi == 0 ) { test(); test(); @@ -1237,9 +1394,16 @@ void ivas_mdct_core_invQ_fx( test(); test(); - IF( !bfi || ( bfi && NE_16( st->core, ACELP_CORE ) ) ) + IF( !bfi || ( bfi && ( st->core != ACELP_CORE ) ) ) { - nSubframes[ch] = ( EQ_16( st->core, TCX_10_CORE ) ) ? NB_DIV : 1; + IF( EQ_16( st->core, TCX_10_CORE ) ) + { + nSubframes[ch] = NB_DIV; + } + ELSE + { + nSubframes[ch] = 1; + } move16(); FOR( k = 0; k < nSubframes[ch]; k++ ) @@ -1256,13 +1420,13 @@ void ivas_mdct_core_invQ_fx( } /* Set pointer to parameters */ - prm[ch] = param[ch] + ( k * DEC_NPRM_DIV ); - L_frameTCX_global[ch] = st->hTcxDec->L_frameTCX / nSubframes[ch]; + prm[ch] = param[ch] + L_mult0( k, DEC_NPRM_DIV ); + L_frameTCX_global[ch] = idiv1616( st->hTcxDec->L_frameTCX, nSubframes[ch] ); move16(); - L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes[ch]; + L_spec[ch] = idiv1616( st->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); move16(); - init_tcx_info_fx( st, st->L_frame / nSubframes[ch], st->hTcxDec->L_frameTCX / nSubframes[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); + init_tcx_info_fx( st, idiv1616( st->L_frame, nSubframes[ch] ), idiv1616( st->hTcxDec->L_frameTCX, nSubframes[ch] ), k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); tmp_concealment_method = 0; move16(); @@ -1271,9 +1435,9 @@ void ivas_mdct_core_invQ_fx( test(); test(); test(); - IF( !bfi && st->hTcxCfg->fIsTNSAllowed && GT_16( ch, 0 ) && LT_16( nf_seed, 0 ) ) + IF( !bfi && st->hTcxCfg->fIsTNSAllowed && ( ch > 0 ) && ( nf_seed < 0 ) ) { - mvs2s( param[0] + k * DEC_NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, prm[ch] + 1 + NOISE_FILL_RANGES + LTPSIZE, nf_seed * -1 ); + Copy( param[0] + k * DEC_NPRM_DIV + 1 + NOISE_FILL_RANGES + LTPSIZE, prm[ch] + 1 + NOISE_FILL_RANGES + LTPSIZE, negate( nf_seed ) ); } nf_seed = 0; move16(); @@ -1830,7 +1994,9 @@ void ivas_mdct_core_reconstruct_fx( Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB_fx; Word16 q_syn = 0; + move16(); Word16 q_win = -2; + move16(); /* TCX */ Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; Word16 tcx_offset[CPE_CHANNELS]; @@ -1847,6 +2013,7 @@ void ivas_mdct_core_reconstruct_fx( /* Initializations */ sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; + move16(); /* TNS, ITF, IMDCT and updates */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -1854,12 +2021,21 @@ void ivas_mdct_core_reconstruct_fx( st = sts[ch]; skip_decoding = 0; - IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + if ( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { skip_decoding = 1; + move16(); } - nSubframes[ch] = ( st->core == TCX_20_CORE ) ? 1 : NB_DIV; + IF( EQ_16( st->core, TCX_20_CORE ) ) + { + nSubframes[ch] = 1; + } + ELSE + { + nSubframes[ch] = NB_DIV; + } + move16(); synth_fx = synth_buf_fx + st->hTcxDec->old_synth_len; synthFB_fx = synth_bufFB_fx + st->hTcxDec->old_synth_lenFB; @@ -1867,11 +2043,11 @@ void ivas_mdct_core_reconstruct_fx( Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( q_syn, st->Q_syn ) ); set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); - IF( NE_16( st->core, ACELP_CORE ) ) + IF( st->core != ACELP_CORE ) { - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, shr( L_FRAME_MAX, 1 ), sub( q_win, -1 - st->Q_syn ) ); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, shr( L_FRAME32k, 1 ), sub( q_win, -1 - st->Q_syn ) ); - Scale_sig( st->hTcxDec->old_syn_Overl, shr( L_FRAME32k, 1 ), sub( q_win, -1 - st->Q_syn ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, sub( -1, st->Q_syn ) ) ); Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->Q_syn ) ); @@ -1883,30 +2059,49 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( synth_buf_fx, 3136, sub( q_win, q_syn ) ); Scale_sig( synth_bufFB_fx, 3136, sub( q_win, q_syn ) ); #endif - Scale_sig( st->syn, M + 1, q_win - st->Q_syn ); + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); FOR( k = 0; k < nSubframes[ch]; k++ ) { - L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes[ch]; - L_frame_global[ch] = st->L_frame / nSubframes[ch]; - L_frame_globalTCX[ch] = st->hTcxDec->L_frameTCX / nSubframes[ch]; + Word16 temp_e; + Word16 temp = BASOP_Util_Divide1616_Scale( st->hTcxCfg->tcx_coded_lines, nSubframes[ch], &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + L_spec[ch] = temp; + move16(); + temp = BASOP_Util_Divide1616_Scale( st->L_frame, nSubframes[ch], &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + L_frame_global[ch] = temp; + move16(); + temp = BASOP_Util_Divide1616_Scale( st->hTcxDec->L_frameTCX, nSubframes[ch], &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + L_frame_globalTCX[ch] = temp; + move16(); init_tcx_info_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); IF( !skip_decoding ) { - decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, - ( ( hCPE->nchan_out == 1 && st->hTcxDec->kernel_type[k] == MDST_IV ) || st->hTcxCfg->tcx_last_overlap_mode == TRANSITION_OVERLAP ) ? MDCT_IV : st->hTcxDec->kernel_type[k], - fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); + test(); + test(); + IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) + { + decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, + MDCT_IV, fUseTns[ch][k], &synth_fx[L_mult0( k, L_frame[ch] )], &synthFB_fx[L_mult0( k, L_frameTCX[ch] )], bfi, k, 0 ); + } + ELSE + { + decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, + st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[L_mult0( k, L_frame[ch] )], &synthFB_fx[L_mult0( k, L_frameTCX[ch] )], bfi, k, 0 ); + } } ELSE { - set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); - set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); + set16_fx( &synth_fx[L_mult0( k, L_frame[ch] )], 0, L_frame[ch] ); + set16_fx( &synthFB_fx[L_mult0( k, L_frame[ch] )], 0, L_frameTCX[ch] ); } } - IF( EQ_16( bfi, 0 ) && st->hTonalMDCTConc != NULL ) + IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) { Word16 synth_tmp[L_FRAME48k]; Copy_Scale_sig( synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2 ); @@ -1914,9 +2109,9 @@ void ivas_mdct_core_reconstruct_fx( } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, NULL, bfi, MCT_flag ); - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, shr( L_FRAME_MAX, 1 ), sub( -1 - st->Q_syn, q_win ) ); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, shr( L_FRAME32k, 1 ), sub( -1 - st->Q_syn, q_win ) ); - Scale_sig( st->hTcxDec->old_syn_Overl, shr( L_FRAME32k, 1 ), sub( -1 - st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), q_win ) ); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), q_win ) ); #ifdef MSAN_FIX Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); @@ -1924,9 +2119,9 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( synth_buf_fx, 3136, sub( q_syn, q_win ) ); Scale_sig( synth_bufFB_fx, 3136, sub( q_syn, q_win ) ); #endif - Scale_sig( st->syn, M + 1, st->Q_syn + 2 ); - Scale_sig( st->hTcxDec->syn_OverlFB, shr( L_FRAME_MAX, 1 ), sub( st->Q_syn, q_win ) ); - Scale_sig( st->hTcxDec->syn_Overl, shr( L_FRAME32k, 1 ), sub( st->Q_syn, q_win ) ); + Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); } @@ -1934,28 +2129,36 @@ void ivas_mdct_core_reconstruct_fx( { assert( EQ_16( st->bfi, 1 ) ); /* PLC: [TCX: TD PLC] */ - IF( NE_16( MCT_flag, 0 ) ) + IF( MCT_flag != 0 ) { con_tcx_fx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); } ELSE { - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] - 1 ) ); - con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, ( sts[1]->core != ACELP_CORE ) ? 1 : 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ) ); + IF( sts[1]->core != ACELP_CORE ) + { + con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 1, &st->hFdCngDec->hFdCngCom->A_cng[0] ); + } + ELSE + { + con_tcx_ivas_fx( st, &synthFB_fx[0], hCPE->hStereoMdct->lastCoh_fx, &sts[0]->seed_acelp, 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); + } } Scale_sig( synthFB_fx, st->hTcxDec->L_frameTCX, q_syn ); - IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || NE_16( st->hTcxDec->tcxConceal_recalc_exc, 0 ) ) + IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) { - Scale_sig( synthFB_fx - ( st->hTcxDec->L_frameTCX / 2 + st->hTcxDec->pit_max_TCX + 2 * M ), sub( q_syn, st->Q_exc - 1 ), st->hTcxDec->L_frameTCX / 2 + st->hTcxDec->pit_max_TCX + 2 * M ); + Scale_sig( synthFB_fx - add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ), sub( q_syn, sub( st->Q_exc, 1 ) ), add( add( shr( st->hTcxDec->L_frameTCX, 1 ), st->hTcxDec->pit_max_TCX ), 2 * M ) ); } ELSE { - Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, sub( q_syn, st->Q_exc - 1 ), st->hTcxDec->L_frameTCX ); + Scale_sig( synthFB_fx - st->hTcxDec->L_frameTCX, sub( q_syn, sub( st->Q_exc, 1 ) ), st->hTcxDec->L_frameTCX ); } lerp( synthFB_fx, synth_fx, st->L_frame, st->hTcxDec->L_frameTCX ); st->con_tcx = 1; + move16(); set16_fx( &st->mem_pitch_gain[2], st->lp_gainp_fx, st->nb_subfr ); /* PLC: [TCX: Tonal Concealment] */ @@ -1974,10 +2177,12 @@ void ivas_mdct_core_reconstruct_fx( st = sts[ch]; - IF( NE_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) ) + test(); + test(); + IF( ( bfi != 0 ) && ( st->last_core != ACELP_CORE ) && ( st->core == ACELP_CORE ) ) { /* Update FEC_scale_syn parameters */ - IF( EQ_16( st->hTcxLtpDec->tcxltp_gain, 0 ) ) + IF( st->hTcxLtpDec->tcxltp_gain == 0 ) { frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); } @@ -1990,23 +2195,24 @@ void ivas_mdct_core_reconstruct_fx( /* Update */ Copy( synth_buf_fx + st->L_frame, st->hTcxDec->old_synth, st->hTcxDec->old_synth_len ); Copy( st->hTcxDec->old_synthFB_fx + st->hTcxDec->L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), st->hTcxDec->synth_history_fx, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); - mvs2s( synth_bufFB_fx + st->hTcxDec->L_frameTCX, st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB ); + Copy( synth_bufFB_fx + st->hTcxDec->L_frameTCX, st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB ); Scale_sig( st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->Q_syn, q_syn ) ); IF( st->hHQ_core != NULL ) { - mvs2s( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + st->hTcxDec->old_synth_lenFB, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } - mvs2s( st->lsp_q_cng, st->old_lsp_q_cng, M ); - mvs2s( st->lsf_q_cng, st->old_lsf_q_cng, M ); + Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); + Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); st->last_is_cng = 0; + move16(); /* Postfiltering */ Word16 x_fx_16[1200]; Copy_Scale_sig_32_16( x_fx[ch][0], x_fx_16, st->L_frame, sub( 0, q_x ) ); IF( st->p_bpf_noise_buf_32 ) { - Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, negate( Q11 ) ); + Copy_Scale_sig_32_16( st->p_bpf_noise_buf_32, st->p_bpf_noise_buf, st->L_frame, -Q11 ); } post_decoder_ivas_fx( st, synth_buf_fx, pit_gain_fx[ch], pitch[ch], x_fx_16, st->p_bpf_noise_buf ); @@ -2023,13 +2229,17 @@ void ivas_mdct_core_reconstruct_fx( /* updates */ st->last_voice_factor_fx = 0; + move16(); st->last_coder_type = st->coder_type; + move16(); - Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, sub( q_x, 0 ) ); + Copy_Scale_sig_16_32( x_fx_16, x_fx[ch][0], st->L_frame, q_x - 0 ); } /* calculate coherence of signal needed when next frame is lost */ - IF( EQ_16( bfi, 0 ) && EQ_16( MCT_flag, 0 ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) + test(); + test(); + IF( ( bfi == 0 ) && ( MCT_flag == 0 ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { Word16 i; Word64 nrgL_fx, nrgR_fx, xcorr_fx; @@ -2068,7 +2278,9 @@ void ivas_mdct_core_reconstruct_fx( e_tmp = add( e_nrgL, e_nrgR ); L_tmp = ISqrt32( L_tmp, &e_tmp ); hCPE->hStereoMdct->lastCoh_fx = extract_l( L_shr( Mpy_32_32( L_abs( W_extract_h( xcorr_fx ) ), L_tmp ), sub( 17, add( e_xcorr, e_tmp ) ) ) ); + move16(); hCPE->hStereoMdct->lastCoh_fx = s_min( hCPE->hStereoMdct->lastCoh_fx, 16384 ); + move16(); } return; @@ -2339,19 +2551,34 @@ void ivas_mdct_core_tns_ns_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; - nSubframes[ch] = EQ_16( st->core, TCX_20_CORE ) ? 1 : NB_DIV; + IF( EQ_16( st->core, TCX_20_CORE ) ) + { + nSubframes[ch] = 1; + } + ELSE + { + nSubframes[ch] = NB_DIV; + } move16(); L_frame_global[ch] = BASOP_Util_Divide3216_Scale( st->L_frame, nSubframes[ch], &exp ); - L_frame_global[ch] = shl( L_frame_global[ch], exp + 1 ); + move16(); + L_frame_global[ch] = shl( L_frame_global[ch], add( exp, 1 ) ); + move16(); L_frameTCX_glob[ch] = BASOP_Util_Divide3216_Scale( st->hTcxDec->L_frameTCX, nSubframes[ch], &exp ); - L_frameTCX_glob[ch] = shl( L_frameTCX_glob[ch], exp + 1 ); + move16(); + L_frameTCX_glob[ch] = shl( L_frameTCX_glob[ch], add( exp, 1 ) ); + move16(); L_spec[ch] = BASOP_Util_Divide3216_Scale( st->hTcxCfg->tcx_coded_lines, nSubframes[ch], &exp ); - L_spec[ch] = shl( L_spec[ch], exp + 1 ); + move16(); + L_spec[ch] = shl( L_spec[ch], add( exp, 1 ) ); + move16(); - IF( ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) || ( NE_16( st->bfi, 0 ) && EQ_16( st->core, ACELP_CORE ) ) ) /* indicates LFE with no content, or odd number of channels */ + test(); + test(); + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) || ( ( st->bfi != 0 ) && ( st->core == ACELP_CORE ) ) ) /* indicates LFE with no content, or odd number of channels */ { IF( st->hTonalMDCTConc != NULL ) { @@ -2369,11 +2596,11 @@ void ivas_mdct_core_tns_ns_fx( Word16 q_x; q_x = sub( 31, x_e[ch][k] ); - IF( EQ_16( bfi, 0 ) ) + IF( bfi == 0 ) { sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); - IF( NE_16( MCT_flag, 0 ) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) + IF( ( MCT_flag != 0 ) && st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { Word16 scf_fx[FDNS_NPTS], scf_e[FDNS_NPTS]; Word16 q_shift; @@ -2381,7 +2608,9 @@ void ivas_mdct_core_tns_ns_fx( { q_shift = norm_l( sns_int_scf_fx[ind] ); scf_fx[ind] = extract_h( L_shl( sns_int_scf_fx[ind], q_shift ) ); + move16(); scf_e[ind] = sub( 15, q_shift ); + move16(); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e[ch][k], L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); } @@ -2390,7 +2619,7 @@ void ivas_mdct_core_tns_ns_fx( { IF( st->hTonalMDCTConc != NULL ) { - IF( EQ_16( MCT_flag, 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) + IF( ( MCT_flag == 0 ) && LT_16( st->hTcxDec->cummulative_damping_tcx, 32440 ) ) { Word16 *scf_last_m, *scf_last_e; Word32 *scf_bg; @@ -2401,21 +2630,26 @@ void ivas_mdct_core_tns_ns_fx( scf_bg = &st->hTonalMDCTConc->scaleFactorsBackground_fx[0]; st->hTonalMDCTConc->scf_fadeout = mult( st->hTonalMDCTConc->scf_fadeout, 31130 ); // 0.95 in Q15 = 31130 + move16(); fade_out = st->hTonalMDCTConc->scf_fadeout; + move16(); fade_in = sub( 32767, fade_out ); FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_add( Mpy_32_16_1( L_shl( scf_last_m[i], 1 + scf_last_e[i] ), fade_out ), Mpy_32_16_1( L_shl( scf_bg[i], 1 ), fade_in ) ); + sns_int_scf_fx[i] = L_add( Mpy_32_16_1( L_shl( scf_last_m[i], add( 1, scf_last_e[i] ) ), fade_out ), Mpy_32_16_1( L_shl( scf_bg[i], 1 ), fade_in ) ); + move32(); } } ELSE { st->hTonalMDCTConc->scf_fadeout = 32767; + move16(); FOR( Word16 i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++ ) { - sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], 1 + st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ); + sns_int_scf_fx[i] = L_shl( st->hTonalMDCTConc->lastBlockData.scaleFactors[i], add( 1, st->hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] ) ); + move32(); } } } @@ -2428,6 +2662,7 @@ void ivas_mdct_core_tns_ns_fx( Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); q_x = add( q_x, norm_x ); x_e[ch][k] = sub( 31, q_x ); + move16(); Word16 q_sns_int_scf; Word16 q_2, length; @@ -2435,28 +2670,34 @@ void ivas_mdct_core_tns_ns_fx( // q_sns_int_scf -= 1; FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { - sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], q_sns_int_scf - 16 ); + sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], sub( q_sns_int_scf, 16 ) ); + move32(); } q_2 = q_x; + move16(); sns_shape_spectrum_fx( x_fx[ch][k], &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins, &length ); IF( LT_16( q_2, add( q_x, 1 ) ) ) /*scaling to q_2*/ { Scale_sig32( &x_fx[ch][k][0], length, q_2 - q_x - 1 ); q_x = q_2; + move16(); } ELSE /*scaling to q_x+1*/ { - Scale_sig32( &x_fx[ch][k][0] + length, L_spec[ch] - length, q_x + 1 - q_2 ); + Scale_sig32( &x_fx[ch][k][0] + length, sub( L_spec[ch], length ), sub( add( q_x, 1 ), q_2 ) ); q_x = add( q_x, 1 ); } x_e[ch][k] = sub( 31, q_x ); + move16(); - v_multc_fixed( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins ); + v_multc_fixed( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sub( L_spec[ch], st->hTcxCfg->psychParamsCurrent->nBins ) ); q_2 = sub( add( q_x, q_sns_int_scf ), 31 ); - Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x ); + Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, sub( q_2, q_x ) ); q_x = q_2; + move16(); x_e[ch][k] = sub( 31, q_x ); + move16(); q_x = sub( q_x, 5 ); Scale_sig32( &x_fx[ch][k][0], L_spec[ch], -5 ); @@ -2465,9 +2706,10 @@ void ivas_mdct_core_tns_ns_fx( Scale_sig32( &x_fx[ch][k][0], L_spec[ch], norm_x ); q_x = add( q_x, norm_x ); x_e[ch][k] = sub( 31, q_x ); + move16(); } - IF( NE_16( bfi, 0 ) && NE_16( st->tonal_mdct_plc_active, 0 ) ) + IF( ( bfi != 0 ) && ( st->tonal_mdct_plc_active != 0 ) ) { Word16 q_x, q_x_old; FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) @@ -2481,34 +2723,48 @@ void ivas_mdct_core_tns_ns_fx( IF( LT_16( q_x_old, q_x ) ) { x_e[ch][0] = sub( 31, q_x_old ); + move16(); FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { FOR( Word16 l = st->hTonalMDCTConc->pTCI->lowerIndex[i]; l <= st->hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { - x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], q_x - q_x_old ); + x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub( q_x, q_x_old ) ); + move32(); } } } ELSE { x_e[ch][0] = sub( 31, q_x ); + move16(); FOR( Word16 i = 0; i < st->hTonalMDCTConc->pTCI->numIndexes; i++ ) { FOR( Word16 l = 0; l < st->hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub( q_x_old, q_x ) ); + move32(); } FOR( Word16 l = st->hTonalMDCTConc->pTCI->upperIndex[i] + 1; l < L_spec[ch]; l++ ) { x_fx[ch][0][l] = L_shr( x_fx[ch][0][l], sub( q_x_old, q_x ) ); + move32(); } } } } + test(); + test(); IF( ( bfi || MCT_flag ) && st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active ); + IF( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) + { + TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], st->old_fpitch, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); + } + ELSE + { + TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], 0, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); + } } } diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 75d42d5ec..892298f1c 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -73,9 +73,13 @@ ivas_error ivas_mono_dmx_renderer_open( } hDownmix->inputEnergy_fx = 0; + move16(); hDownmix->protoEnergy_fx = 0; + move16(); hDownmix->Q_inputEner = 0; + move16(); hDownmix->Q_protoEner = 0; + move16(); st_ivas->hMonoDmxRenderer = hDownmix; @@ -112,6 +116,7 @@ void ivas_mono_dmx_renderer_close( MONO_DOWNMIX_RENDERER_HANDLE *hMonoDmxRenderer /* i/ i/o: Mono downmix structure */ ) { + test(); IF( hMonoDmxRenderer == NULL || *hMonoDmxRenderer == NULL ) { return; @@ -219,14 +224,17 @@ void ivas_mono_downmix_render_passive_fx( Word16 diff_shift, div, div_sqrt; Word32 protoEner_pre, inputEner_pre; numInputChannels = st_ivas->nSCE; - IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) SBA_ISM_FORMAT ) ) + move16(); + if ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { numInputChannels = st_ivas->nchan_ism; + move16(); } - IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - IF( EQ_16( (Word16) st_ivas->ism_mode, (Word16) ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, (Word16) ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { numInputChannels = add( st_ivas->nchan_transport, 1 ); } @@ -240,10 +248,11 @@ void ivas_mono_downmix_render_passive_fx( set32_fx( proto_signal_fx, 0, output_frame ); Word16 Output_norm = 32; - FOR( int lp = 0; lp < numInputChannels; lp++ ) + move16(); + FOR( Word16 lp = 0; lp < numInputChannels; lp++ ) { Word16 norm = L_norm_arr( output_f_fx[lp], output_frame ); - Output_norm = min( Output_norm, norm ); + Output_norm = s_min( Output_norm, norm ); } Q_shift = sub( Output_norm, find_guarded_bits_fx( numInputChannels ) ); @@ -256,7 +265,9 @@ void ivas_mono_downmix_render_passive_fx( /* compute the input energy, proto energy after smoothing */ hDownmix->inputEnergy_fx = Mpy_32_16_1( hDownmix->inputEnergy_fx, DOWNMIX_ALPHA_FX ); + move32(); hDownmix->protoEnergy_fx = Mpy_32_16_1( hDownmix->protoEnergy_fx, DOWNMIX_ALPHA_FX ); + move32(); proto_norm = L_norm_arr( proto_signal_fx, output_frame ); @@ -279,7 +290,7 @@ void ivas_mono_downmix_render_passive_fx( /* compute the eq factor */ - IF( EQ_32( hDownmix->protoEnergy_fx, 0 ) ) + IF( hDownmix->protoEnergy_fx == 0 ) { norm_protoEner = add( 31, hDownmix->Q_protoEner ); } @@ -287,7 +298,7 @@ void ivas_mono_downmix_render_passive_fx( { norm_protoEner = add( norm_l( hDownmix->protoEnergy_fx ), hDownmix->Q_protoEner ); } - IF( EQ_32( hDownmix->inputEnergy_fx, 0 ) ) + IF( hDownmix->inputEnergy_fx == 0 ) { norm_inputEner = add( 31, hDownmix->Q_inputEner ); } @@ -296,31 +307,41 @@ void ivas_mono_downmix_render_passive_fx( norm_inputEner = add( norm_l( hDownmix->inputEnergy_fx ), hDownmix->Q_inputEner ); } - norm_protoEner = min( norm_protoEner, sub( shl( add( add( 11, Q_shift ), proto_shift ), 1 ), 31 ) ) - 1; - norm_inputEner = min( norm_inputEner, sub( shl( add( 11, input_shift ), 1 ), 31 ) ) - 1; + norm_protoEner = sub( s_min( norm_protoEner, sub( shl( add( add( 11, Q_shift ), proto_shift ), 1 ), 31 ) ), 1 ); + norm_inputEner = sub( s_min( norm_inputEner, sub( shl( add( 11, input_shift ), 1 ), 31 ) ), 1 ); hDownmix->protoEnergy_fx = L_shl( hDownmix->protoEnergy_fx, sub( norm_protoEner, hDownmix->Q_protoEner ) ); + move32(); hDownmix->inputEnergy_fx = L_shl( hDownmix->inputEnergy_fx, sub( norm_inputEner, hDownmix->Q_inputEner ) ); + move32(); hDownmix->Q_protoEner = norm_protoEner; + move16(); hDownmix->Q_inputEner = norm_inputEner; + move16(); protoEner_pre = L_shl( protoEner_pre, sub( norm_protoEner, sub( shl( add( add( 11, Q_shift ), proto_shift ), 1 ), 31 ) ) ); inputEner_pre = L_shl( inputEner_pre, sub( norm_inputEner, sub( shl( add( 11, input_shift ), 1 ), 31 ) ) ); hDownmix->protoEnergy_fx = L_add( hDownmix->protoEnergy_fx, protoEner_pre ); + move32(); hDownmix->inputEnergy_fx = L_add( hDownmix->inputEnergy_fx, inputEner_pre ); + move32(); diff_shift = sub( hDownmix->Q_inputEner, hDownmix->Q_protoEner ); - IF( GT_16( diff_shift, 0 ) ) + IF( diff_shift > 0 ) { hDownmix->inputEnergy_fx = L_shr( hDownmix->inputEnergy_fx, diff_shift ); + move32(); hDownmix->Q_inputEner = sub( hDownmix->Q_inputEner, diff_shift ); + move16(); } ELSE { hDownmix->protoEnergy_fx = L_shr( hDownmix->protoEnergy_fx, -diff_shift ); + move32(); hDownmix->Q_protoEner = add( hDownmix->Q_protoEner, diff_shift ); + move16(); } IF( GE_32( hDownmix->protoEnergy_fx, L_shr( hDownmix->inputEnergy_fx, 2 ) ) ) { @@ -349,6 +370,7 @@ void ivas_mono_downmix_render_passive_fx( * Downmix process in McMASA *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_mono_stereo_downmix_mcmasa( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output_f[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ @@ -388,7 +410,7 @@ void ivas_mono_stereo_downmix_mcmasa( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_mono_stereo_downmix_mcmasa_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ @@ -402,21 +424,22 @@ void ivas_mono_stereo_downmix_mcmasa_fx( set32_fx( dmx_tmp_fx, 0, output_frame ); /* Dowmix center channel to L and R */ - if ( st_ivas->hDecoderConfig->nchan_out == 2 && st_ivas->hOutSetup.separateChannelEnabled ) + test(); + IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 2 ) && st_ivas->hOutSetup.separateChannelEnabled ) { v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); } /* Mono downmix */ - else if ( st_ivas->hDecoderConfig->nchan_out == 1 ) + ELSE IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) { /* Downmix L and R to dmx_tmp */ - for ( i = 0; i < st_ivas->nchan_transport; i++ ) + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); } /* Add center channel */ - if ( st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.separateChannelEnabled ) { v_add_32( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], dmx_tmp_fx, dmx_tmp_fx, output_frame ); } @@ -437,6 +460,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( * Apply non-diegetic panning *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_apply_non_diegetic_panning( float *output_f[], /* i/o: core-coder transport mono channel/stereo output */ const float non_diegetic_pan_gain, /* i : non-diegetic panning gain */ @@ -454,7 +478,7 @@ void ivas_apply_non_diegetic_panning( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_apply_non_diegetic_panning_fx( Word32 *output_f_fx[], /* i/o: core-coder transport mono channel/stereo output */ const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ @@ -463,8 +487,8 @@ void ivas_apply_non_diegetic_panning_fx( { Word16 pan_left_fx, pan_right_fx; - pan_left_fx = mult( non_diegetic_pan_gain_fx, 16348 ) + 16348; - pan_right_fx = 32767 - pan_left_fx; + pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16348 ), 16348 ); + pan_right_fx = sub( 32767, pan_left_fx ); v_multc_fixed( output_f_fx[0], L_shl( L_deposit_l( pan_right_fx ), 16 ), output_f_fx[1], output_frame ); v_multc_fixed( output_f_fx[0], L_shl( L_deposit_l( pan_left_fx ), 16 ), output_f_fx[0], output_frame ); diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index aeb119af8..51cf795b3 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -43,8 +43,6 @@ #include "prot_fx1.h" #include "prot_fx2.h" #include "debug.h" -#define float_to_fixed( n, factor ) ( round( n * ( 1 << factor ) ) ) -#define fixed_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) #endif @@ -61,7 +59,8 @@ ivas_error ivas_td_binaural_open_fx( { *num_src = st_ivas->nchan_transport; move16(); - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + test(); + if ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { *num_src = st_ivas->nchan_ism; move16(); @@ -104,7 +103,15 @@ ivas_error ivas_td_binaural_renderer_fx( Word16 ism_md_subframe_update; Word16 nchan_transport; test(); - nchan_transport = ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) ? st_ivas->nchan_ism : st_ivas->nchan_transport; + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + nchan_transport = st_ivas->nchan_ism; + } + ELSE + { + nchan_transport = st_ivas->nchan_transport; + } + move16(); IF( st_ivas->hDecoderConfig->Opt_delay_comp ) { @@ -114,12 +121,13 @@ ivas_error ivas_td_binaural_renderer_fx( { ism_md_subframe_update = 2; } + move16(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + if ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { ism_md_subframe_update = 2; + move16(); } - return ivas_td_binaural_renderer_unwrap_fx( st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, st_ivas->hIsmMetaData, st_ivas->hCombinedOrientationData, ism_md_subframe_update, output, output_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); } #else @@ -186,7 +194,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( Word16 enableCombinedOrientation; /* Set the number of ISMs */ - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nchan_ism_internal = st_ivas->nchan_ism; move16(); @@ -195,7 +203,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( ch_offset = 2; move16(); } - ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { nchan_ism_internal = st_ivas->nchan_ism; move16(); @@ -224,7 +232,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( ism_md_subframe_update_jbm = sub( st_ivas->hTcBuffer->nb_subframes, 2 ); } - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { ism_md_subframe_update_jbm = s_max( 0, sub( st_ivas->hTcBuffer->nb_subframes, 2 ) ); } @@ -248,6 +256,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ tmp = 0; + move16(); IF( n_samples_granularity != 0 ) { tmp = idiv1616( n_samples_granularity, slot_size ); @@ -258,6 +267,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( last_sf = first_sf; move16(); st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); + move16(); WHILE( slots_to_render > 0 ) { @@ -275,7 +285,8 @@ ivas_error ivas_td_binaural_renderer_sf_fx( FOR( nS = 0; nS < nchan_ism; nS++ ) { - IF( !( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( nS, LFE_CHANNEL ) ) ) /* Skip LFE for MC */ + test(); + IF( !( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( nS, LFE_CHANNEL ) ) ) /* Skip LFE for MC */ { st_ivas->hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = tc_local_fx[nS]; /* Q11 */ st_ivas->hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; @@ -298,6 +309,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( tmp_Quaternion_fx = &st_ivas->hCombinedOrientationData->Quaternions[st_ivas->hCombinedOrientationData->subframe_idx]; tmp_vector_fx = &st_ivas->hCombinedOrientationData->listenerPos[st_ivas->hCombinedOrientationData->subframe_idx]; enableCombinedOrientation = st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx]; + move16(); /* Shifting x_fx, y_fx, z_fx to the same Q-factor as Listener_p->Pos_q (usually Q25) */ Word16 pos_q = st_ivas->hBinRendererTd->Listener_p->Pos_q; @@ -306,6 +318,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( tmp_vector_fx->y_fx = L_shr( tmp_vector_fx->y_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); tmp_vector_fx->z_fx = L_shr( tmp_vector_fx->z_fx, sub( tmp_vector_fx->q_fact, pos_q ) ); tmp_vector_fx->q_fact = pos_q; + move16(); } ELSE { @@ -315,17 +328,19 @@ ivas_error ivas_td_binaural_renderer_sf_fx( move16(); } - IF( ( error = TDREND_Update_listener_orientation_fx( st_ivas->hBinRendererTd, - enableCombinedOrientation, - tmp_Quaternion_fx, - tmp_vector_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_Update_listener_orientation_fx( st_ivas->hBinRendererTd, + enableCombinedOrientation, + tmp_Quaternion_fx, + tmp_vector_fx ) ), + IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->hRenderConfig != NULL && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + test(); + IF( st_ivas->hRenderConfig != NULL && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -334,12 +349,13 @@ ivas_error ivas_td_binaural_renderer_sf_fx( /* Render subframe */ /* ism_md_subframe_update_jbm != subframe_idx: trigger update only for ism_md_subframe_update_jbm == subframe_idx, where then the two TDREND_GetMix()-arguments subframe_idx and ism_md_subframe_update are equal, and we want to enforce the update inside TDREND_GetMix to use subframe_idx == 0 */ - IF( ( error = TDREND_GetMix_fx( st_ivas->hBinRendererTd, output_fx_local, output_frame, 0, ism_md_subframe_update_jbm != subframe_idx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_GetMix_fx( st_ivas->hBinRendererTd, output_fx_local, output_frame, 0, ism_md_subframe_update_jbm != subframe_idx ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->hRenderConfig != NULL && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + test(); + IF( st_ivas->hRenderConfig != NULL && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* add reverb to rendered signals */ v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 01a1e4554..f376e8d7e 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -147,11 +147,13 @@ ivas_error ivas_omasa_data_open_fx( } hMasaIsmData->objectsMoved = 0; + move16(); hMasaIsmData->delayBuffer_fx = NULL; FOR( ch = 0; ch < MAX_NUM_OBJECTS; ch++ ) { hMasaIsmData->ism_is_edited[ch] = 0; + move16(); hMasaIsmData->q_elevation_old_fx[ch] = 0; move32(); hMasaIsmData->q_azimuth_old_fx[ch] = 0; @@ -302,6 +304,7 @@ ivas_error ivas_omasa_dec_config_fx( *-----------------------------------------------------------------*/ old_renderer_type = st_ivas->renderer_type; + move32(); /* MASA reconfig. */ cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); @@ -309,14 +312,14 @@ ivas_error ivas_omasa_dec_config_fx( test(); test(); test(); - IF( st_ivas->ini_active_frame == 0 && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) + IF( ( st_ivas->ini_active_frame == 0 ) && ( ivas_total_brate != FRAME_NO_DATA ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) { st_ivas->hCPE[0]->nchan_out = 1; move16(); } ELSE { - IF( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -335,9 +338,9 @@ ivas_error ivas_omasa_dec_config_fx( /* OMASA reconfig. */ test(); - IF( st_ivas->hMasaIsmData == NULL && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( st_ivas->hMasaIsmData == NULL && EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - IF( ( error = ivas_omasa_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -346,7 +349,7 @@ ivas_error ivas_omasa_dec_config_fx( ivas_set_omasa_TC_fx( st_ivas->ism_mode, st_ivas->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); /* re-configure hp20 memories */ - IF( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -361,28 +364,22 @@ ivas_error ivas_omasa_dec_config_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + ism_total_brate = L_add( ism_total_brate, sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )] ); } brate_SCE = 0; move32(); - IF( GT_16( st_ivas->nSCE, 0 ) ) + IF( st_ivas->nSCE > 0 ) { - brate_SCE = sep_object_brate[k - 2][st_ivas->nSCE - 1]; + brate_SCE = sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )]; move32(); } brate_CPE = L_sub( ivas_total_brate, ism_total_brate ); -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, 1, 2, 0, brate_SCE, brate_CPE ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - IF( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, brate_SCE, brate_CPE ) ) != IVAS_ERR_OK ) + + IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, 1, 2, 0, brate_SCE, brate_CPE ) ), IVAS_ERR_OK ) ) { return error; } -#endif IF( NE_16( ism_mode_old, st_ivas->ism_mode ) ) { @@ -391,27 +388,27 @@ ivas_error ivas_omasa_dec_config_fx( move16(); test(); - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { n_MD = 1; move16(); IF( st_ivas->hIsmMetaData[0] == NULL ) { - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, 1, NULL ) ), IVAS_ERR_OK ) ) { return error; } } } - ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { n_MD = st_ivas->nchan_ism; move16(); ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, NULL ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -433,9 +430,9 @@ ivas_error ivas_omasa_dec_config_fx( IF( NE_16( old_renderer_type, st_ivas->renderer_type ) ) { - IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { - IF( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -452,16 +449,16 @@ ivas_error ivas_omasa_dec_config_fx( ivas_omasa_separate_object_renderer_close( st_ivas ); } - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate TD renderer for the objects in DISC mode */ #ifdef FIX_1033_MEMORY_LEAK_OMASA IF( st_ivas->hBinRendererTd == NULL ) { #endif - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ), IVAS_ERR_OK ) ) { return error; } @@ -470,7 +467,7 @@ ivas_error ivas_omasa_dec_config_fx( #endif /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -479,7 +476,8 @@ ivas_error ivas_omasa_dec_config_fx( { /* TD renderer handle */ #ifdef FIX_1033_MEMORY_LEAK_OMASA - IF( st_ivas->hBinRendererTd != NULL && st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + test(); + IF( st_ivas->hBinRendererTd != NULL && EQ_16( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM, TRUE ) ) { #endif ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); @@ -494,17 +492,19 @@ ivas_error ivas_omasa_dec_config_fx( } } - IF( st_ivas->renderer_type == RENDERER_DIRAC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + test(); + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -522,7 +522,7 @@ ivas_error ivas_omasa_dec_config_fx( IF( st_ivas->hDiracDecBin != NULL ) { - IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ), IVAS_ERR_OK ) ) { return error; @@ -533,7 +533,7 @@ ivas_error ivas_omasa_dec_config_fx( * CLDFB instances *-----------------------------------------------------------------*/ - IF( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -543,12 +543,12 @@ ivas_error ivas_omasa_dec_config_fx( *-----------------------------------------------------------------*/ nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } @@ -919,6 +919,7 @@ void ivas_set_surplus_brate_dec( move32(); st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, *ism_total_brate ); + move32(); /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_PARAM_ONE_OBJ mode */ st_ivas->hSCE[0]->hCoreCoder[0]->total_brate = *ism_total_brate; @@ -926,7 +927,7 @@ void ivas_set_surplus_brate_dec( st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 0; move16(); - IF( EQ_16( st_ivas->hIsmMetaData[0]->ism_imp, ISM_NO_META ) ) + if ( EQ_16( st_ivas->hIsmMetaData[0]->ism_imp, ISM_NO_META ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 1; move16(); @@ -961,7 +962,7 @@ void ivas_set_surplus_brate_dec( tmp = idiv1616( bits_ism, st_ivas->nchan_ism ); } set16_fx( bits_element, tmp, st_ivas->nchan_ism ); - bits_element[st_ivas->nchan_ism - 1] = add( bits_element[st_ivas->nchan_ism - 1], bits_ism % st_ivas->nchan_ism ); + bits_element[sub( st_ivas->nchan_ism, 1 )] = add( bits_element[sub( st_ivas->nchan_ism, 1 )], bits_ism % st_ivas->nchan_ism ); move16(); bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism ); @@ -980,16 +981,20 @@ void ivas_set_surplus_brate_dec( IF( GT_16( ism_imp[n], 1 ) && EQ_16( st_ivas->flag_omasa_brate, 1 ) && brate_limit_flag >= 0 ) { *ism_total_brate = L_sub( *ism_total_brate, ADJUST_ISM_BRATE_NEG ); + move32(); } + test(); test(); test(); IF( EQ_16( brate_limit_flag, -1 ) && GE_16( ism_imp[n], 1 ) && GE_16( st_ivas->nchan_ism, 3 ) && GT_32( L_sub( ism_total_brate_ref, *ism_total_brate ), IVAS_48k ) ) { *ism_total_brate = L_add( *ism_total_brate, ADJUST_ISM_BRATE_POS ); + move32(); } } st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, *ism_total_brate ); + move32(); /* 'st->total_brate' is set in ivas_ism_config */ } @@ -1124,8 +1129,9 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /* decode ISM metadata */ - IF( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, - nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, + nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), + IVAS_ERR_OK ) ) { return error; } @@ -1138,8 +1144,16 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( { // azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); // elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - azimuth_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[n]->azimuth_fx, ONE_IN_Q21 ), 21 ) / 2 ); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf - elevation_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[n]->elevation_fx, ONE_IN_Q21 ), 21 ) / 2 ); + azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx ), 22 ) ); + if ( st_ivas->hIsmMetaData[n]->azimuth_fx < 0 ) + { + azimuth_ism = negate( azimuth_ism ); + } + elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx ), 22 ) ); + if ( st_ivas->hIsmMetaData[n]->elevation_fx < 0 ) + { + elevation_ism = negate( elevation_ism ); + } FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -1154,8 +1168,16 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( } ELSE /* ISM_MASA_MODE_MASA_ONE_OBJ */ { - azimuth_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[0]->azimuth_fx, ONE_IN_Q21 ), 21 ) / 2 ); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf - elevation_ism = extract_l( L_shr( L_add( st_ivas->hIsmMetaData[0]->elevation_fx, ONE_IN_Q21 ), 21 ) / 2 ); + azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[0]->azimuth_fx ), 22 ) ); + if ( st_ivas->hIsmMetaData[0]->azimuth_fx < 0 ) + { + azimuth_ism = negate( azimuth_ism ); + } + elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[0]->elevation_fx ), 22 ) ); + if ( st_ivas->hIsmMetaData[0]->elevation_fx < 0 ) + { + elevation_ism = negate( elevation_ism ); + } FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -1237,6 +1259,7 @@ void ivas_omasa_dirac_rend_jbm_fx( Word16 n; Word32 data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { Copy32( output_f[CPE_CHANNELS], data_separated_objects[0], nSamplesAsked ); @@ -1371,7 +1394,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( } /* Delay the object signals to match the CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ - IF( EQ_16( st_ivas->hSpatParamRendCom->slots_rendered, 0 ) ) + IF( st_ivas->hSpatParamRendCom->slots_rendered == 0 ) { Word16 tcBufferSize; @@ -1391,7 +1414,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( /* reset combined orientation access index before calling the td renderer */ ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); - IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ), IVAS_ERR_OK ) ) { return error; } @@ -1411,6 +1434,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( * in case of external rendering, rearrange the channels order *--------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_rearrange_channels( float *output[], /* o : output synthesis signal */ const int16_t nchan_transport_ism, /* o : number of ISM TCs */ @@ -1432,8 +1456,7 @@ void ivas_omasa_rearrange_channels( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_omasa_rearrange_channels_fx( Word32 *output[], /* o : output synthesis signal */ const Word16 nchan_transport_ism, /* o : number of ISM TCs */ @@ -1451,7 +1474,7 @@ void ivas_omasa_rearrange_channels_fx( Copy32( output[CPE_CHANNELS + n], output[n], output_frame ); } Copy32( tmp_buff[0], output[n], output_frame ); - Copy32( tmp_buff[1], output[n + 1], output_frame ); + Copy32( tmp_buff[1], output[add( n, 1 )], output_frame ); return; } diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index fff163ccd..47d3ee5ec 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -42,8 +42,6 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx1.h" #include "prot_fx2.h" -#include "math.h" // temporary (for fabs) -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif // IVAS_FLOAT_FIXED @@ -93,24 +91,26 @@ ivas_error ivas_osba_data_open_fx( ) { SBA_ISM_DATA_HANDLE hSbaIsmData; - int16_t i; + Word16 i; - if ( ( hSbaIsmData = (SBA_ISM_DATA_HANDLE) malloc( sizeof( SBA_ISM_DATA ) ) ) == NULL ) + IF( ( hSbaIsmData = (SBA_ISM_DATA_HANDLE) malloc( sizeof( SBA_ISM_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OSBA data\n" ) ); } hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; - hSbaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); + move16(); + hSbaIsmData->delayBuffer_size = shr( div_l( st_ivas->hDecoderConfig->output_Fs, 50 / 2 ), 2 /* / MAX_PARAM_SPATIAL_SUBFRAMES*/ ); + move16(); - if ( ( hSbaIsmData->delayBuffer_fx = (Word32 **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hSbaIsmData->delayBuffer_fx = (Word32 **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); } - for ( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ ) + FOR( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ ) { - if ( ( hSbaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( hSbaIsmData->delayBuffer_size * sizeof( Word32 ) ) ) == NULL ) + IF( ( hSbaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( hSbaIsmData->delayBuffer_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) ); } @@ -162,16 +162,17 @@ void ivas_osba_data_close_fx( SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ ) { - int16_t i; + Word16 i; - if ( hSbaIsmData == NULL || *hSbaIsmData == NULL ) + test(); + IF( hSbaIsmData == NULL || *hSbaIsmData == NULL ) { return; } - if ( ( *hSbaIsmData )->delayBuffer_fx != NULL ) + IF( ( *hSbaIsmData )->delayBuffer_fx != NULL ) { - for ( i = 0; i < ( *hSbaIsmData )->delayBuffer_nchan; i++ ) + FOR( i = 0; i < ( *hSbaIsmData )->delayBuffer_nchan; i++ ) { free( ( *hSbaIsmData )->delayBuffer_fx[i] ); } @@ -208,7 +209,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( ivas_error error; Word32 output_separated_objects_fx[BINAURAL_CHANNELS][L_FRAME48k]; // VE2SB: TBV Word32 *p_sepobj_fx[BINAURAL_CHANNELS]; - int16_t channel_offset; + Word16 channel_offset; FOR( n = 0; n < BINAURAL_CHANNELS; n++ ) { @@ -218,12 +219,12 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( channel_offset = st_ivas->nchan_ism; move16(); - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_fx[channel_offset], out_len ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_fx[channel_offset], out_len ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ), IVAS_ERR_OK ) ) { return error; } @@ -233,7 +234,8 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( Word16 i; FOR( i = 0; i < nSamplesAsked; i++ ) { - output_fx[n][i] = L_add( L_shr( output_fx[channel_offset + n][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); + output_fx[n][i] = L_add( L_shr( output_fx[add( channel_offset, n )][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); + move32(); } } return IVAS_ERR_OK; @@ -302,11 +304,14 @@ ivas_error ivas_osba_ism_metadata_dec_fx( /* set ISM parameters */ nchan_transport_ism = st_ivas->nchan_ism; + move16(); *nchan_ism = st_ivas->nchan_ism; + move16(); /* decode ISM metadata */ - IF( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi, - nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hCPE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi, + nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hCPE[0]->hCoreCoder[0] ) ), + IVAS_ERR_OK ) ) { return error; } @@ -367,22 +372,22 @@ ivas_error ivas_osba_render_sf_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - v_shr( p_output[n], sub( Q11, Q11 ), output_ism[n], nSamplesAsked ); + v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); } - IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960 ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { ivas_ism_render_sf_fx( st_ivas, p_output_ism, *nSamplesRendered ); } FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) { - IF( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { v_add_fixed( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered, 1 ); // takes care of downscaling by 0.5f } diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index 2e34c3508..9b9d1b402 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -176,18 +176,22 @@ void ivas_renderer_select( IF( EQ_16( nchan_internal, 2 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 1; + move16(); } ELSE IF( EQ_16( nchan_internal, 4 ) || EQ_16( nchan_internal, 3 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 0; + move16(); } ELSE IF( EQ_16( nchan_internal, 6 ) || EQ_16( nchan_internal, 5 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 2; + move16(); } ELSE IF( EQ_16( nchan_internal, 8 ) || EQ_16( nchan_internal, 7 ) ) { st_ivas->hCombinedOrientationData->shd_rot_max_order = 3; + move16(); } } } @@ -357,7 +361,17 @@ void ivas_renderer_select( IVAS_FORMAT ivas_format; *renderer_type = RENDERER_DIRAC; move16(); - ivas_format = ( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) ? SBA_FORMAT : st_ivas->ivas_format; /* treat ISM_SBA_MODE_NONE just like SBA_FORMAT */ + + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) + { + ivas_format = SBA_FORMAT; /* treat ISM_SBA_MODE_NONE just like SBA_FORMAT */ + } + ELSE + { + ivas_format = st_ivas->ivas_format; + } + move16(); test(); test(); @@ -410,6 +424,7 @@ void ivas_renderer_select( move16(); } st_ivas->renderer_type = RENDERER_SBA_LINEAR_DEC; + move16(); } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) || ( EQ_32( ivas_format, SBA_FORMAT ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) ) @@ -487,6 +502,7 @@ void ivas_renderer_select( ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { *internal_config = transport_config; + move16(); test(); IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && NE_32( *internal_config, output_config ) ) { @@ -506,6 +522,7 @@ void ivas_renderer_select( ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { *internal_config = transport_config; + move16(); IF( NE_32( *internal_config, output_config ) ) { test(); diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index fb4a65206..095868940 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -1432,7 +1432,7 @@ static void JB4_popFromBuffer( test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ); + frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); test(); IF( frameoffset > 0 && LT_16( frameoffset, MAXOFFSET ) ) { @@ -1509,7 +1509,7 @@ static void JB4_popFromBuffer( test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ); + frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); test(); IF( ( frameoffset > 0 ) && LT_16( frameoffset, MAXOFFSET ) ) { diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index ad750273b..a4810115b 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -28,6 +28,7 @@ void CNG_reset_dec_fx( /*set16_fx( st_fx->dispMem_fx, 0, 8 );*/ set16_fx( st_fx->dm_fx.prev_gain_pit, 0, 6 ); st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + move32(); st_fx->dm_fx.prev_state = 0; move16(); @@ -66,6 +67,7 @@ void CNG_reset_dec_fx( #else st_fx->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ #endif + move16(); } /* reset the pitch buffer in case of FRAME_NO_DATA or SID frames */ IF( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -86,8 +88,8 @@ void CNG_reset_dec_fx( if ( st_fx->hTdCngDec != NULL ) { st_fx->hTdCngDec->act_cnt2 = 0; + move16(); } - move16(); return; } diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index 39b56fa7f..b3c6998b6 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -14,18 +14,19 @@ * Modifies excitation signal in UC mode when the noise is stationary *---------------------------------------------------------*/ void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ - , + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector */ + Word16 *lsp_mid, /* i : mid-frame LSP vector */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ + Word16 *exc2, /* i/o: excitation buffer */ const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ) { Word16 noisiness = 0, i; + move16(); Word32 L_tmp; Word16 coder_type = st_fx->coder_type; + move16(); /*-----------------------------------------------------------------* @@ -33,18 +34,18 @@ void stat_noise_uv_dec_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16( coder_type, UNVOICED ) && !uc_two_stage_flag ) || ( EQ_16( coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) + test(); + IF( ( EQ_16( coder_type, UNVOICED ) && !uc_two_stage_flag ) || ( coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) { /* read the noisiness parameter */ noisiness = (Word16) get_next_indice( st_fx, 5 ); - move16(); } /*-----------------------------------------------------------------* * Update long-term energies for FEC * Update LSP vector for CNG *-----------------------------------------------------------------*/ - IF( EQ_16( coder_type, INACTIVE ) ) + IF( coder_type == INACTIVE ) { IF( GT_16( st_fx->unv_cnt, 20 ) ) { @@ -52,8 +53,8 @@ void stat_noise_uv_dec_fx( L_tmp = L_mult0( st_fx->lp_gainc_fx, st_fx->lp_gainc_fx ); /*Q3 * Q3 ->Q6*/ /*st->lp_ener = 0.7f * st->lp_ener + 0.3f * ftmp;*/ L_tmp = Mult_32_16( L_tmp, 9830 ); - st_fx->lp_ener_fx = L_add( Mult_32_16( st_fx->lp_ener_fx, 22938 ), L_tmp ); - move16(); /*Q6 + Q6*/ + st_fx->lp_ener_fx = L_add( Mult_32_16( st_fx->lp_ener_fx, 22938 ), L_tmp ); /*Q6 + Q6*/ + move32(); FOR( i = 0; i < M; i++ ) /* AR Low pass filter */ { @@ -66,6 +67,7 @@ void stat_noise_uv_dec_fx( ELSE { st_fx->unv_cnt = add( st_fx->unv_cnt, 1 ); + move16(); } } ELSE diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index bcee86982..f2b096d72 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -239,6 +239,7 @@ static Word16 para_pred_bws_fx( Word32 avrg1_fx, avrg2_fx, min_fx; Word16 att_fx; Word16 coder_type = st_fx->coder_type; + move16(); mode = NORMAL; move16(); @@ -246,7 +247,6 @@ static Word16 para_pred_bws_fx( k = 0; move16(); input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; - move16(); FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -266,7 +266,7 @@ static Word16 para_pred_bws_fx( input_hi_fx++; } - IF( Q_syn < 11 ) + IF( LT_16( Q_syn, 11 ) ) { tmp = 1; move16(); @@ -343,6 +343,7 @@ static Word16 para_pred_bws_fx( IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) { min_fx = peak_32_fx; + move32(); } ELSE { @@ -380,34 +381,30 @@ static Word16 para_pred_bws_fx( j = 0; move16(); mea = &mean_fx[4]; - move16(); L_tmp_max = L_shl( 32767, add( Q_syn, 5 ) ); FOR( i = 0; i < SWB_FENV; i++ ) { - IF( j == 5 ) + if ( EQ_16( j, 5 ) ) { mea++; - move16(); j = 0; move16(); } - j++; - move16(); + j = add( j, 1 ); L_tmp = L_min( Mult_32_16( *mea, tmp ), L_tmp_max ); SWB_fenv_fx[i] = extract_l( L_shr( L_tmp, add( Q_syn, 5 ) ) ); + move16(); } } j = 0; move16(); - FOR( i = shr( SWB_FENV, 1 ); i < SWB_FENV; i++ ) + FOR( i = SWB_FENV / 2; i < SWB_FENV; i++ ) { tmp = sub( 32767, i_mult( j, 2341 ) ); - move16(); SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], tmp ); move16(); - j++; - move16(); + j = add( j, 1 ); } IF( GT_32( avrg1_fx, L_shl( avrg2_fx, 3 ) ) ) @@ -435,11 +432,13 @@ static Word16 para_pred_bws_fx( { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + move16(); } ELSE { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + move16(); } } @@ -472,6 +471,7 @@ static Word16 para_pred_bws_fx( { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 29491), mult_r(st_fx->prev_SWB_fenv_fx[i], 3277)); */ SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + move16(); } st_fx->attenu_fx = 3277; move16(); @@ -484,8 +484,7 @@ static Word16 para_pred_bws_fx( } - att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); - move16(); /*15 */ + att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); /*15 */ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( i = 0; i < 4; i++ ) @@ -1072,8 +1071,10 @@ Word16 swb_bwe_dec_fx32( Word16 i, j, l_subfr; Word16 fb_band_begin; Word16 frica_flag = 0; + move16(); Word16 ener_adjust_quan_fx; Word16 fb_ener_adjust_fx = 0; + move16(); Word16 scl, new_input_fx_exp, ysynth_frame_size; Word16 Q_syn, Q_syn_hb, tmp, tmp2, q_tmp, Qsynth_fx16; @@ -1095,7 +1096,7 @@ Word16 swb_bwe_dec_fx32( /*---------------------------------------------------------------------* * SWB BWE decoding *---------------------------------------------------------------------*/ - + test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { /* todo - wtda() does not support L_FRAME length; thus temporarily resample the signal */ @@ -1107,8 +1108,10 @@ Word16 swb_bwe_dec_fx32( /* DCT of the ACELP core synthesis */ new_input_fx_exp = 11; + move16(); direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, /*st_fx->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); ysynth_frame_size = L_FRAME16k; + move16(); } ELSE { @@ -1119,18 +1122,20 @@ Word16 swb_bwe_dec_fx32( /* DCT of the ACELP core synthesis */ // direct_transform(wtda_synth, ysynth, 0, output_frame, st_fx->element_mode); new_input_fx_exp = 11; + move16(); direct_transform_fx( wtda_synth_fx, ysynth_fx32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); ysynth_frame_size = output_frame; + move16(); } /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub( 16 + 11, new_input_fx_exp ); /* Possible to Upscale? */ - IF( GT_16( scl, 0 ) ) + IF( scl > 0 ) { /* Yes */ /* Calc Room to Upscale */ - Q_syn = Find_Max_Norm32( ysynth_fx32, ysynth_frame_size ) - 3; + Q_syn = sub( Find_Max_Norm32( ysynth_fx32, ysynth_frame_size ), 3 ); /* Stay within MAX_Q_NEW_INPUT */ scl = s_min( Q_syn, scl ); } @@ -1140,8 +1145,10 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < ysynth_frame_size; i++ ) { ysynth_fx[i] = extract_l( ysynth_fx32[i] ); + move16(); } Q_syn = new_input_fx_exp; + move16(); } ELSE { @@ -1151,7 +1158,7 @@ Word16 swb_bwe_dec_fx32( IF( !st_fx->bfi ) { - IF( GT_16( st_fx->bws_cnt, 0 ) ) + IF( st_fx->bws_cnt > 0 ) { /* estimate parameters */ mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn ); @@ -1163,12 +1170,15 @@ Word16 swb_bwe_dec_fx32( } L = SWB_FENV; - IF( EQ_16( mode, TRANSIENT ) ) + move16(); + if ( EQ_16( mode, TRANSIENT ) ) { L = SWB_FENV_TRANS; + move16(); } L_tmp = 0; + move32(); FOR( i = 0; i < L; i++ ) { L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) ); @@ -1177,6 +1187,7 @@ Word16 swb_bwe_dec_fx32( tmp = div_s( shl( 1, sub( 14, q_tmp ) ), L ); /*Q(29-q_tmp) */ L_tmp = Mpy_32_16_1( L_tmp, tmp ); /*Q(1+29-q_tmp+1-16)->Q(15-q_tmp) */ st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( q_tmp, 2 ) ) ); /*Q1 */ + move16(); } ELSE { @@ -1185,10 +1196,12 @@ Word16 swb_bwe_dec_fx32( IF( NE_16( hBWE_FD->prev_mode, TRANSIENT ) ) { mode = hBWE_FD->prev_mode; + move16(); } ELSE { mode = NORMAL; + move16(); } Copy( st_fx->prev_SWB_fenv_fx, SWB_fenv_fx, SWB_FENV ); @@ -1206,18 +1219,20 @@ Word16 swb_bwe_dec_fx32( SWB_BWE_decoding_fx( ysynth_fx, SWB_fenv_fx, yerror_fx, L_FRAME32k - 80, mode, &frica_flag, &hBWE_FD->prev_Energy_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, st_fx->tilt_wb_fx, &hBWE_FD->Seed, 6, &hBWE_FD->prev_weight_fx, st_fx->extl, Q_syn, st_fx->last_extl, st_fx->element_mode ); } - + test(); IF( EQ_16( hBWE_FD->prev_frica_flag, 1 ) && frica_flag == 0 ) { FOR( i = 0; i < L_SUBFR; i++ ) { tmp = sub( 32767, extract_l( L_mult0( i, 512 ) ) ); /*Q15 */ hBWE_FD->mem_imdct_fx[i] = mult_r( hBWE_FD->mem_imdct_fx[i], tmp ); + move16(); } FOR( ; i < output_frame; i++ ) { hBWE_FD->mem_imdct_fx[i] = 0; + move16(); } } @@ -1232,9 +1247,11 @@ Word16 swb_bwe_dec_fx32( ELSE IF( st_fx->bfi ) { fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; + move16(); } st_fx->prev_fb_ener_adjust_fx = fb_ener_adjust_fx; + move16(); IF( EQ_16( mode, TRANSIENT ) ) { ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 ); @@ -1249,17 +1266,21 @@ Word16 swb_bwe_dec_fx32( ELSE { ener_adjust_quan_fx = 0; + move16(); } } fb_band_begin = FB_BAND_BEGIN; - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + move16(); + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { fb_band_begin = FB_BAND_BEGIN_12k8; + move16(); } j = 0; - FOR( i = fb_band_begin; i < fb_band_begin + DE_OFFSET1; i++ ) + move16(); + FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ ) { tmp = sub( 32767, i_mult( j, 1024 ) ); tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/ @@ -1269,11 +1290,13 @@ Word16 swb_bwe_dec_fx32( tmp = add( tmp, tmp2 ); /*Q13*/ yerror_fx[i] = L_shl( Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], tmp ), 2 ); /*15+Q_syn */ + move32(); j = add( j, 1 ); } FOR( ; i < FB_BAND_END; i++ ) { yerror_fx[i] = Mpy_32_16_1( yerror_fx[i - FB_BAND_WIDTH], fb_ener_adjust_fx ); /*15+Q_syn */ + move32(); } } @@ -1285,11 +1308,13 @@ Word16 swb_bwe_dec_fx32( window_ola_fx( wtda_synth_fx, hb_synth_fx16, &Q_syn_hb, hBWE_FD->mem_imdct_fx, &hBWE_FD->mem_imdct_exp_fx, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); l_subfr = mult( output_frame, 8192 ); + test(); IF( EQ_16( mode, TRANSIENT ) ) { FOR( i = 0; i < SWB_TENV; i++ ) { SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + move32(); } /* time envelope shaping when the current frame is TRANSIENT frame */ @@ -1297,13 +1322,14 @@ Word16 swb_bwe_dec_fx32( Q_syn_hb = sub( Q_syn_hb, 3 ); hBWE_FD->prev_td_energy_fx = SWB_tenv_fx[3]; + move16(); } - ELSE IF( EQ_16( frica_flag, 1 ) && EQ_16( hBWE_FD->prev_frica_flag, 0 ) ) + ELSE IF( EQ_16( frica_flag, 1 ) && hBWE_FD->prev_frica_flag == 0 ) { Qsynth_fx16 = Find_Max_Norm32( synth_fx, output_frame ); Qsynth_fx16 = sub( Qsynth_fx16, shr( add( sub( 15, norm_s( l_subfr ) ), 1 ), 1 ) ); Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 ); - Qsynth_fx16 = add( sub( 11, 16 ), Qsynth_fx16 ); + Qsynth_fx16 = add( 11 - 16, Qsynth_fx16 ); /* IVAS_fmToDo: synth[] is @internal_Fs!!! */ time_reduce_pre_echo_fx( synth_fx16, hb_synth_fx16, hBWE_FD->prev_td_energy_fx, l_subfr, Qsynth_fx16, Q_syn_hb ); @@ -1315,13 +1341,14 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < l_subfr; i++ ) { - L_tmp = L_mac0_sat( L_tmp, hb_synth_fx16[tmp + i], hb_synth_fx16[tmp + i] ); /*(2*Q_syn_hb) */ + L_tmp = L_mac0_sat( L_tmp, hb_synth_fx16[add( tmp, i )], hb_synth_fx16[add( tmp, i )] ); /*(2*Q_syn_hb) */ } L_tmp = Mult_32_16( L_tmp, div_s( 1, l_subfr ) ); /*(2*Q_syn_hb) */ hBWE_FD->prev_td_energy_fx = 0; + move16(); - IF( NE_32( L_tmp, 0 ) ) + IF( L_tmp != 0 ) { q_tmp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, q_tmp ) ); @@ -1331,12 +1358,14 @@ Word16 swb_bwe_dec_fx32( L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &q_tmp ); /*Q(31-exp) */ hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( q_tmp, 15 ) ) ); /*Q0 */ + move16(); } } + test(); IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { - Qsynth_fx16 = add( sub( 16, 11 ), Q_syn_hb ); + Qsynth_fx16 = add( 16 - 11, Q_syn_hb ); Copy_Scale_sig32_16( synth_fx, synth_fx16, output_frame, Qsynth_fx16 ); /* add HB synth from hf_synth() */ @@ -1344,11 +1373,14 @@ Word16 swb_bwe_dec_fx32( } hBWE_FD->prev_mode = mode; + move16(); hBWE_FD->prev_frica_flag = frica_flag; + move16(); FOR( i = 0; i < output_frame; i++ ) { hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + move32(); } return Q_syn_hb; diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 34167dc29..742706db3 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -38,6 +38,7 @@ static Word16 para_pred_bws_fx( Word32 avrg1_fx, avrg2_fx, min_fx; Word16 att_fx; Word16 coder_type = st_fx->coder_type; + move16(); mode = NORMAL; move16(); @@ -45,7 +46,6 @@ static Word16 para_pred_bws_fx( k = 0; move16(); input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; - move16(); FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -65,7 +65,7 @@ static Word16 para_pred_bws_fx( input_hi_fx++; } - IF( Q_syn < 11 ) + IF( LT_16( Q_syn, 11 ) ) { tmp = 1; move16(); @@ -142,6 +142,7 @@ static Word16 para_pred_bws_fx( IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) { min_fx = peak_32_fx; + move32(); } ELSE { @@ -179,34 +180,30 @@ static Word16 para_pred_bws_fx( j = 0; move16(); mea = &mean_fx[4]; - move16(); L_tmp_max = L_shl( 32767, add( Q_syn, 5 ) ); FOR( i = 0; i < SWB_FENV; i++ ) { - IF( j == 5 ) + if ( EQ_16( j, 5 ) ) { mea++; - move16(); j = 0; move16(); } - j++; - move16(); + j = add( j, 1 ); L_tmp = L_min( Mult_32_16( *mea, tmp ), L_tmp_max ); SWB_fenv_fx[i] = extract_l( L_shr( L_tmp, add( Q_syn, 5 ) ) ); + move16(); } } j = 0; move16(); - FOR( i = shr( SWB_FENV, 1 ); i < SWB_FENV; i++ ) + FOR( i = SWB_FENV / 2; i < SWB_FENV; i++ ) { tmp = sub( 32767, i_mult( j, 2341 ) ); - move16(); SWB_fenv_fx[i] = mult_r( SWB_fenv_fx[i], tmp ); move16(); - j++; - move16(); + j = add( j, 1 ); } IF( GT_32( avrg1_fx, L_shl( avrg2_fx, 3 ) ) ) @@ -234,11 +231,13 @@ static Word16 para_pred_bws_fx( { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 3277), mult_r(st_fx->prev_SWB_fenv_fx[i], 29491)); */ SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 3277 ), st_fx->prev_SWB_fenv_fx[i], 29491 ) ); + move16(); } ELSE { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], st_fx->attenu_fx), mult_r(st_fx->prev_SWB_fenv_fx[i], sub(32767, st_fx->attenu_fx))); */ SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], st_fx->attenu_fx ), st_fx->prev_SWB_fenv_fx[i], sub( 32767, st_fx->attenu_fx ) ) ); + move16(); } } @@ -271,6 +270,7 @@ static Word16 para_pred_bws_fx( { /*SWB_fenv_fx[i] = add(mult_r(SWB_fenv_fx[i], 29491), mult_r(st_fx->prev_SWB_fenv_fx[i], 3277)); */ SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); + move16(); } st_fx->attenu_fx = 3277; move16(); @@ -283,8 +283,7 @@ static Word16 para_pred_bws_fx( } - att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); - move16(); /*15 */ + att_fx = i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ); /*15 */ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { FOR( i = 0; i < 4; i++ ) @@ -332,7 +331,7 @@ Word16 WB_BWE_gain_deq_fx( move16(); - L_tmp = L_shr( F_2_5_fx[add( index2, 1 )], 1 ); + L_tmp = L_shr( F_2_5_fx[index2 + 1], 1 ); L_tmp = L_shl( L_tmp, 6 ); frac = L_Extract_lc( L_tmp, &exp ); @@ -372,6 +371,7 @@ Word16 ivas_wb_bwe_dec_fx( FD_BWE_DEC_HANDLE hBWE_FD; Word16 coder_type = st_fx->coder_type; + move16(); hBWE_FD = st_fx->hBWE_FD; @@ -379,7 +379,8 @@ Word16 ivas_wb_bwe_dec_fx( new_input_fx_exp = *Qpost; move16(); - IF( st_fx->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft ) + test(); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_dft ) { /* IVAS_fmToDo: wtda() does not support L_FRAME length; thus temporarily resample the signal */ /* IVAS_fmToDo: delay output[] by 1.25ms ? */ @@ -387,6 +388,7 @@ Word16 ivas_wb_bwe_dec_fx( wtda_fx( ysynth_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /*st->L_frame*/ L_FRAME16k ); *Qpost = sub( new_input_fx_exp, 15 ); + move16(); direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, /*st->L_frame*/ L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); } ELSE @@ -395,6 +397,7 @@ Word16 ivas_wb_bwe_dec_fx( &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); *Qpost = sub( new_input_fx_exp, 15 ); + move16(); /* DCT of the ACELP core synthesis */ #ifdef MSAN_FIX direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); @@ -430,19 +433,21 @@ Word16 ivas_wb_bwe_dec_fx( /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ) ); + move16(); } ELSE { Word32 tmp_brate; tmp_brate = st_fx->last_core_brate; + move32(); test(); - IF( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) + if ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { tmp_brate = ACELP_8k00; /* this is needed in order to stay BE wrt. EVS mono */ - move16(); + move32(); } - IF( NE_16( st_fx->last_extl, WB_BWE ) ) + if ( NE_16( st_fx->last_extl, WB_BWE ) ) { st_fx->prev_SWB_fenv_fx[0] = 0; move16(); @@ -450,7 +455,6 @@ Word16 ivas_wb_bwe_dec_fx( mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, st_fx->prev_SWB_fenv_fx[0], voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); - move16(); } } ELSE @@ -461,6 +465,7 @@ Word16 ivas_wb_bwe_dec_fx( FOR( i = 0; i < 2; i++ ) { WB_fenv_fx[i] = mult_r( st_fx->prev_SWB_fenv_fx[i], 24576 ); + move16(); } } test(); @@ -473,11 +478,13 @@ Word16 ivas_wb_bwe_dec_fx( IF( GT_16( add( st_fx->prev_Q_synth, exp ), Q_syn ) ) { hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( st_fx->prev_Q_synth, Q_syn ) ); + move32(); } ELSE { Q_syn = add( st_fx->prev_Q_synth, exp ); hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp ); + move32(); } WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, @@ -502,7 +509,9 @@ Word16 ivas_wb_bwe_dec_fx( v_add_16( hb_synth_fx, synth_fx, hb_synth_fx, output_frame ); } hBWE_FD->prev_mode = mode; + move16(); st_fx->prev_Q_synth = Q_syn; + move16(); return Q_syn_hb; } #endif @@ -533,6 +542,7 @@ Word16 wb_bwe_dec_fx( FD_BWE_DEC_HANDLE hBWE_FD; Word16 coder_type = st_fx->coder_type; + move16(); hBWE_FD = st_fx->hBWE_FD; @@ -557,6 +567,7 @@ Word16 wb_bwe_dec_fx( &hBWE_FD->old_wtda_swb_fx_exp, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); *Qpost = sub( new_input_fx_exp, 15 ); + move16(); /* DCT of the ACELP core synthesis */ direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); } @@ -588,18 +599,20 @@ Word16 wb_bwe_dec_fx( #else st_fx->last_wb_bwe_ener_fx = mult_r( add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ); #endif + move16(); } ELSE { int32_t tmp_brate; tmp_brate = st_fx->last_core_brate; + move32(); #if 1 // def ADD_IVAS_BWE test(); - IF( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) + if ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { tmp_brate = ACELP_8k00; /* this is needed in order to stay BE wrt. EVS mono */ - move16(); + move32(); } #endif if ( NE_16( st_fx->last_extl, WB_BWE ) ) @@ -610,7 +623,6 @@ Word16 wb_bwe_dec_fx( mode = WB_BWE_gain_pred_fx( WB_fenv_fx, ysynth_fx, coder_type, st_fx->prev_coder_type, st_fx->prev_SWB_fenv_fx[0], voice_factors_fx, pitch_buf_fx, tmp_brate, st_fx->last_wb_bwe_ener_fx, Q_syn, st_fx->last_extl, st_fx->tilt_wb_fx ); - move16(); } } ELSE @@ -621,6 +633,7 @@ Word16 wb_bwe_dec_fx( FOR( i = 0; i < 2; i++ ) { WB_fenv_fx[i] = mult_r( st_fx->prev_SWB_fenv_fx[i], 24576 ); + move16(); } } test(); @@ -633,11 +646,13 @@ Word16 wb_bwe_dec_fx( IF( GT_16( add( st_fx->prev_Q_synth, exp ), Q_syn ) ) { hBWE_FD->prev_Energy_wb_fx = L_shr( hBWE_FD->prev_Energy_wb_fx, sub( st_fx->prev_Q_synth, Q_syn ) ); + move32(); } ELSE { Q_syn = add( st_fx->prev_Q_synth, exp ); hBWE_FD->prev_Energy_wb_fx = L_shl( hBWE_FD->prev_Energy_wb_fx, exp ); + move32(); } WB_BWE_decoding_fx( ysynth_fx, WB_fenv_fx, ysynth_32, L_FRAME16k, mode, st_fx->last_extl, &hBWE_FD->prev_Energy_wb_fx, st_fx->prev_SWB_fenv_fx, &hBWE_FD->prev_L_swb_norm, @@ -664,7 +679,9 @@ Word16 wb_bwe_dec_fx( } #endif hBWE_FD->prev_mode = mode; + move16(); st_fx->prev_Q_synth = Q_syn; + move16(); return Q_syn_hb; } /*-------------------------------------------------------------------* @@ -708,7 +725,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class } test(); - IF( EQ_16( mode, 1 ) && EQ_16( core, ACELP_CORE ) ) + IF( EQ_16( mode, 1 ) && core == ACELP_CORE ) { FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { @@ -740,7 +757,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class quant_tmp[1] = add( shr( add( quant_tmp[0], quant_tmp[2] ), 1 ), Env_TR_Cdbk2_fx[tmp] ); #endif move16(); /*Q8 */ - quant_tmp[3] = add( quant_tmp[2], Env_TR_Cdbk2_fx[add( tmp, 1 )] ); + quant_tmp[3] = add( quant_tmp[2], Env_TR_Cdbk2_fx[tmp + 1] ); move16(); /*Q8 */ FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) @@ -817,9 +834,9 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); - Copy( &EnvCdbk2nd_fx[i_mult2( indice[2], DIM2ND )], quant_tmp2 + DIM1ST, DIM2ND ); + Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND ); - FOR( n_band = 0; n_band < DIM11 - 1; n_band++ ) + FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ ) { quant_tmp[n_band] = add( quant_tmp[n_band], quant_tmp2[n_band] ); move16(); /*Q8 */ @@ -834,13 +851,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class SWB_fenv[11] = quant_tmp[6]; move16(); - Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[i_mult( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk3rd_fx[i_mult( indice[4], DIM3RD )], quant_tmp2 + DIM3RD, DIM3RD ); FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( shl( n_band, 1 ), 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); + SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); #endif @@ -858,19 +875,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class move16(); Copy( &EnvCdbk3rd_fx[i_mult2( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk4th_fx[i_mult2( indice[4], DIM4TH )], quant_tmp2 + DIM3RD, DIM4TH ); + Copy( &EnvCdbk4th_fx[indice[4] * DIM4TH], quant_tmp2 + DIM3RD, DIM4TH ); FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( shl( n_band, 1 ), 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); + SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #else SWB_fenv[add( shl( n_band, 1 ), 1 )] = add( shr( add( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); #endif move16(); /*Q8 */ } - SWB_fenv[n_band * 2 + 1] = add( quant_tmp[n_band], quant_tmp2[n_band] ); + SWB_fenv[add( n_band * 2, 1 )] = add( quant_tmp[n_band], quant_tmp2[n_band] ); move16(); /*Q8 */ } @@ -942,6 +959,7 @@ Word16 swb_bwe_dec_fx( Word16 i, l_subfr; Word16 mode; Word16 frica_flag = 0; + move16(); Word16 idxGain; Word16 Q_syn, Q_syn_hb; Word16 ysynth_fx[L_FRAME48k]; @@ -954,9 +972,11 @@ Word16 swb_bwe_dec_fx( Word32 L_tmp; Word16 exp, frac; Word16 fb_ener_adjust_fx = 0; + move16(); Word16 SWB_fenv_fx[SWB_FENV]; Word16 L; Word16 j = 0; + move16(); Word16 ener_adjust_quan_fx; Word16 tmp2; Word16 fb_band_begin; @@ -968,6 +988,7 @@ Word16 swb_bwe_dec_fx( *---------------------------------------------------------------------*/ /* windowing of the ACELP core synthesis */ new_input_fx_exp = *Qpost; + move16(); #ifdef ADD_IVAS_BWE if ( st->element_mode == IVAS_CPE_DFT && !use_cldfb_for_dft ) { @@ -988,6 +1009,7 @@ Word16 swb_bwe_dec_fx( ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); *Qpost = sub( new_input_fx_exp, 15 ); + move16(); /* DCT of the ACELP core synthesis */ direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); } @@ -1011,13 +1033,11 @@ Word16 swb_bwe_dec_fx( { /* estimate parameters */ mode = para_pred_bws_fx( st_fx, ysynth_fx, SWB_fenv_fx, Q_syn ); - move16(); } ELSE { /* de-quantization */ mode = swb_bwe_gain_deq_fx( st_fx, ACELP_CORE, SWB_tenv_fx, SWB_fenv_fx, 0, -1 ); - move16(); } L = SWB_FENV; @@ -1031,7 +1051,7 @@ Word16 swb_bwe_dec_fx( move16(); FOR( i = 0; i < L; i++ ) { - L_tmp = L_add( L_tmp, (Word32) SWB_fenv_fx[i] ); + L_tmp = L_add( L_tmp, L_deposit_l( SWB_fenv_fx[i] ) ); } exp = norm_s( L ); @@ -1039,6 +1059,7 @@ Word16 swb_bwe_dec_fx( L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(1+29-exp+1-16)->Q(15-exp) */ st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, add( exp, 2 ) ) ); /*Q1 */ + move16(); } ELSE { @@ -1096,7 +1117,7 @@ Word16 swb_bwe_dec_fx( idxGain = (Word16) get_next_indice( st_fx, NUM_BITS_FB_FRAMEGAIN ); fb_ener_adjust_fx = usdequant_fx( idxGain, FB_GAIN_QLOW_FX, FB_GAIN_QDELTA_FX ); /*Q15 */ } - ELSE if ( st_fx->bfi ) + ELSE IF( st_fx->bfi ) { fb_ener_adjust_fx = st_fx->prev_fb_ener_adjust_fx; move16(); @@ -1106,8 +1127,7 @@ Word16 swb_bwe_dec_fx( move16(); IF( EQ_16( mode, TRANSIENT ) ) { - ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 ); - move16(); /*Q13*/ + ener_adjust_quan_fx = shr( fb_ener_adjust_fx, 2 ); /*Q13*/ } ELSE { @@ -1116,11 +1136,10 @@ Word16 swb_bwe_dec_fx( tmp = div_s( 1, SWB_fenv_fx[7] ); move16(); /*Q14*/ #ifdef BASOP_NOGLOB - ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); + ener_adjust_quan_fx = s_min( shr( i_mult_sat( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); /*Q13*/ #else ener_adjust_quan_fx = s_min( shr( i_mult( SWB_fenv_fx[13], tmp ), 2 ), 32767 ); #endif - move16(); /*Q13*/ } ELSE { @@ -1129,13 +1148,14 @@ Word16 swb_bwe_dec_fx( } } fb_band_begin = FB_BAND_BEGIN; + move16(); #ifdef ADD_IVAS_BWE IF( st_fx->L_frame == L_FRAME ) { fb_band_begin = FB_BAND_BEGIN_12k8; } #endif - FOR( i = fb_band_begin; i < fb_band_begin + DE_OFFSET1; i++ ) + FOR( i = fb_band_begin; i < add( fb_band_begin, DE_OFFSET1 ); i++ ) { tmp = sub( 32767, i_mult( j, 1024 ) ); tmp = mult_r( tmp, ener_adjust_quan_fx ); /*Q13*/ @@ -1192,7 +1212,7 @@ Word16 swb_bwe_dec_fx( FOR( i = 0; i < l_subfr; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac0_sat( L_tmp, hb_synth_fx[tmp + i], hb_synth_fx[tmp + i] ); /*(2*Q_syn_hb) */ + L_tmp = L_mac0_sat( L_tmp, hb_synth_fx[add( tmp, i )], hb_synth_fx[add( tmp, i )] ); /*(2*Q_syn_hb) */ #else L_tmp = L_mac0( L_tmp, hb_synth_fx[tmp + i], hb_synth_fx[tmp + i] ); /*(2*Q_syn_hb) */ #endif @@ -1211,6 +1231,7 @@ Word16 swb_bwe_dec_fx( L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ hBWE_FD->prev_td_energy_fx = round_fx( L_shl( L_tmp, sub( exp, 15 ) ) ); /*Q0 */ + move16(); } } #ifdef ADD_IVAS_BWE @@ -1271,6 +1292,7 @@ void fd_bwe_dec_init( st_fx->last_wb_bwe_ener_fx = 0; move16(); hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 ); + move32(); hBWE_FD->memExp1 = 0; move16(); @@ -1279,7 +1301,9 @@ void fd_bwe_dec_init( move16(); hBWE_FD->mem_deemph_old_syn_fx = 0; + move16(); st_fx->prev_fb_ener_adjust_fx = 0; + move16(); return; } diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 3276cf990..ed6ed4ae6 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -47,27 +47,37 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) IF( EQ_16( min, G_AVQ_MIN_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ + move32(); L_fact = MAKE_PSEUDO_FLT( 14145, 11 ); /* Log2(96) - Log2(0.8) in Q11 */ + move32(); } ELSE IF( EQ_16( min, G_AVQ_MIN_DIV10_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 20972, 18 ); /* 0.8*0.1 in Q18 */ + move32(); L_fact = MAKE_PSEUDO_FLT( 20949, 11 ); /* Log2(96) - Log2(0.8*0.1) in Q11 */ + move32(); } ELSE IF( EQ_16( min, G_CODE_MIN_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 20972, 20 ); /* 0.02 in Q20 */ + move32(); L_fact = MAKE_PSEUDO_FLT( 32628, 12 ); /* Log2(5) - Log2(0.02) in Q12 */ + move32(); } ELSE IF( EQ_16( min, G_CODE_MIN_TC192_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 19661, 15 ); /* 0.6 in Q15 */ + move32(); L_fact = MAKE_PSEUDO_FLT( 24963, 12 ); /* Log2(41) - Log2(0.6) in Q12 */ + move32(); } ELSE IF( EQ_16( min, MIN_GLOB_GAIN_BWE_HR_FX ) ) { L_mini = MAKE_PSEUDO_FLT( 24576, 13 ); /* 3.0 in Q13 */ + move32(); L_fact = MAKE_PSEUDO_FLT( 30232, 12 ); /* Log2(500) - Log2(3) in Q12 */ + move32(); } /* levels = 1<bwe_highrate_seed_fx = extract_l( L_mult0( pitch_buf[0], pitch_buf[3] ) ); + move16(); /*---------------------------------------------------------------------* @@ -308,7 +321,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ind2 = 0; move16(); L_ener_saved = 0; - move16(); + move32(); ener_saved_exp = 0; move16(); @@ -331,7 +344,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * calculate tilt of the core synthesis *---------------------------------------------------------------------*/ L_tilt_wb = calc_tilt_bwe_fx( syn_12k8_16k_fx, exp, L_FRAME16k ); - L_temp = L_mac( 1L, 8192, pitch_buf[0] ); + L_temp = L_mac( 1, 8192, pitch_buf[0] ); FOR( i = 1; i < NB_SUBFR16k - 1; i++ ) { L_temp = L_mac( L_temp, 8192, pitch_buf[i] ); @@ -401,9 +414,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp4 = add( temp4, t_audio_exp ); FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[add( i, ind1 )] ); L_temp = L_shr( L_temp, temp4 ); - t_audio32[pos + i] = L_temp; + t_audio32[add( pos, i )] = L_temp; move32(); } ind1 = add( ind1, tmpS ); @@ -457,6 +470,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB hBWE_FD_HR->L_mem_EnergyLT_fx = Mul_flt32_Q15( hBWE_FD_HR->L_mem_EnergyLT_fx, &hBWE_FD_HR->mem_EnergyLT_fx_exp, alpha ); move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = add( hBWE_FD_HR->mem_EnergyLT_fx_exp, t_audio_exp ); + move16(); /* Set Exponent */ t_audio_exp = Q_32_BITS; @@ -557,7 +571,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp = shl( ind1, 1 ); en_band[0] = swb_hr_env_code3_fx[temp]; move16(); - en_band[1] = swb_hr_env_code3_fx[add( temp, 1 )]; + en_band[1] = swb_hr_env_code3_fx[temp + 1]; move16(); /*env = add(shr(en_band[0], 1), shr(en_band[1], 1));*/ @@ -606,9 +620,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* 't_audio' in Q8 */ t_audio_exp = 8; move16(); - FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) + FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { - t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); + t_audio[add( temp, i )] = shl( x_norm[i], t_audio_exp ); move16(); } @@ -623,7 +637,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Go from Q't_audio_exp' on 16 Bits to 'Q_32_BITS' on 32 bits */ temp2 = i_mult2( WIDTH_BAND, Nsv ); ptr16 = &t_audio[temp]; - move16(); ptr32 = &t_audio32[temp]; j = shl( 1, sub( Q_32_BITS, t_audio_exp ) ); FOR( i = 0; i < temp2; i++ ) @@ -644,7 +657,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr( t_audio32[pos + j], 1 ); + *ptr32++ = L_shr( t_audio32[add( pos, j )], 1 ); move32(); } @@ -667,7 +680,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_END_FREQ_COEF_EFF, temp ); j = sub( tmpS, width_noncoded ); ptr16 = &t_audio[add( temp2, j )]; - move16(); ptr32 = &t_audio32[add( temp2, j )]; /* envelope denormalization of 14.4-16(20) kHz spectrum */ FOR( ; j < tmpS; j++ ) @@ -680,15 +692,14 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_START_FREQ_COEF, temp ); ptr16 = &t_audio[temp2]; - move16(); ptr32 = &t_audio32[temp2]; - temp4 = i_mult2( NSV_OVERLAP, shr( WIDTH_BAND, 2 ) ); + temp4 = NSV_OVERLAP * ( WIDTH_BAND >> 2 ); /* overlap region */ IF( EQ_16( output_frame, L_FRAME48k ) ) { FOR( i = 0; i < temp4; i++ ) { - L_temp = Mult_32_16( *ptr32, overlap_coefs_48kHz_fx[shl( i, 2 )] ); /* overlap_coefs_fx in Q15 */ + L_temp = Mult_32_16( *ptr32, overlap_coefs_48kHz_fx[i * 4] ); /* overlap_coefs_fx in Q15 */ *ptr32++ = L_temp; move32(); } @@ -697,7 +708,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { FOR( i = 0; i < temp4; i++ ) { - L_temp = Mult_32_16( *ptr32, overlap_coefs_fx[shl( i, 2 )] ); /* overlap_coefs_fx in Q15 */ + L_temp = Mult_32_16( *ptr32, overlap_coefs_fx[i * 4] ); /* overlap_coefs_fx in Q15 */ *ptr32++ = L_temp; move32(); } @@ -705,9 +716,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_START_FREQ_COEF, temp ); ptr16 = &t_audio[temp2]; - move16(); ptr32 = &t_audio32[temp2]; - temp4 = add( i_mult2( WIDTH_TRANS_FREQ_COEF, N_BANDS_TRANS_BWE_HR ), width_noncoded ); + temp4 = add( WIDTH_TRANS_FREQ_COEF * N_BANDS_TRANS_BWE_HR, width_noncoded ); temp3 = sub( 15, exp1 ); /* apply global gain */ FOR( i = 0; i < temp4; i++ ) @@ -720,7 +730,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* save transform coefficients for the next frame (needed in case of frame erasures) */ temp = add( NUM_TRANS_START_FREQ_COEF, len ); - IF( output_frame == L_FRAME32k ) + IF( EQ_16( output_frame, L_FRAME32k ) ) { pos = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); @@ -728,6 +738,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ELSE /* output_frame == L_FRAME48k */ { pos = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; + move16(); } temp4 = Find_Max_Norm32( t_audio32 + temp, pos ); Copy_Scale_sig32_16( t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx + i_mult2( k, pos ), pos, temp4 ); @@ -745,7 +756,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB j = ( 2 * END_FREQ_BWE_FULL_FB / 50 ) / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); - if ( output_frame == L_FRAME32k ) + if ( EQ_16( output_frame, L_FRAME32k ) ) { j = L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; move16(); @@ -753,7 +764,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( i = 0; i < j; i++ ) { - t_audio[temp + i] = mult_r( t_audio[temp + i], temp2 ); + t_audio[add( temp, i )] = mult_r( t_audio[add( temp, i )], temp2 ); move16(); } } @@ -779,12 +790,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp = shl( ind1, 1 ); en_band[0] = swb_hr_env_code1_fx[temp]; move16(); - en_band[1] = swb_hr_env_code1_fx[add( temp, 1 )]; + en_band[1] = swb_hr_env_code1_fx[temp + 1]; move16(); temp = shl( ind2, 1 ); en_band[2] = swb_hr_env_code2_fx[temp]; move16(); - en_band[3] = swb_hr_env_code2_fx[add( temp, 1 )]; + en_band[3] = swb_hr_env_code2_fx[temp + 1]; move16(); /*env = add(add(shr(en_band[0], 2), shr(en_band[1], 2)), add(shr(en_band[2], 2), shr(en_band[3], 2)));*/ @@ -892,7 +903,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Nsv2 * 12 <= nBits (Nsv2 is not too high) AND */ /* nBits - Nsv2 * 12 < 12 (Nsv2 is the highest divisor) */ L_temp = L_msu0( L_deposit_l( nBits ), 12, Nsv2 ); - if ( GE_32( L_temp, 12L ) ) + if ( GE_32( L_temp, 12 ) ) Nsv2 = add( Nsv2, 1 ); if ( L_temp < 0 ) Nsv2 = sub( Nsv2, 1 ); @@ -913,7 +924,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* set 't_audio' exp */ t_audio_exp = 10; move16(); - FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) + FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { #ifdef BASOP_NOGLOB t_audio_tmp[i] = shl_sat( x_norm[i], t_audio_exp ); @@ -944,7 +955,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_temp = L_mult( gain2_fx, *ptr16++ ); L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[temp + j] = round_fx( L_temp ); + t_audio_tmp[add( temp, j )] = round_fx( L_temp ); } /* 'nq[i] = add(nq[i], nq2[incr])' replaced by 'nq[i] = nq2[incr]' because 'nq[i] == 0' */ nq[i] = nq2[incr]; @@ -968,9 +979,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < WIDTH_BAND; j++ ) { L_temp = L_mult( gain2_fx, *ptr16++ ); - L_temp = L_msu( L_temp, t_audio_tmp[temp + j], temp3 ); /* go to -Q't_audio' */ - L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[temp + j] = round_fx( L_temp ); + L_temp = L_msu( L_temp, t_audio_tmp[add( temp, j )], temp3 ); /* go to -Q't_audio' */ + L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ + t_audio_tmp[add( temp, j )] = round_fx( L_temp ); } nq[i] = add( nq[i], nq2[incr] ); move16(); @@ -989,6 +1000,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB Copy( t_audio_tmp, ptr16, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ temp4 = NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF; + move16(); } ELSE { @@ -997,12 +1009,14 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ temp4 = ind1; + move16(); temp = add( pos, 1 ); ind2 = add( shl( temp, 6 ), i_mult2( shr( temp, 1 ), WIDTH_BAND ) ); - Copy( t_audio_tmp + ind1, ptr16 + ind2, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF - ind2 ); + Copy( t_audio_tmp + ind1, ptr16 + ind2, sub( NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF, ind2 ) ); /* Update Maximum Written Location (from t_audio + NUM_NONTRANS_START_FREQ_COEF) */ temp4 = s_max( temp4, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); + move16(); /* reconstruct non-encoded subband */ IF( EQ_16( pos, 3 ) ) @@ -1030,7 +1044,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { nq[j] = nq[i]; move16(); - j = sub( j, 1 ); + j = j - 1; } Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); @@ -1069,14 +1083,14 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( EQ_16( pos, 3 ) && LE_16( nBits_total, 400 ) ) { ptr16 = &t_audio[NUM_NONTRANS_START_FREQ_COEF + 200 - WIDTH_BAND]; - L_temp = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + L_temp = L_mac0( 1 /* EPSILON */, *ptr16, *ptr16 ); FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; L_temp = L_mac0( L_temp, *ptr16, *ptr16 ); } ptr16++; - L_temp2 = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + L_temp2 = L_mac0( 1 /* EPSILON */, *ptr16, *ptr16 ); FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; @@ -1088,7 +1102,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = s_min( 0, temp ); L_temp = L_shl( L_temp, temp2 ); /* Energy_flt - i*(Energy_flt-1.0)/8.0 */ - L_temp2 = L_add( L_temp, L_shr( -2147483647L - 1L, s_max( 0, temp ) ) ); /* 1.0 in same Q as Sqrt minus the Guard */ + L_temp2 = L_add( L_temp, L_shr( -2147483647 - 1, s_max( 0, temp ) ) ); /* 1.0 in same Q as Sqrt minus the Guard */ /* / 8.0 */ L_temp2 = L_shr( L_temp2, 3 + Q_GUARD ); /* Add Guard */ @@ -1112,22 +1126,22 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB width_noncoded = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_END_FREQ_COEF; move16(); /* st->extl == FB_BWE_HIGHRATE */ test(); - if ( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( output_frame, L_FRAME32k ) ) + IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( output_frame, L_FRAME32k ) ) { width_noncoded = L_FRAME32k - NUM_NONTRANS_END_FREQ_COEF; move16(); } ptr16 = &t_audio[NUM_NONTRANS_END_FREQ_COEF - WIDTH_BAND]; - L_temp = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + L_temp = L_mac0( 1 /* EPSILON */, *ptr16, *ptr16 ); FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; L_temp = L_mac0( L_temp, *ptr16, *ptr16 ); } - ptr16 = &t_audio[sub( NUM_NONTRANS_END_FREQ_COEF, width_noncoded )]; - L_temp2 = L_mac0( 1L /* EPSILON */, *ptr16, *ptr16 ); + ptr16 = &t_audio[NUM_NONTRANS_END_FREQ_COEF - width_noncoded]; + L_temp2 = L_mac0( 1 /* EPSILON */, *ptr16, *ptr16 ); FOR( i = 1; i < WIDTH_BAND; i++ ) { ptr16++; @@ -1143,7 +1157,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB t_audio32 + NUM_NONTRANS_END_FREQ_COEF + WIDTH_BAND, sub( width_noncoded, WIDTH_BAND ) ); /* smoothing 14.4-14.8kHz */ - ptr16 = &t_audio[sub( NUM_NONTRANS_END_FREQ_COEF, width_noncoded )]; + ptr16 = &t_audio[NUM_NONTRANS_END_FREQ_COEF - width_noncoded]; ptr32 = &t_audio32[NUM_NONTRANS_END_FREQ_COEF]; temp = sub( temp, add( t_audio_exp, 16 - Q_32_BITS ) ); FOR( i = 0; i < WIDTH_BAND; i++ ) @@ -1186,7 +1200,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* in L_temp/L_temp2, value in Q16+9 */ FOR( j = 0; j < WIDTH_BAND; j++ ) { - *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), 15 - 9 ); + *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), ( 15 - 9 ) ); move32(); ptr32++; L_temp = L_sub( L_temp, L_temp2 ); @@ -1216,7 +1230,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < tmpS; j++ ) { /* t_audio[NUM_NONTRANS_END_FREQ_COEF + j] *= 2.2f * en_noncoded * (1-(float)k/(float)160); */ - *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), 31 - 23 ); + *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), ( 31 - 23 ) ); move32(); ptr32++; L_temp = L_sub( L_temp, L_temp2 ); @@ -1227,7 +1241,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( ; j < width_noncoded; j++ ) { /* t_audio[NUM_NONTRANS_END_FREQ_COEF + j] *= 0.65f * en_noncoded * (1-(float)k/(float)320); */ - *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), 31 - 25 ); + *ptr32 = L_shl( Mult_32_16( *ptr32, round_fx( L_temp ) ), ( 31 - 25 ) ); move32(); ptr32++; L_temp = L_sub( L_temp, L_temp2 ); @@ -1279,13 +1293,15 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Save transform coefficients for the next frame (needed in case of frame erasures) */ temp = NUM_NONTRANS_START_FREQ_COEF; move16(); /* not necessary but improves readability and allows a larger common code path */ - IF( output_frame == L_FRAME32k ) + IF( EQ_16( output_frame, L_FRAME32k ) ) { pos = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; + move16(); } ELSE /* output_frame == L_FRAME48k */ { pos = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF; + move16(); } temp4 = Find_Max_Norm32( t_audio32 + temp, pos ); Copy_Scale_sig32_16( t_audio32 + temp, hBWE_FD_HR->t_audio_prev_fx, pos, temp4 ); @@ -1299,7 +1315,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB j = 2 * END_FREQ_BWE_FULL_FB / 50 - NUM_NONTRANS_START_FREQ_COEF; move16(); - if ( output_frame == L_FRAME32k ) + if ( EQ_16( output_frame, L_FRAME32k ) ) { j = L_FRAME32k - NUM_NONTRANS_START_FREQ_COEF; move16(); @@ -1317,10 +1333,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB IF( gain_fx < 0 ) { st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( 32767, env ), 7 ) ); + move16(); } ELSE { st_fx->prev_ener_shb_fx = extract_h( L_shr( L_mult0( gain_fx, env ), 7 ) ); + move16(); } FOR( i = 0; i < SWB_FENV; i++ ) { @@ -1333,6 +1351,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB *---------------------------------------------------------------------*/ t_audio_exp = Q_32_BITS; + move16(); Inverse_Transform( t_audio32, &t_audio_exp, t_audio32_tmp, is_transient, output_frame, output_frame, st_fx->element_mode ); window_ola_fx( t_audio32_tmp, hb_synth_fx, &t_audio_exp, hBWE_FD->L_old_wtda_swb_fx, &st_fx->hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); @@ -1354,7 +1373,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB move16(); ptr16 = hb_synth_fx; - move16(); len = shr( output_frame, 2 ); /* Divide Frame Len by 4, all (160, 320, 640, 960) are divisible by 4 */ L_ener_all = L_deposit_l( 0 ); @@ -1365,7 +1383,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_Energy = Calc_Energy_Autoscaled( ptr16, hb_synth_fx_exp, len, &temp2 ); ptr16 += len; - move16(); /* Normalize Energy */ temp = norm_l( L_Energy ); L_Energy = L_shl( L_Energy, temp ); @@ -1414,11 +1431,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB test(); test(); test(); - IF( IsTransient != 0 && pos > 0 && LT_32( L_tilt_wb, 16777216L * 3 /*tilt_wb in Q24*/ ) && GT_16( pitch, 500 * 16 /*Q4*/ ) ) + IF( IsTransient != 0 && pos > 0 && LT_32( L_tilt_wb, 50331648 /* (16777216L * 3) */ /*tilt_wb in Q24*/ ) && GT_16( pitch, ( 500 * 16 ) /*Q4*/ ) ) { Nsv = i_mult2( pos, shr( output_frame, 2 ) ); gain_fx = 16384; /* sqrt(1.0) in Q14 */ + move16(); /* pos is 1,2 or 3 */ temp3 = sub( pos, 2 ); if ( temp3 == 0 ) @@ -1456,7 +1474,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * +1: Because of L_mult'0' * and the normalization */ - exp2 = add( exp1, +16 - 16 - 15 + 1 ); + exp2 = add( exp1, 16 - 16 - 15 + 1 ); temp = norm_l( L_temp ); L_temp = L_shl( L_temp, temp ); exp2 = add( exp2, temp ); @@ -1466,6 +1484,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB L_temp2 = L_mult( temp, hb_synth_fx[i] ); L_temp2 = L_shr( L_temp2, exp2 ); hb_synth_fx[i] = round_fx( L_temp2 ); + move16(); } len = shr( output_frame, 3 ); /* all frame length are divisible by 8 */ @@ -1484,7 +1503,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Put to Q30 */ L_temp2 = L_shr( L_temp2, exp2 ); /* 1/frame_len in Q30 */ - L_temp2 = L_msu( L_temp2, swb_hr_inv_frm_len[temp], 32768L >> ( 19 - 15 + 1 ) ); /* 19-15+1 to Bring to Q30 */ + L_temp2 = L_msu( L_temp2, swb_hr_inv_frm_len[temp], 1024 /*(32768L >> ( 19 - 15 + 1 )*/ ); /* 19-15+1 to Bring to Q30 */ FOR( i = 0; i < len; i++ ) { /* hb_synth[i+Nsv] *= (gain_flt - i*8.0f*(1.0f/output_frame*gain_flt - 1.0f/output_frame)) */ @@ -1506,7 +1525,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB test(); IF( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->last_extl, st_fx->extl ) ) { - IF( LT_32( L_tilt_wb, 16777216L * 3 /*tilt_wb in Q24*/ ) ) + IF( LT_32( L_tilt_wb, 50331648 /* (16777216L * 3) */ /*tilt_wb in Q24*/ ) ) { temp = TD_Postprocess( hb_synth_fx, hb_synth_fx_exp, output_frame, st_fx->last_extl ); @@ -1553,6 +1572,7 @@ void hr_bwe_dec_init( move16(); hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index 689029be4..52c200bc4 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -30,14 +30,14 @@ static void DecodeSWBGenericParameters_fx( { IF( EQ_16( hq_swb_clas_fx, HQ_HARMONIC ) ) { - lagIndices_fx[sb] = get_next_indice( st_fx, bits_lagIndices_mode0_Har[sb] ); + lagIndices_fx[sb] = (Word16) get_next_indice( st_fx, bits_lagIndices_mode0_Har[sb] ); move16(); } ELSE { - IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) + IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) { - lagIndices_fx[sb] = get_next_indice( st_fx, bits_lagIndices_modeNormal[sb] ); + lagIndices_fx[sb] = (Word16) get_next_indice( st_fx, bits_lagIndices_modeNormal[sb] ); move16(); } ELSE @@ -144,8 +144,7 @@ static void DecodeSWBSubbands_fx( /* Generate HF noise */ genhf_noise_fx( sspectra_diff_fx, Qss, L_xSynth_har, QsL, sspectra_fx, BANDS_fx, har_bands_fx, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow_fx, fLenHigh_fx, sbWidth_fx, lagIndices_fx, subband_offsets_fx, subband_search_offset_fx ); - imin_fx = get_next_indice( st_fx, 2 ); - move16(); + imin_fx = (Word16) get_next_indice( st_fx, 2 ); /* g= pow(10.0f, gain_table_SWB_BWE[imin]) */ L_temp = L_mult( gain_table_SWB_BWE_fx[imin_fx], 27213 ); /* Q14+Q13+1=Q28 log(10)/log(2)=3.3219 27213.23(Q13) */ L_temp = L_shr( L_temp, 12 ); /* Q28-Q12 -> Q16 */ @@ -180,12 +179,12 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; + L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; move32(); /* QsL */ } } } - ELSE IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + ELSE IF( hqswb_clas_fx == HQ_NORMAL ) { ss_min_fx = spectrumsmooth_noiseton_fx( L_spectra, /*QsL,*/ L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, &Qss, fLenLow_fx, ni_seed_fx ); @@ -193,7 +192,7 @@ static void DecodeSWBSubbands_fx( convert_lagIndices_pls2smp_fx( lagIndices_fx, nBands_fx, lagIndices_real_fx, sspectra_fx, sbWidth_fx, fLenLow_fx ); FOR( k = 0; k < nBands_fx; k++ ) { - if ( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) + if ( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) { lagIndices_real_fx[k] = 0; move16(); @@ -201,12 +200,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[BANDS_fx - NB_SWB_SUBBANDS], Qbe, + &L_band_energy[sub( BANDS_fx, NB_SWB_SUBBANDS )], Qbe, nBands_fx, sbWidth_fx, lagIndices_real_fx, fLenLow_fx, lagGains_fx, QlagGains ); FOR( k = 0; k < nBands_fx; k++ ) { - IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) + IF( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) { lagGains_fx[k] = 0; move16(); @@ -216,15 +215,18 @@ static void DecodeSWBSubbands_fx( ELSE { lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + move16(); } } FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { - L_th_g[k] = L_deposit_l( 0 ); - IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) + L_th_g[k] = 0; + move32(); + IF( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> Qs */ + move32(); } } @@ -242,7 +244,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; + L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; move32(); /* QsL */ } } @@ -313,7 +315,7 @@ void swb_bwe_dec_lr_fx( DecodeSWBGenericParameters_fx( st_fx, lagIndices_fx, nBands_search_fx, BANDS_fx, p2a_flags_fx, hqswb_clas_fx ); /* Copy WB synthesis for SWB decoding */ - Copy32( L_m_core, L_m, swb_lowband_fx + swb_highband_fx ); + Copy32( L_m_core, L_m, add( swb_lowband_fx, swb_highband_fx ) ); /* Generic subband processing */ DecodeSWBSubbands_fx( st_fx, st_fx->hHQ_core, L_m, QsL, swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, @@ -321,7 +323,7 @@ void swb_bwe_dec_lr_fx( L_band_energy, Qbe, p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, prev_frm_hfe2, prev_stab_hfe2, band_width_fx, L_y2_ni, ni_seed_fx ); - p_L_m = &L_m[sub( allband_fx, 1 )]; + p_L_m = &L_m[allband_fx - 1]; *p_L_m = Mult_32_16( *p_L_m, 2028 ); move32(); p_L_m--; /* 0.0625 = 2028 (Q15) */ @@ -339,6 +341,7 @@ void swb_bwe_dec_lr_fx( FOR( k = 0; k < swb_lowband_fx; k++ ) { L_m[k] = L_deposit_l( 0 ); + move32(); } return; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 70c57bff2..2b1bd7f63 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -468,54 +468,72 @@ static void calc_tilt_bwe_fx_loc( Word64 r0_fx, r1_fx; r0_fx = EPSILON_FX_SMALL; + move64(); FOR( i = 0; i < N; i++ ) { - r0_fx += ( (Word64) sp_fx[i] ) * ( sp_fx[i] ); + r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); } - r1_fx = abs( sp_fx[1] - sp_fx[0] ); + r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); FOR( i = 2; i < N; i++ ) { - IF( ( (Word64) ( sp_fx[i] - sp_fx[i - 1] ) ) * ( sp_fx[i - 1] - sp_fx[i - 2] ) < 0 ) + IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ), L_sub( sp_fx[i - 1], sp_fx[i - 2] ) ) < 0 ) { - r1_fx += abs( sp_fx[i] - sp_fx[i - 1] ); + r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); } } Word16 headroom_left_r0 = W_norm( r0_fx ); Word16 headroom_left_r1 = W_norm( r1_fx ); Word16 r0_q = 0, r1_q = 0; + move16(); + move16(); // Word16 r0_bits_occ = 0, r1_bits_occ = 0; - IF( headroom_left_r0 < 32 ) + IF( LT_16( headroom_left_r0, 32 ) ) { - r0_fx = W_shr( r0_fx, ( 32 - headroom_left_r0 ) ); - r0_q = ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_r0 ) ) ); + r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) ); + r0_q = sub( 31, sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_r0 ) ) ); } ELSE { r0_q = 31 - ( 2 * OUTPUT_Q ); + move16(); } - IF( headroom_left_r1 < 32 ) + IF( LT_16( headroom_left_r1, 32 ) ) { - r1_fx = W_shr( r1_fx, ( 32 - headroom_left_r1 ) ); - r1_q = ( OUTPUT_Q - ( 32 - headroom_left_r1 ) ); + r1_fx = W_shr( r1_fx, sub( 32, headroom_left_r1 ) ); + r1_q = sub( OUTPUT_Q, sub( 32, headroom_left_r1 ) ); } ELSE { r1_q = OUTPUT_Q; + move16(); + } + Word32 temp_r0_inv = ISqrt32( W_extract_l( r0_fx ), &r0_q ); + Word32 res = Mpy_32_32( W_extract_l( r1_fx ), temp_r0_inv ); + // Word16 res_q = r1_q + ( r0_q < 0 ? ( 31 + ( -1 * r0_q ) ) : r0_q ) - 31; + Word16 res_q; + IF( r0_q < 0 ) + { + res_q = add( r1_q, sub( add( 31, -r0_q ), 31 ) ); + } + ELSE + { + res_q = add( r1_q, sub( r0_q, 31 ) ); } - Word32 temp_r0_inv = ISqrt32( (Word32) r0_fx, &r0_q ); - Word32 res = Mpy_32_32( (Word32) r1_fx, temp_r0_inv ); - Word16 res_q = r1_q + ( r0_q < 0 ? ( 31 + ( -1 * r0_q ) ) : r0_q ) - 31; Word16 norm_res = norm_l( res ); IF( norm_res > 0 ) { *tilt_fx = L_shl_sat( res, norm_res ); - *tilt_fx_q = res_q + norm_res; + move32(); + *tilt_fx_q = add( res_q, norm_res ); + move16(); } ELSE { *tilt_fx = res; + move32(); *tilt_fx_q = res_q; + move16(); } return; } @@ -561,7 +579,7 @@ static void rescale_genSHB_mem_dec( } } - IF( EQ_16( st_fx->extl, FB_TBE ) ) + if ( EQ_16( st_fx->extl, FB_TBE ) ) { } hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); @@ -619,7 +637,7 @@ static void gradientGainShape( /* get the first gainshape template */ test(); test(); - IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && GainGradFEC[0] > 0 ) + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) { GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), GainGradFEC[0] ); move16(); @@ -641,7 +659,7 @@ static void gradientGainShape( tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] > 0 ) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) ) { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -654,7 +672,7 @@ static void gradientGainShape( ELSE { test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] < 0 ) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) ) { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -680,7 +698,7 @@ static void gradientGainShape( test(); test(); test(); - IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && st_fx->nbLostCmpt == 1 ) + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -690,19 +708,20 @@ static void gradientGainShape( IF( GT_16( 8192, tmp ) ) { - GainShape_fx[i * 4 + j] = shl( tmp, 2 ); + GainShape_fx[add( i * 4, j )] = shl( tmp, 2 ); move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape_fx[i * 4 + j] = 32767; + GainShape_fx[add( i * 4, j )] = 32767; move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); } - ELSE IF( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) + ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -710,29 +729,31 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - GainShape_fx[i * 4 + j] = 32767; + GainShape_fx[add( i * 4, j )] = 32767; move16(); } } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); } - ELSE IF( st_fx->nbLostCmpt > 1 ) + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[i * 4 + j] = GainShapeTemp[i]; + GainShape_fx[add( i * 4, j )] = GainShapeTemp[i]; move16(); } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + move16(); } ELSE { @@ -742,20 +763,22 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - GainShape_fx[i * 4 + j] = 32767; + GainShape_fx[add( i * 4, j )] = 32767; move16(); } } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + move16(); } *GainFrame_fx = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ + move32(); } static void find_max_mem_dec( @@ -767,8 +790,11 @@ static void find_max_mem_dec( Word16 i; Word16 n_mem_32; Word16 max = 0; + move16(); Word32 Lmax = 0; + move32(); Word16 tempQ15, max2 = 0; + move16(); Word16 max3; Word32 tempQ32, Lmax3; TD_BWE_DEC_HANDLE hBWE_TD; @@ -813,9 +839,14 @@ static void find_max_mem_dec( /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ *n_mem2 = norm_s( max2 ); - IF( max2 == 0 ) *n_mem2 = 15; + move16(); + if ( max2 == 0 ) + { + *n_mem2 = 15; + move16(); + } - IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) + if ( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { max = s_max( max, max2 ); } @@ -840,22 +871,26 @@ static void find_max_mem_dec( } /* estimate the norm for 16-bit memories */ *n_mem = norm_s( max ); - IF( max == 0 ) + move16(); + if ( max == 0 ) { *n_mem = 15; + move16(); } /* estimate the norm for 32-bit memories */ Lmax = L_abs( hBWE_TD->mem_csfilt_fx[0] ); /* only element [0] is used in env. shaping */ n_mem_32 = norm_l( Lmax ); - IF( Lmax == 0 ) + if ( Lmax == 0 ) { n_mem_32 = 31; + move16(); } tempQ15 = sub( s_min( *n_mem, n_mem_32 ), 1 ); *n_mem = s_max( tempQ15, 0 ); + move16(); /* --------------------------------------------------------------*/ /* Find headroom for synthesis stage associated with these memories: @@ -863,6 +898,7 @@ static void find_max_mem_dec( 2. st_fx->genSHBsynth_state_lsyn_filt_shb_local 3. st_fx->genSHBsynth_Hilbert_Mem_fx (32-bit) */ max3 = 0; + move16(); /* find max in prev overlapSyn */ FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { @@ -894,9 +930,15 @@ static void find_max_mem_dec( } /* estimate the norm for 16-bit memories */ *n_mem3 = norm_s( max3 ); - IF( max3 == 0 ) *n_mem3 = 15; + move16(); + if ( max3 == 0 ) + { + *n_mem3 = 15; + move16(); + } Lmax3 = 0; + move32(); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* find max in prev genSHBsynth_Hilbert_Mem_fx */ @@ -909,12 +951,16 @@ static void find_max_mem_dec( /* estimate the norm for 32-bit memories */ n_mem_32 = norm_l( Lmax3 ); - IF( Lmax3 == 0 ) - n_mem_32 = 31; + if ( Lmax3 == 0 ) + { + n_mem_32 = 31; + move16(); + } tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); + move16(); /* --------------------------------------------------------------*/ } #endif // IVAS_FLOAT_FIXED @@ -935,6 +981,7 @@ void find_max_mem_dec_m3( /* Find headroom for synthesis stage associated with these memories: 1. st->syn_overlap_fx*/ max3 = 0; + move16(); /* find max in prev overlapSyn */ FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { @@ -966,7 +1013,12 @@ void find_max_mem_dec_m3( // } /* estimate the norm for 16-bit memories */ *n_mem3 = norm_s( max3 ); - IF( max3 == 0 ) *n_mem3 = 15; + move16(); + if ( max3 == 0 ) + { + *n_mem3 = 15; + move16(); + } // Lmax3 = 0; // IF(EQ_16(st->L_frame, L_FRAME)) @@ -1080,7 +1132,7 @@ void ivas_swb_tbe_dec_fx( shb_ener_sf_32 = 0; move32(); set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); - IF( st->hTdCngDec != NULL ) + if ( st->hTdCngDec != NULL ) { st->hTdCngDec->shb_dtx_count = 0; move16(); @@ -1105,16 +1157,19 @@ void ivas_swb_tbe_dec_fx( /* find tilt */ calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); - tilt_swb_fec_fx = extract_l( L_shr( tilt_swb_fec_32_fx, ( tilt_swb_fec_fx_q - 11 ) ) ); + tilt_swb_fec_fx = extract_l( L_shr( tilt_swb_fec_32_fx, sub( tilt_swb_fec_fx_q, 11 ) ) ); - IF( st->bfi && st->clas_dec != UNVOICED_CLAS ) + test(); + if ( st->bfi && st->clas_dec != UNVOICED_CLAS ) { tilt_swb_fec_fx = hBWE_TD->tilt_swb_fec_fx; move16(); } /* WB/SWB bandwidth switching */ - IF( ( st->tilt_wb_fx > 10240 && st->clas_dec == UNVOICED_CLAS ) || st->tilt_wb_fx > 20480 ) + test(); + test(); + IF( ( GT_16( st->tilt_wb_fx, 10240 ) && ( st->clas_dec == UNVOICED_CLAS ) ) || GT_16( st->tilt_wb_fx, 20480 ) ) { test(); test(); @@ -1123,7 +1178,8 @@ void ivas_swb_tbe_dec_fx( test(); test(); test(); - IF( ( st->prev_fractive == 0 && + test(); + IF( ( ( st->prev_fractive == 0 ) && ( LT_32( st->prev_enerLH_fx, L_shl( st->enerLH_fx, 1 ) ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) && LT_32( st->prev_enerLL_fx, L_shl( st->enerLL_fx, 1 ) ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) ) || ( EQ_16( st->prev_fractive, 1 ) && GT_32( L_shr( st->prev_enerLH_fx, 2 ), Mult_32_16( st->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ @@ -1149,7 +1205,7 @@ void ivas_swb_tbe_dec_fx( inc_fx = 1489; /*Q15*/ move16(); - IF( is_fractive == 1 ) + IF( EQ_16( is_fractive, 1 ) ) { Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); } @@ -1162,13 +1218,20 @@ void ivas_swb_tbe_dec_fx( f_fx = add( f_fx, inc_fx ); } } - IF( ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE && !( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 && L_sub( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) || st->last_core != ACELP_CORE || ( st->last_core == ACELP_CORE && labs( st->last_core_brate - st->core_brate ) > 3600 ) || ( is_fractive ^ st->prev_fractive ) == 1 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) ) { set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); } ELSE { - IF( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) { hBWE_TD->prev_GainShape_fx = 11587; move16(); @@ -1181,7 +1244,8 @@ void ivas_swb_tbe_dec_fx( } ELSE { - IF( st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) + test(); + IF( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) { f_fx = 1489; /*Q15*/ move16(); @@ -1199,7 +1263,7 @@ void ivas_swb_tbe_dec_fx( { IF( st->use_partial_copy ) { - IF( st->last_extl != SWB_TBE ) + IF( NE_16( st->last_extl, SWB_TBE ) ) { hBWE_TD->GainFrame_prevfrm_fx = 0; move32(); @@ -1217,7 +1281,7 @@ void ivas_swb_tbe_dec_fx( Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); set16_fx( GainShape_fx, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); - IF( st->rf_frame_type == RF_NELP ) + IF( EQ_16( st->rf_frame_type, RF_NELP ) ) { /* Frame gain */ @@ -1228,7 +1292,13 @@ void ivas_swb_tbe_dec_fx( L_tmp = Pow2( 30, frac ); GainFrame_fx = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - IF( st->core == ACELP_CORE && st->last_core == ACELP_CORE && !st->prev_use_partial_copy && st->prev_coder_type == UNVOICED && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && st->next_coder_type != GENERIC && st->last_extl == SWB_TBE ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) ) { GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6553 ) ); } @@ -1243,33 +1313,41 @@ void ivas_swb_tbe_dec_fx( case 0: GainFrame_fx = 131072; /* 0.5f in Q18 */ move32(); - IF( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - temp_fx = 26214 /*0.8 Q15*/; - move16(); + if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) + { + temp_fx = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 1: GainFrame_fx = 524288; /* 2.0f in Q18 */ move32(); - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - temp_fx = 26214 /*0.8 Q15*/; - move16(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) + { + temp_fx = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 2: GainFrame_fx = 1048576; /* 4.0f in Q18 */ move32(); - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - temp_fx = 26214 /*0.8 Q15*/; - move16(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) + { + temp_fx = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 3: GainFrame_fx = 2097152; /* 8.0f in Q18 */ move32(); - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) - temp_fx = 26214 /*0.8 Q15*/; - move16(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) + { + temp_fx = 26214 /*0.8 Q15*/; + move16(); + } BREAK; default: fprintf( stderr, "RF SWB-TBE gain bits not supported." ); @@ -1280,9 +1358,9 @@ void ivas_swb_tbe_dec_fx( GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) ); } - IF( st->core == ACELP_CORE && st->last_core == ACELP_CORE ) + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) ) { - IF( !st->prev_use_partial_copy && st->last_coder_type == VOICED && st->rf_frame_type == RF_GENPRED && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) + if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) { GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 ); } @@ -1294,7 +1372,7 @@ void ivas_swb_tbe_dec_fx( /* de-quantization */ ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); - IF( hStereoICBWE != NULL ) + if ( hStereoICBWE != NULL ) { hStereoICBWE->MSFlag = MSFlag; move16(); @@ -1304,8 +1382,8 @@ void ivas_swb_tbe_dec_fx( ELSE { Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); - - IF( st->codec_mode == MODE1 && st->element_mode == EVS_MONO ) + test(); + IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) ) { gradientGainShape( st, GainShape_fx, &GainFrame_fx ); } @@ -1315,11 +1393,11 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[add( i * 4, j )] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); move16(); } } - IF( GT_16( tilt_swb_fec_fx, 8 << 11 ) ) /* tilt_swb_fec_fx in Q11 */ + IF( GT_16( tilt_swb_fec_fx, ( 8 << 11 ) ) ) /* tilt_swb_fec_fx in Q11 */ { IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1342,9 +1420,10 @@ void ivas_swb_tbe_dec_fx( } } - IF( st->extl_brate >= SWB_TBE_2k8 ) + IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) ) { - IF( st->codec_mode == MODE1 && st->element_mode == EVS_MONO ) + test(); + IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) ) { L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ @@ -1361,19 +1440,19 @@ void ivas_swb_tbe_dec_fx( scale_fx = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ scale_fx = s_max( scale_fx, 0 ); #ifdef BASOP_NOGLOB - tmp = shl_sat( scale_fx, 15 - exp - i ); /*Q15*/ + tmp = shl_sat( scale_fx, sub( sub( 15, exp ), i ) ); /*Q15*/ #else tmp = shl( scale, 15 - exp - i ); /*Q15*/ #endif } scale_fx = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ - + test(); IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) { shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale_fx ); - IF( GT_16( st->nbLostCmpt, 1 ) ) + if ( GT_16( st->nbLostCmpt, 1 ) ) { shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); } @@ -1386,6 +1465,7 @@ void ivas_swb_tbe_dec_fx( } ELSE { + test(); IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) { @@ -1428,6 +1508,7 @@ void ivas_swb_tbe_dec_fx( Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); + test(); IF( EQ_16( st->coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) @@ -1445,6 +1526,7 @@ void ivas_swb_tbe_dec_fx( } } + test(); IF( st->use_partial_copy && st->nelp_mode_dec ) { set16_fx( vf_modified_fx, 0, NB_SUBFR16k ); @@ -1453,7 +1535,8 @@ void ivas_swb_tbe_dec_fx( /* SHB LSF from current frame; and convert to LSP for interpolation */ E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); - IF( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) + test(); + IF( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) { /* SHB LSP values from prev. frame for interpolation */ Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); @@ -1464,15 +1547,18 @@ void ivas_swb_tbe_dec_fx( Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - IF( st->bws_cnt == 0 && st->bws_cnt1 == 0 && st->prev_use_partial_copy == 0 && st->use_partial_copy == 0 ) + test(); + test(); + test(); + IF( ( st->bws_cnt == 0 ) && ( st->bws_cnt1 == 0 ) && ( st->prev_use_partial_copy == 0 ) && ( st->use_partial_copy == 0 ) ) { lsf_diff_fx[0] = 16384; move16(); /*Q15*/ - lsf_diff_fx[sub( LPC_SHB_ORDER, 1 )] = 16384; + lsf_diff_fx[LPC_SHB_ORDER - 1] = 16384; move16(); /*Q15*/ FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); + lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); move16(); } @@ -1483,7 +1569,8 @@ void ivas_swb_tbe_dec_fx( tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ tilt_para_fx = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - IF( st->last_extl != SWB_TBE && st->last_extl != FB_TBE ) + test(); + IF( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) { FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { @@ -1492,8 +1579,13 @@ void ivas_swb_tbe_dec_fx( } } - IF( st->extl_brate <= FB_TBE_1k8 ) + IF( LE_32( st->extl_brate, FB_TBE_1k8 ) ) { + test(); + test(); + test(); + test(); + test(); IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( st->coder_type, TRANSITION ) || LT_16( tilt_para_fx, 1024 ) ) ) && !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para_fx, 5120 ) ) ) { @@ -1504,7 +1596,7 @@ void ivas_swb_tbe_dec_fx( tmp = mult( 26214, lsf_diff_fx[i] ); test(); - IF( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ { st->BER_detect = 1; move16(); @@ -1525,7 +1617,7 @@ void ivas_swb_tbe_dec_fx( tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); test(); - IF( lsf_diff_fx[i] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF( ( lsf_diff_fx[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ { st->BER_detect = 1; move16(); @@ -1544,7 +1636,7 @@ void ivas_swb_tbe_dec_fx( } w_fx[0] = w_fx[1]; move16(); - w_fx[sub( LPC_SHB_ORDER, 1 )] = w_fx[sub( LPC_SHB_ORDER, 2 )]; + w_fx[LPC_SHB_ORDER - 1] = w_fx[LPC_SHB_ORDER - 2]; move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -1566,13 +1658,14 @@ void ivas_swb_tbe_dec_fx( Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = tilt_para_fx; + move16(); } ELSE { Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); } - IF( st->extl_brate >= SWB_TBE_2k8 ) + IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) ) { /* SHB LSP interpolation */ ptr_lsp_interp_coef_fx = interpol_frac_shb; /*Q15*/ @@ -1591,7 +1684,8 @@ void ivas_swb_tbe_dec_fx( E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); /* Bring the LPCs to Q12 */ Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); - lpc_shb_sf_fx[j * ( LPC_SHB_ORDER + 1 )] = ONE_IN_Q12; // recheck this + lpc_shb_sf_fx[i_mult( j, ( LPC_SHB_ORDER + 1 ) )] = ONE_IN_Q12; // recheck this + move16(); } } @@ -1623,10 +1717,11 @@ void ivas_swb_tbe_dec_fx( lpc_shb_fx[0] = ONE_IN_Q12; move16(); - IF( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 ) + test(); + IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) { - Word32 vind_temp = ( L_add( mixFactors_fx, 1 ) * ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) ); // check addition of 1 - vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ + Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 + vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ /* i: mixFactors_fx in Q15 */ /* o: vind in Q0 */ } @@ -1640,11 +1735,11 @@ void ivas_swb_tbe_dec_fx( /* Determine formant PF strength */ formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - IF( st->total_brate > ACELP_32k ) + IF( GT_32( st->total_brate, ACELP_32k ) ) { FOR( j = 0; j < 4; j++ ) { - Copy( lpc_shb_fx, &lpc_shb_sf_fx[j * ( LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); + Copy( lpc_shb_fx, &lpc_shb_sf_fx[i_mult( j, ( LPC_SHB_ORDER + 1 ) )], LPC_SHB_ORDER + 1 ); } } @@ -1659,7 +1754,7 @@ void ivas_swb_tbe_dec_fx( Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) ); } Q_bwe_exc = norm_l( Lmax ); - IF( Lmax == 0 ) + if ( Lmax == 0 ) { Q_bwe_exc = 31; move16(); @@ -1668,7 +1763,7 @@ void ivas_swb_tbe_dec_fx( find_max_mem_dec( st, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ tmp = add( st->prev_Q_bwe_exc, n_mem ); - IF( GT_16( Q_bwe_exc, tmp ) ) + if ( GT_16( Q_bwe_exc, tmp ) ) { Q_bwe_exc = tmp; move16(); @@ -1691,6 +1786,7 @@ void ivas_swb_tbe_dec_fx( #else bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); #endif + move16(); } /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ @@ -1738,12 +1834,14 @@ void ivas_swb_tbe_dec_fx( /* rescale the TBE post proc memory */ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], Q_bwe_exc - st->prev_Q_bwe_syn ); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st->prev_Q_bwe_syn ) ); move16(); } #endif /* fill-in missing SHB excitation */ - IF( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 ) + test(); + test(); + IF( ( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) && LE_32( st->last_core_brate, SID_2k40 ) ) { Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, shaped_shb_excitation_fx, L_SHB_LAHEAD ); } @@ -1753,7 +1851,8 @@ void ivas_swb_tbe_dec_fx( Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k ); } - IF( st->extl_brate != SWB_TBE_1k10 && st->extl_brate != SWB_TBE_1k75 ) + test(); + IF( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) { FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { @@ -1783,7 +1882,7 @@ void ivas_swb_tbe_dec_fx( #endif } - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) { curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* Q(2*Q_bwe_exc) */ } @@ -1804,6 +1903,7 @@ void ivas_swb_tbe_dec_fx( { Lscale = L_shl( Lscale, exp ); exp = 0; + move16(); } FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { @@ -1833,6 +1933,7 @@ void ivas_swb_tbe_dec_fx( /* Update SHB excitation */ Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ l_subframe = L_FRAME16k / NUM_SHB_SUBGAINS; + move16(); L_ener = EPSILON_FX_SMALL; move32(); @@ -1847,7 +1948,7 @@ void ivas_swb_tbe_dec_fx( move64(); FOR( j = 0; j < l_subframe; j++ ) { - tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation_fx[i * l_subframe + j], shaped_shb_excitation_fx[i * l_subframe + j] ); /* 2*Q_bwe_exc */ + tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation_fx[add( i_mult( i, l_subframe ), j )], shaped_shb_excitation_fx[add( i_mult( i, l_subframe ), j )] ); /* 2*Q_bwe_exc */ } L_tmp = W_sat_l( tmp64 ); @@ -1856,7 +1957,7 @@ void ivas_swb_tbe_dec_fx( { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - ( 2 * Q_bwe_exc ) ); + exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); @@ -1890,7 +1991,7 @@ void ivas_swb_tbe_dec_fx( move16(); } test(); - IF( st->prev_fractive == 1 && GT_16( st->tilt_wb_fx, 1024 ) ) + if ( EQ_16( st->prev_fractive, 1 ) && GT_16( st->tilt_wb_fx, 1024 ) ) { st->tilt_wb_fx = 1024; move16(); @@ -1914,6 +2015,7 @@ void ivas_swb_tbe_dec_fx( ELSE { st->tilt_wb_fx = shl( st->tilt_wb_fx, 2 ); + move16(); } } @@ -1932,6 +2034,7 @@ void ivas_swb_tbe_dec_fx( #else st->tilt_wb_fx = extract_h( L_shr( Mult_32_16( st->enerLH_fx, inv_ener ), sub( sub( st->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ #endif + move16(); /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ } ELSE IF( LT_32( L_tmp, Mult_32_16( st->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) @@ -1941,6 +2044,7 @@ void ivas_swb_tbe_dec_fx( #else st->tilt_wb_fx = extract_h( L_shr( Mult_32_16( st->enerLH_fx, inv_ener ), sub( sub( st->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ #endif + move16(); /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ @@ -1954,11 +2058,11 @@ void ivas_swb_tbe_dec_fx( IF( EQ_16( is_fractive, 1 ) ) { - GainFrame_fx = L_shl( (Word32) st->tilt_wb_fx, 10 ); + GainFrame_fx = L_shl( L_deposit_l( st->tilt_wb_fx ), 10 ); } ELSE { - GainFrame_fx = L_shl( (Word32) st->tilt_wb_fx, 8 ); + GainFrame_fx = L_shl( L_deposit_l( st->tilt_wb_fx ), 8 ); } test(); @@ -1972,14 +2076,14 @@ void ivas_swb_tbe_dec_fx( test(); test(); test(); - IF( ( LT_32( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st->prev_enerLL_fx, 1 ), st->enerLL_fx ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) && ( is_fractive ^ st->prev_fractive ) == 0 ) + IF( ( LT_32( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) && GT_32( st->prev_enerLH_fx, L_shr( st->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st->prev_enerLL_fx, 1 ), st->enerLL_fx ) && GT_32( st->prev_enerLL_fx, L_shr( st->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st->prev_fractive ) == 0 ) ) { GainFrame_fx = L_add( L_shr( GainFrame_fx, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); } ELSE { test(); - IF( is_fractive == 0 && EQ_16( st->prev_fractive, 1 ) ) + IF( ( is_fractive == 0 ) && EQ_16( st->prev_fractive, 1 ) ) { L_tmp1 = L_shl( Mult_32_16( GainFrame_fx, 3277 ), 13 ); /* 31 */ L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ @@ -2009,9 +2113,19 @@ void ivas_swb_tbe_dec_fx( prev_ener_ratio_fx = L_shr( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */ } - IF( st->nbLostCmpt == 1 ) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { - IF( NE_16( st->clas_dec, UNVOICED_CLAS ) && NE_16( st->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->clas_dec != UNVOICED_CLAS ) && NE_16( st->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && ( ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st->enerLL_fx, 1 ), st->prev_enerLL_fx ) ) || ( GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st->enerLH_fx, 1 ), st->prev_enerLH_fx ) ) ) ) { IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) ) /*18*/ @@ -2028,7 +2142,7 @@ void ivas_swb_tbe_dec_fx( } test(); - IF( GT_16( tilt_swb_fec_fx, hBWE_TD->tilt_swb_fec_fx ) && hBWE_TD->tilt_swb_fec_fx > 0 ) + IF( GT_16( tilt_swb_fec_fx, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) { exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ @@ -2037,14 +2151,22 @@ void ivas_swb_tbe_dec_fx( GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } } - ELSE IF( ( NE_16( st->clas_dec, UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && + ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) { GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); } } - ELSE IF( st->nbLostCmpt > 1 ) + ELSE IF( GT_16( st->nbLostCmpt, 1 ) ) { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) ) { test(); @@ -2077,7 +2199,7 @@ void ivas_swb_tbe_dec_fx( /* Adjust the subframe and frame gain of the synthesized shb signal */ /* Scale the shaped excitation */ - IF( st->L_frame == L_FRAME ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { L_tmp = L_mult( pitch_buf_fx[0], 8192 ); FOR( i = 1; i < NB_SUBFR; i++ ) @@ -2096,11 +2218,23 @@ void ivas_swb_tbe_dec_fx( pitch_fx = round_fx( L_tmp ); /* Q6 */ } - IF( ( ( st->extl_brate >= SWB_TBE_2k8 && st->prev_coder_type == st->coder_type && st->coder_type != UNVOICED ) || ( st->extl_brate < SWB_TBE_2k8 && ( st->prev_coder_type == st->coder_type || ( st->prev_coder_type == VOICED && st->coder_type == GENERIC ) || ( st->prev_coder_type == GENERIC && st->coder_type == VOICED ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && st->extl < FB_TBE && st->extl_brate != SWB_TBE_1k10 && st->extl_brate != SWB_TBE_1k75 ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( GE_32( st->extl_brate, SWB_TBE_2k8 ) && EQ_16( st->prev_coder_type, st->coder_type ) && NE_16( st->coder_type, UNVOICED ) ) || ( LT_32( st->extl_brate, SWB_TBE_2k8 ) && ( EQ_16( st->prev_coder_type, st->coder_type ) || ( EQ_16( st->prev_coder_type, VOICED ) && EQ_16( st->coder_type, GENERIC ) ) || ( EQ_16( st->prev_coder_type, GENERIC ) && EQ_16( st->coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st->extl, FB_TBE ) && NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - GainShape_tmp_fx[i] = GainShape_fx[shl( i, 2 )]; /* Q15 */ + GainShape_tmp_fx[i] = GainShape_fx[i * 4]; /* Q15 */ move16(); } @@ -2118,7 +2252,7 @@ void ivas_swb_tbe_dec_fx( { L_tmp = L_tmp2; move32(); - IF( L_tmp2 < 0 ) + if ( L_tmp2 < 0 ) { L_tmp = L_negate( L_tmp2 ); } @@ -2129,11 +2263,11 @@ void ivas_swb_tbe_dec_fx( #else fracb = round_fx( L_shl( L_tmp, expb ) ); #endif - expb = 30 - expb; /* - (2*Q_bwe_exc_ext); */ + expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ expa = norm_l( ener_tmp_fx[i] ); fraca = extract_h( L_shl( ener_tmp_fx[i], expa ) ); - expa = 30 - expa; + expa = sub( 30, expa ); scale_fx = shr( sub( fraca, fracb ), 15 ); fracb = shl( fracb, scale_fx ); @@ -2156,7 +2290,13 @@ void ivas_swb_tbe_dec_fx( FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) { - GainShape_fx[i] = GainShape_tmp_fx[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + GainShape_fx[i] = GainShape_tmp_fx[idx]; move16(); } } @@ -2170,7 +2310,8 @@ void ivas_swb_tbe_dec_fx( /* Gain shape smoothing after quantization */ - IF( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 ) + test(); + IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -2180,37 +2321,47 @@ void ivas_swb_tbe_dec_fx( lls_interp_n_fx( GainShape_tmp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp_fx, 1 ); - IF( vind >= 6 && abs( GainShape_tilt_fx ) < 3932 ) + test(); + IF( GE_16( vind, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 ) ) { feedback_fx = 9830; move16(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - GainShape_fx[i] = add_sat( mult( ( 32767 - feedback_fx ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), mult( feedback_fx, GainShape_tmp_fx[i] ) ); + GainShape_fx[i] = add_sat( mult( sub( 32767, feedback_fx ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), mult( feedback_fx, GainShape_tmp_fx[i] ) ); move16(); } FOR( i = NUM_SHB_SUBFR - 1; i > 0; i-- ) { - GainShape_fx[i] = GainShape_fx[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + GainShape_fx[i] = GainShape_fx[idx]; move16(); } } } /* fil-in missing memory */ - IF( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 ) + test(); + test(); + IF( ( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) && LE_32( st->last_core_brate, SID_2k40 ) ) { FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { Word16 intermediate = mult( shaped_shb_excitation_fx[i], subwin_shb_fx[L_SHB_LAHEAD - i] ); Word32 intermediate_32 = Mpy_32_16_1( Mpy_32_16_1( GainFrame_fx, window_shb_fx[L_SHB_LAHEAD - 1 - i] ), intermediate ); - hBWE_TD->syn_overlap_fx[i] = (Word16) round_fx( L_shl_sat( intermediate_32, 16 - ( Q_bwe_exc + 18 - 15 ) ) ); + hBWE_TD->syn_overlap_fx[i] = round_fx( L_shl_sat( intermediate_32, sub( 16, ( add( Q_bwe_exc, 18 - 15 ) ) ) ) ); move16(); } } Word16 n_mem3_new = 0; + move16(); find_max_mem_dec_m3( st, &n_mem3_new ); ScaleShapedSHB_fx( SHB_OVERLAP_LEN, @@ -2233,6 +2384,7 @@ void ivas_swb_tbe_dec_fx( } max_val = 0; + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { max_val = s_max( max_val, shaped_shb_excitation_fx[i] ); /* Q0 */ @@ -2275,10 +2427,12 @@ void ivas_swb_tbe_dec_fx( IF( GT_16( tmp, 32 ) ) { st->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); + move16(); tmp = 32; move16(); } hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); + move32(); st->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } @@ -2294,18 +2448,21 @@ void ivas_swb_tbe_dec_fx( curr_frame_pow_exp = st->prev_frame_pow_exp; move16(); } - + test(); + test(); IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) ) { + test(); + test(); IF( ( GT_32( L_shr( curr_frame_pow_fx, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st->prev_coder_type, UNVOICED ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); scale_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp_fx = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ } ELSE @@ -2319,11 +2476,11 @@ void ivas_swb_tbe_dec_fx( { GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx ); move16(); - GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx ); + GainShape_fx[add( 2 * j, 1 )] = mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { - shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ); + shaped_shb_excitation_fx[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation_fx[add( i, j * ( L_FRAME16k / 8 ) )], scale_fx ); move16(); } @@ -2355,7 +2512,7 @@ void ivas_swb_tbe_dec_fx( scale_fx = temp_fx = 4096; move16(); /*Q12*/ move16(); - IF( st->nbLostCmpt == 1 ) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { test(); test(); @@ -2367,18 +2524,18 @@ void ivas_swb_tbe_dec_fx( test(); IF( GT_32( curr_frame_pow_fx, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && NE_16( st->prev_coder_type, UNVOICED ) && - NE_16( st->last_good, UNVOICED_CLAS ) ) + ( st->last_good != UNVOICED_CLAS ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); /*31 - exp*/ scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } ELSE IF( LT_32( curr_frame_pow_fx, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st->nbLostCmpt, 1 ) && ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st->prev_coder_type, UNVOICED ) || EQ_16( st->last_good, UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + ( EQ_16( st->prev_coder_type, UNVOICED ) || ( st->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); #ifdef BASOP_NOGLOB @@ -2386,21 +2543,26 @@ void ivas_swb_tbe_dec_fx( #else scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #endif - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } - ELSE IF( st->nbLostCmpt > 1 ) + ELSE IF( GT_16( st->nbLostCmpt, 1 ) ) { + test(); + test(); + test(); + test(); + test(); IF( GT_32( curr_frame_pow_fx, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); #ifdef BASOP_NOGLOB temp_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #else @@ -2409,18 +2571,18 @@ void ivas_swb_tbe_dec_fx( } ELSE IF( LT_32( curr_frame_pow_fx, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) && - ( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + ( EQ_16( st->prev_coder_type, UNVOICED ) || ( st->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow_fx, curr_frame_pow_exp, &exp ); #ifdef BASOP_NOGLOB - L_tmp = L_min( L_tmp, L_shl_sat( 2, ( 31 - exp ) ) ); /*31 - exp*/ + L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ #else L_tmp = L_min( L_tmp, L_shl( 2, ( 31 - exp ) ) ); /*31 - exp*/ #endif scale_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp_fx = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } @@ -2434,14 +2596,14 @@ void ivas_swb_tbe_dec_fx( #endif move16(); /* 15 +12 +3-15 =15*/ #ifdef BASOP_NOGLOB - GainShape_fx[2 * j + 1] = shl_sat( mult_r( GainShape_fx[2 * j + 1], scale_fx ), 3 ); + GainShape_fx[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ), 3 ); #else GainShape_fx[2 * j + 1] = shl( mult_r( GainShape_fx[2 * j + 1], scale_fx ), 3 ); #endif move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation_fx[add( i, i_mult( j, 40 ) )] = shl( mult_r( shaped_shb_excitation_fx[add( i, i_mult( j, 40 ) )], scale_fx ), 3 ); + shaped_shb_excitation_fx[add( i, j * 40 )] = shl( mult_r( shaped_shb_excitation_fx[add( i, j * 40 )], scale_fx ), 3 ); move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -2487,12 +2649,13 @@ void ivas_swb_tbe_dec_fx( { exp = norm_l( L_prev_ener_shb ); tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); - exp = sub( exp, 30 - ( 2 * Q_bwe_exc + 8 ) ); + exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); st->prev_ener_shb_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ + move16(); } IF( st->hBWE_FD != NULL ) @@ -2504,7 +2667,7 @@ void ivas_swb_tbe_dec_fx( { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - ( curr_frame_pow_exp + 8 ) ); + exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); @@ -2516,7 +2679,7 @@ void ivas_swb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { - shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], Q11 - Q_bwe_exc ); + shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) ); move32(); } @@ -2528,18 +2691,18 @@ void ivas_swb_tbe_dec_fx( /* resample SHB synthesis (if needed) and scale down */ synth_scale_fx = 32767; move16(); /* 1.0 in Q15 */ - IF( EQ_16( st->codec_mode, MODE1 ) ) + if ( EQ_16( st->codec_mode, MODE1 ) ) { synth_scale_fx = 29491; move16(); /* 0.9 in Q15 */ } - IF( st->output_Fs == 48000 ) + IF( EQ_32( st->output_Fs, 48000 ) ) { - IF( st->extl == FB_TBE ) + IF( EQ_16( st->extl, FB_TBE ) ) { tmp = norm_l( GainFrame_fx ); - IF( GainFrame_fx == 0 ) + if ( GainFrame_fx == 0 ) { tmp = 31; move16(); @@ -2550,14 +2713,22 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); + } + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ + move16(); tmp = norm_s( tmp1 ); - IF( tmp1 == 0 ) + if ( tmp1 == 0 ) { tmp = 15; move16(); @@ -2569,6 +2740,7 @@ void ivas_swb_tbe_dec_fx( move16(); } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); + move16(); } IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ @@ -2581,7 +2753,7 @@ void ivas_swb_tbe_dec_fx( } interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } - ELSE IF( st->output_Fs == 32000 ) + ELSE IF( EQ_32( st->output_Fs, 32000 ) ) { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { @@ -2596,7 +2768,7 @@ void ivas_swb_tbe_dec_fx( Copy32( error_fx, synth_fx, L_FRAME32k ); } } - ELSE IF( st->output_Fs == 16000 ) + ELSE IF( EQ_32( st->output_Fs, 16000 ) ) { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { @@ -2612,14 +2784,14 @@ void ivas_swb_tbe_dec_fx( /* Update previous frame parameters for FEC */ - IF( st->codec_mode == MODE1 ) + IF( EQ_16( st->codec_mode, MODE1 ) ) { hBWE_TD->GainFrame_prevfrm_fx = GainFrame_fx; move32(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx; move16(); - IF( !st->bfi ) + if ( !st->bfi ) { hBWE_TD->GainAttn_fx = 32767; move16(); @@ -4247,7 +4419,7 @@ void fb_tbe_dec( } #endif - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * tbe_read_bitstream() * @@ -4335,7 +4507,7 @@ void tbe_read_bitstream( return; } - +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -4418,13 +4590,17 @@ void GenTransition_fixed( Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; /* set targeted length of transition signal */ - length = 2 * NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); /* perFORm spectral flip and downmix with overlap snippet to match HB synth */ - IF( ( element_mode == EVS_MONO && ( rf_flag || total_brate == ACELP_9k60 ) ) || ( element_mode > EVS_MONO && L_frame == L_FRAME ) ) + test(); + test(); + test(); + test(); + IF( ( ( element_mode == EVS_MONO ) && ( rf_flag || EQ_32( total_brate, ACELP_9k60 ) ) ) || ( ( element_mode > EVS_MONO ) && EQ_16( L_frame, L_FRAME ) ) ) { flip_and_downmix_generic_fx_32( syn_overlap_32k_fx, syn_overlap_32k_fx, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem_fx + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), &( hBWE_TD->syn_dm_phase ) ); } @@ -4432,7 +4608,16 @@ void GenTransition_fixed( { FOR( i = 0; i < 2 * SHB_OVERLAP_LEN; i++ ) { - syn_overlap_32k_fx[i] = ( ( i % 2 ) == 0 ) ? ( -syn_overlap_32k_fx[i] ) : ( syn_overlap_32k_fx[i] ); + IF( i % 2 == 0 ) + { + syn_overlap_32k_fx[i] = -syn_overlap_32k_fx[i]; + move32(); + } + ELSE + { + syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; + move32(); + } } } @@ -4440,19 +4625,21 @@ void GenTransition_fixed( FOR( i = 0; i < 2 * L_SHB_LAHEAD; i++ ) { outputHB_fx[i] = L_add_sat( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_32k_fx[i] ), Mpy_32_16_1( syn_overlap_32k_fx[i], window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i] ) ); + move32(); } /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ FOR( ; i < length; i++ ) { outputHB_fx[i] = hBWE_TD->old_tbe_synth_fx[L_SHB_TRANSITION_LENGTH - 1 - i]; + move32(); } - IF( output_Fs == 48000 ) + IF( EQ_32( output_Fs, 48000 ) ) { interpolate_3_over_2_allpass_32( outputHB_fx, length, outputHB_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } - ELSE IF( output_Fs == 16000 ) + ELSE IF( EQ_32( output_Fs, 16000 ) ) { Decimate_allpass_steep_fx32( outputHB_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, outputHB_fx ); } @@ -4531,7 +4718,7 @@ void GenTransition_WB_fixed( Word32 upsampled_synth_fx[L_FRAME48k]; /* set targeted length of transition signal */ - length = 2 * NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); @@ -4540,30 +4727,43 @@ void GenTransition_WB_fixed( /* perform spectral flip and downmix with overlap snippet to match HB synth */ FOR( i = 0; i < SHB_OVERLAP_LEN; i++ ) { - speech_buf_16k2_fx[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_16k2_fx[i] ) : ( speech_buf_16k2_fx[i] ); + IF( i % 2 == 0 ) + { + speech_buf_16k2_fx[i] = -speech_buf_16k2_fx[i]; + move32(); + } + ELSE + { + speech_buf_16k2_fx[i] = speech_buf_16k2_fx[i]; + move32(); + } } /* cross fade of overlap snippet and mirrored HB synth from previous frame */ FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { outputHB_fx[i] = L_add( Mpy_32_16_1( hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i], window_shb_fx[i] ), Mpy_32_16_1( speech_buf_16k2_fx[i], window_shb_fx[L_SHB_LAHEAD - 1 - i] ) ); + move32(); outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 ); + move32(); } /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ FOR( ; i < length; i++ ) { outputHB_fx[i] = hBWE_TD->old_tbe_synth_fx_32[L_SHB_TRANSITION_LENGTH - 1 - i]; + move32(); outputHB_fx[i] = Mpy_32_16_1( outputHB_fx[i], 21299 ); + move32(); } /* upsampling if necessary */ - IF( output_Fs == 32000 ) + IF( EQ_32( output_Fs, 32000 ) ) { Interpolate_allpass_steep_32( outputHB_fx, hBWE_TD->mem_resamp_HB_fx_32, L_FRAME16k, upsampled_synth_fx ); Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME32k ); } - ELSE IF( output_Fs == 48000 ) + ELSE IF( EQ_32( output_Fs, 48000 ) ) { interpolate_3_over_1_allpass_32( outputHB_fx, L_FRAME16k, upsampled_synth_fx, hBWE_TD->mem_resamp_HB_fx_32 ); Copy32( upsampled_synth_fx, outputHB_fx, L_FRAME48k ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 11421e1e1..333361cc8 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -52,8 +52,11 @@ static void find_max_mem_dec( Word16 i; Word16 n_mem_32; Word16 max = 0; + move16(); Word32 Lmax = 0; + move32(); Word16 tempQ15, max2 = 0; + move16(); Word16 max3; Word32 tempQ32, Lmax3; TD_BWE_DEC_HANDLE hBWE_TD; @@ -98,8 +101,12 @@ static void find_max_mem_dec( /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ *n_mem2 = norm_s( max2 ); + move16(); if ( max2 == 0 ) + { *n_mem2 = 15; + move16(); + } if ( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { @@ -126,9 +133,11 @@ static void find_max_mem_dec( } /* estimate the norm for 16-bit memories */ *n_mem = norm_s( max ); + move16(); if ( max == 0 ) { *n_mem = 15; + move16(); } /* estimate the norm for 32-bit memories */ @@ -138,10 +147,12 @@ static void find_max_mem_dec( if ( Lmax == 0 ) { n_mem_32 = 31; + move16(); } tempQ15 = sub( s_min( *n_mem, n_mem_32 ), 1 ); *n_mem = s_max( tempQ15, 0 ); + move16(); /* --------------------------------------------------------------*/ /* Find headroom for synthesis stage associated with these memories: @@ -149,6 +160,7 @@ static void find_max_mem_dec( 2. st_fx->genSHBsynth_state_lsyn_filt_shb_local 3. st_fx->genSHBsynth_Hilbert_Mem_fx (32-bit) */ max3 = 0; + move16(); /* find max in prev overlapSyn */ FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { @@ -180,10 +192,15 @@ static void find_max_mem_dec( } /* estimate the norm for 16-bit memories */ *n_mem3 = norm_s( max3 ); + move16(); if ( max3 == 0 ) + { *n_mem3 = 15; + move16(); + } Lmax3 = 0; + move32(); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { /* find max in prev genSHBsynth_Hilbert_Mem_fx */ @@ -197,11 +214,15 @@ static void find_max_mem_dec( /* estimate the norm for 32-bit memories */ n_mem_32 = norm_l( Lmax3 ); if ( Lmax3 == 0 ) + { n_mem_32 = 31; + move16(); + } tempQ15 = sub( s_min( *n_mem3, n_mem_32 ), 2 ); /* very important leave at least 2 bit head room because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); + move16(); /* --------------------------------------------------------------*/ } @@ -246,7 +267,7 @@ static void rescale_genSHB_mem_dec( } } - IF( EQ_16( st_fx->extl, FB_TBE ) ) + if ( EQ_16( st_fx->extl, FB_TBE ) ) { } hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); @@ -262,7 +283,9 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) { Word16 i; Word16 max = 0; + move16(); Word32 Lmax = 0; + move32(); Word16 n_mem_32; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; @@ -274,34 +297,34 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) FOR( i = 0; i < 7; i++ ) { - if ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ), max ) ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_shb_fx[i] ); } FOR( i = 0; i < 7; i++ ) { - if ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ), max ) ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx[i] ); } FOR( i = 0; i < 7; i++ ) { - if ( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ), max ) ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR( i = 0; i < 10; i++ ) { - if ( abs_s( hBWE_TD->state_lpc_syn_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->state_lpc_syn_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } FOR( i = 0; i < 5; i++ ) { - if ( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } @@ -320,7 +343,7 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) FOR( i = 0; i < 2; i++ ) { - if ( L_abs( hBWE_TD->mem_csfilt_fx[i] ) > Lmax ) + if ( GT_32( L_abs( hBWE_TD->mem_csfilt_fx[i] ), Lmax ) ) Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } @@ -335,7 +358,9 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) } *n_mem = sub( s_min( *n_mem, n_mem_32 ), 1 ); + move16(); *n_mem = s_max( *n_mem, 0 ); + move16(); } void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) @@ -413,10 +438,13 @@ void InitSWBdecBuffer_ivas_fx( hBWE_TD->syn_dm_phase = 0; move16(); hBWE_TD->prev_fbbwe_ratio_fx = 32767 /*1.0f Q15*/; + move16(); /* these are fd-bwe constants */ - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + move32(); hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + move32(); st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_ener_fx_Q = 31; @@ -455,10 +483,13 @@ void InitSWBdecBuffer_fx( hBWE_TD->syn_dm_phase = 0; move16(); hBWE_TD->prev_fbbwe_ratio_fx = 32767 /*1.0f Q15*/; + move16(); /* these are fd-bwe constants */ - hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + move32(); hBWE_TD->prev_swb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + move32(); st_fx->prev_Q_bwe_exc = 31; move16(); st_fx->prev_ener_fx_Q = 31; @@ -483,7 +514,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - IF( st_fx->extl != WB_TBE ) + IF( NE_16( st_fx->extl, WB_TBE ) ) { f = 1489; move16(); /* Q15 */ @@ -528,7 +559,7 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /* States for FEC */ - IF( st_fx->extl != WB_TBE ) + IF( NE_16( st_fx->extl, WB_TBE ) ) { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -558,12 +589,17 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * hBWE_TD->GainAttn_fx = 32767; move16(); /*Q15*/ hBWE_TD->tbe_demph_fx = 0; + move16(); hBWE_TD->tbe_premph_fx = 0; + move16(); set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb_fx = 16384; /*Q14 =1*/ + move16(); set16_fx( &st_fx->GainShape_Delay[0], 0, NUM_SHB_SUBFR / 2 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ - hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + move32(); + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + move16(); set16_fx( hBWE_TD->old_core_synth_fx, 0, L_FRAME16k ); set16_fx( hBWE_TD->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH ); @@ -625,24 +661,30 @@ void ivas_wb_tbe_dec_fx( Word16 Q_bwe_exc, Q_bwe_exc_ext, Qx; Word16 n_mem, cnt; Word16 max = 0; + move16(); Word32 L_tmp, Lacc, Lscale, Lmax = 0; + move32(); Word16 tmp, exp, sc; Word16 vf_modified[NB_SUBFR16k]; Word16 uv_flag = 0; + move16(); Word16 dummy = 0; - Word32 dummy2[HILBERT_MEM_SIZE] = { 0 }; + move16(); + Word32 dummy2[HILBERT_MEM_SIZE]; Word16 f, inc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - + set_val_Word32( &dummy2[0], 0, HILBERT_MEM_SIZE ); IF( st_fx->bws_cnt == 0 ) { /* Initialization */ set16_fx( GainShape, 11469 /*0.35f Q15*/, NUM_SHB_SUBFR ); GainFrame = 1; + move32(); IF( !st_fx->bfi ) { @@ -651,11 +693,13 @@ void ivas_wb_tbe_dec_fx( IF( NE_16( st_fx->last_extl, WB_TBE ) ) { hBWE_TD->GainFrame_prevfrm_fx = 0; + move32(); hBWE_TD->lsp_prevfrm_fx[0] = 3277 /*0.1f Q15*/; move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); + move16(); } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); @@ -665,8 +709,14 @@ void ivas_wb_tbe_dec_fx( { /* Frame gain */ st_fx->rf_indx_tbeGainFr = s_and( st_fx->rf_indx_tbeGainFr, 0xF ); /* only four LSBs are valid */ + move16(); Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); - IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); @@ -681,30 +731,42 @@ void ivas_wb_tbe_dec_fx( { case 0: GainFrame = 131072; /* 0.5f in Q18 */ - IF( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); + if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 1: GainFrame = 524288; /* 2.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 2: GainFrame = 1048576; /* 4.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 3: GainFrame = 2097152; /* 8.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; default: fprintf( stderr, "RF SWB-TBE gain bits not supported." ); @@ -714,8 +776,13 @@ void ivas_wb_tbe_dec_fx( GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } - IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) ) + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) ) { + test(); + test(); + test(); + test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { GainFrame = Mult_32_16( GainFrame, 9830 ); @@ -752,10 +819,11 @@ void ivas_wb_tbe_dec_fx( ELSE { GainFrame = hBWE_TD->GainFrame_prevfrm_fx; /*Q18*/ + move32(); } } - IF( st_fx->extl_brate == WB_TBE_0k35 ) + IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { /* convert LSPs back into LP coeffs */ lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); @@ -792,14 +860,14 @@ void ivas_wb_tbe_dec_fx( } Copy( voice_factors, vf_modified, NB_SUBFR16k ); - IF( coder_type == VOICED ) + IF( EQ_16( coder_type, VOICED ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ move16(); } - IF( st_fx->L_frame != L_FRAME ) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ move16(); @@ -808,29 +876,39 @@ void ivas_wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; + move32(); FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - Q_bwe_exc = ( Lmax == 0 ) ? 31 : norm_l( Lmax ); + IF( Lmax == 0 ) + { + Q_bwe_exc = 31; + move16(); + } + ELSE + { + Q_bwe_exc = norm_l( Lmax ); + } Q_bwe_exc = sub( Q_bwe_exc, 3 ); Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); find_max_mem_wb( st_fx, &n_mem ); - IF( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) > n_mem ) + if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) { Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); } test(); - IF( uv_flag && GT_16( Q_bwe_exc, 20 ) ) + if ( uv_flag && GT_16( Q_bwe_exc, 20 ) ) { Q_bwe_exc = 20; move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } prev_pow = 0; + move32(); FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ @@ -842,6 +920,7 @@ void ivas_wb_tbe_dec_fx( FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); + move16(); } Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); @@ -854,12 +933,13 @@ void ivas_wb_tbe_dec_fx( bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); curr_pow = 0; + move32(); FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ } - IF( GT_16( voice_factors[0], 24576 ) ) + if ( GT_16( voice_factors[0], 24576 ) ) { curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } @@ -871,10 +951,12 @@ void ivas_wb_tbe_dec_fx( { L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + move16(); } - Lscale = root_a_fx( Lscale, 31 - exp, &exp ); + Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + move16(); /* Update SHB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); @@ -887,6 +969,7 @@ void ivas_wb_tbe_dec_fx( Q_bwe_exc_ext, st_fx->L_frame, 0, &dummy, dummy, dummy2 ); max = 0; + move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); @@ -914,6 +997,7 @@ void ivas_wb_tbe_dec_fx( } n = sub( 14, n ); curr_frame_pow = 1; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -931,12 +1015,15 @@ void ivas_wb_tbe_dec_fx( { curr_frame_pow = L_shr( curr_frame_pow, sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ); curr_frame_pow_exp = st_fx->prev_frame_pow_exp; + move16(); } ELSE { hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); + move32(); } + test(); test(); IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) { @@ -945,24 +1032,26 @@ void ivas_wb_tbe_dec_fx( L_tmp = root_a_over_b_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp = round_fx( L_shl( L_tmp, exp ) ); /* Q15 */ } ELSE { scale = temp = 32767; move16(); /* Q15 */ + move16(); } FOR( j = 0; j < 8; j++ ) { GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - GainShape[2 * j + 1] = mult_r( GainShape[2 * j + 1], scale ); + GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); FOR( i = 0; i < L_FRAME16k / ( 4 * 8 ); i++ ) { - shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )] = mult_r( shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )], scale ); + shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )] = mult_r( shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )], scale ); + move16(); } IF( temp > 0 ) { @@ -994,13 +1083,13 @@ void ivas_wb_tbe_dec_fx( move16(); FOR( cnt = 0; cnt < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; cnt++ ) { - IF( abs_s( shaped_wb_excitation[cnt] ) > max ) + if ( GT_16( abs_s( shaped_wb_excitation[cnt] ), max ) ) { max = abs_s( shaped_wb_excitation[cnt] ); } } Qx = norm_s( max ); - IF( max == 0 ) + if ( max == 0 ) { Qx = 15; move16(); @@ -1012,14 +1101,14 @@ void ivas_wb_tbe_dec_fx( move16(); FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - IF( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ) > max ) - max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); + if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) + max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - IF( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ) > max ) - max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); + if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) + max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); } IF( EQ_32( st_fx->output_Fs, 32000 ) ) @@ -1037,14 +1126,15 @@ void ivas_wb_tbe_dec_fx( } } n_mem = 15; - IF( max != 0 ) + move16(); + if ( max != 0 ) { n_mem = norm_s( max ); } n_mem = s_max( n_mem, 0 ); - IF( sub( Qx, st_fx->prev_Qx ) > n_mem ) - Qx = add( st_fx->prev_Qx, n_mem ); + if ( GT_16( sub( Qx, st_fx->prev_Qx ), n_mem ) ) + Qx = add( st_fx->prev_Qx, n_mem ); FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) { @@ -1097,6 +1187,7 @@ void ivas_wb_tbe_dec_fx( n = sub( sub( 14, n ), Qx ); Lacc = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ @@ -1112,8 +1203,9 @@ void ivas_wb_tbe_dec_fx( #endif exp = sub( add( exp, 22 ), 30 ); tmp = div_s( 16384, tmp ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ - st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ + st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ + move16(); } @@ -1148,9 +1240,13 @@ void ivas_wb_tbe_dec_fx( move16(); } GainFrame = 0; /* Q18 */ + move32(); Qx = 0; + move16(); Q_bwe_exc = 31; + move16(); hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + move32(); st_fx->prev_frame_pow_exp = 0; move16(); } @@ -1165,8 +1261,9 @@ void ivas_wb_tbe_dec_fx( Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ + move32(); - IF( !st_fx->bfi ) + if ( !st_fx->bfi ) { hBWE_TD->GainAttn_fx = 32767; move16(); @@ -1211,24 +1308,30 @@ void wb_tbe_dec_fx( Word16 Q_bwe_exc, Q_bwe_exc_ext, Qx; Word16 n_mem, cnt; Word16 max = 0; + move16(); Word32 L_tmp, Lacc, Lscale, Lmax = 0; + move32(); Word16 tmp, exp, sc; Word16 vf_modified[NB_SUBFR16k]; Word16 uv_flag = 0; + move16(); Word16 dummy = 0; - Word32 dummy2[HILBERT_MEM_SIZE] = { 0 }; + move16(); + Word32 dummy2[HILBERT_MEM_SIZE]; Word16 f, inc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - + set_val_Word32( &dummy2[0], 0, HILBERT_MEM_SIZE ); IF( st_fx->bws_cnt == 0 ) { /* Initialization */ set16_fx( GainShape, 11469 /*0.35f Q15*/, NUM_SHB_SUBFR ); GainFrame = 1; + move32(); IF( !st_fx->bfi ) { @@ -1237,11 +1340,13 @@ void wb_tbe_dec_fx( IF( NE_16( st_fx->last_extl, WB_TBE ) ) { hBWE_TD->GainFrame_prevfrm_fx = 0; + move32(); hBWE_TD->lsp_prevfrm_fx[0] = 3277 /*0.1f Q15*/; move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { hBWE_TD->lsp_prevfrm_fx[i] = add( hBWE_TD->lsp_prevfrm_fx[i - i], 3277 /*0.1f Q15*/ ); + move16(); } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_wb, LPC_SHB_ORDER_LBR_WB ); @@ -1251,8 +1356,14 @@ void wb_tbe_dec_fx( { /* Frame gain */ st_fx->rf_indx_tbeGainFr = s_and( st_fx->rf_indx_tbeGainFr, 0xF ); /* only four LSBs are valid */ + move16(); Copy32( SHBCB_FrameGain16_fx + st_fx->rf_indx_tbeGainFr, &GainFrame, 1 ); - IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); @@ -1267,30 +1378,42 @@ void wb_tbe_dec_fx( { case 0: GainFrame = 131072; /* 0.5f in Q18 */ - IF( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); + if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 1: GainFrame = 524288; /* 2.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 2: GainFrame = 1048576; /* 4.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 3: GainFrame = 2097152; /* 8.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; default: fprintf( stderr, "RF SWB-TBE gain bits not supported." ); @@ -1300,8 +1423,13 @@ void wb_tbe_dec_fx( GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } - IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) ) + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) ) { + test(); + test(); + test(); + test(); IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && LT_16( st_fx->prev_tilt_code_dec_fx, 1497 ) && GT_16( st_fx->prev_tilt_code_dec_fx, 200 ) ) { GainFrame = Mult_32_16( GainFrame, 9830 ); @@ -1337,14 +1465,15 @@ void wb_tbe_dec_fx( ELSE { GainFrame = hBWE_TD->GainFrame_prevfrm_fx; /*Q18*/ + move32(); } } - IF( st_fx->extl_brate == WB_TBE_0k35 ) + IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { /* convert LSPs back into LP coeffs */ lsp2lpc_fx( lpc_wb + 1, lsf_wb, st_fx->prev_lpc_wb_fx, LPC_SHB_ORDER_LBR_WB ); - set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) ); + set16_fx( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0, LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ); FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { st_fx->prev_lpc_wb_fx[i] = lpc_wb[i + 1]; @@ -1377,14 +1506,14 @@ void wb_tbe_dec_fx( } Copy( voice_factors, vf_modified, NB_SUBFR16k ); - IF( coder_type == VOICED ) + IF( EQ_16( coder_type, VOICED ) ) { FOR( i = 1; i < NB_SUBFR; i++ ) { vf_modified[i] = add( mult_r( 26214, voice_factors[i] ), mult_r( 6554, voice_factors[i - 1] ) ); /* Q15 */ move16(); } - IF( st_fx->L_frame != L_FRAME ) + IF( NE_16( st_fx->L_frame, L_FRAME ) ) { vf_modified[4] = add( mult_r( 26214, voice_factors[4] ), mult_r( 6554, voice_factors[3] ) ); /* Q15 */ move16(); @@ -1393,17 +1522,26 @@ void wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; + move32(); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); } - Q_bwe_exc = ( Lmax == 0 ) ? 31 : norm_l( Lmax ); + IF( Lmax == 0 ) + { + Q_bwe_exc = 31; + move16(); + } + ELSE + { + Q_bwe_exc = norm_l( Lmax ); + } Q_bwe_exc = sub( Q_bwe_exc, 1 ); Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); find_max_mem_wb( st_fx, &n_mem ); - if ( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) > n_mem ) + if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) { Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); } @@ -1416,6 +1554,7 @@ void wb_tbe_dec_fx( } prev_pow = 0; + move32(); FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1449,6 +1588,7 @@ void wb_tbe_dec_fx( bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); curr_pow = 0; + move32(); FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1474,8 +1614,9 @@ void wb_tbe_dec_fx( #else shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #endif + move16(); } - Lscale = root_a_fx( Lscale, 31 - exp, &exp ); + Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ @@ -1490,6 +1631,7 @@ void wb_tbe_dec_fx( Q_bwe_exc_ext, st_fx->L_frame, 0, &dummy, dummy, dummy2 ); max = 0; + move16(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ @@ -1498,7 +1640,7 @@ void wb_tbe_dec_fx( IF( max == 0 ) { curr_frame_pow = 1; - move16(); + move32(); n = 0; move16(); } @@ -1517,6 +1659,7 @@ void wb_tbe_dec_fx( } n = sub( 14, n ); curr_frame_pow = 1; + move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { #ifdef BASOP_NOGLOB @@ -1534,10 +1677,12 @@ void wb_tbe_dec_fx( { curr_frame_pow = L_shr( curr_frame_pow, sub( st_fx->prev_frame_pow_exp, curr_frame_pow_exp ) ); curr_frame_pow_exp = st_fx->prev_frame_pow_exp; + move16(); } ELSE { hBWE_TD->prev_wb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_wb_bwe_frame_pow_fx, sub( curr_frame_pow_exp, st_fx->prev_frame_pow_exp ) ); + move32(); } test(); @@ -1548,24 +1693,25 @@ void wb_tbe_dec_fx( L_tmp = root_a_over_b_fx( hBWE_TD->prev_wb_bwe_frame_pow_fx, 22, curr_frame_pow, 22, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp = round_fx( L_shl( L_tmp, exp ) ); /* Q15 */ } ELSE { scale = temp = 32767; move16(); /* Q15 */ + move16(); } FOR( j = 0; j < 8; j++ ) { GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - GainShape[2 * j + 1] = mult_r( GainShape[2 * j + 1], scale ); + GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); FOR( i = 0; i < L_FRAME16k / ( 4 * 8 ); i++ ) { - shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )] = mult_r( shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )], scale ); + shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )] = mult_r( shaped_wb_excitation[add( i, j * ( L_FRAME16k / ( 4 * 8 ) ) )], scale ); } IF( temp > 0 ) { @@ -1597,7 +1743,7 @@ void wb_tbe_dec_fx( move16(); FOR( cnt = 0; cnt < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; cnt++ ) { - if ( abs_s( shaped_wb_excitation[cnt] ) > max ) + if ( GT_16( abs_s( shaped_wb_excitation[cnt] ), max ) ) { max = abs_s( shaped_wb_excitation[cnt] ); } @@ -1615,13 +1761,13 @@ void wb_tbe_dec_fx( move16(); FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - if ( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - if ( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ) > max ) + if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); } @@ -1640,13 +1786,14 @@ void wb_tbe_dec_fx( } } n_mem = 15; + move16(); if ( max != 0 ) { n_mem = norm_s( max ); } n_mem = s_max( n_mem, 0 ); - if ( sub( Qx, st_fx->prev_Qx ) > n_mem ) + if ( GT_16( sub( Qx, st_fx->prev_Qx ), n_mem ) ) Qx = add( st_fx->prev_Qx, n_mem ); FOR( i = 0; i < ( L_FRAME16k + L_SHB_LAHEAD ) / 4; i++ ) @@ -1700,6 +1847,7 @@ void wb_tbe_dec_fx( n = sub( sub( 14, n ), Qx ); Lacc = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_mult( synth_frac[i], synth_frac[i] ); /* Q29 */ @@ -1717,10 +1865,11 @@ void wb_tbe_dec_fx( tmp = div_s( 16384, tmp ); L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* Q(31-exp) */ #ifdef BASOP_NOGLOB - st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ + st_fx->last_wb_bwe_ener_fx = round_fx_sat( L_shl_sat( L_tmp, add( exp, sub( n, 12 ) ) ) ); /* Q3 */ #else st_fx->last_wb_bwe_ener_fx = round_fx( L_shl( L_tmp, add( exp, n - 12 ) ) ); /* Q3 */ #endif + move16(); } @@ -1755,9 +1904,13 @@ void wb_tbe_dec_fx( move16(); } GainFrame = 0; /* Q18 */ + move32(); Qx = 0; + move16(); Q_bwe_exc = 31; + move16(); hBWE_TD->prev_wb_bwe_frame_pow_fx = 4194l /*0.001f Q22*/; /* Q22 */ + move32(); st_fx->prev_frame_pow_exp = 0; move16(); } @@ -1772,8 +1925,9 @@ void wb_tbe_dec_fx( Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ + move32(); - if ( !st_fx->bfi ) + IF( !st_fx->bfi ) { hBWE_TD->GainAttn_fx = 32767; move16(); @@ -1883,6 +2037,7 @@ void swb_tbe_dec_fx( Word16 mean_vf; Word16 exp_ener, inv_ener; Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ + move32(); Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; Word32 curr_frame_pow; Word16 curr_frame_pow_exp; @@ -1902,7 +2057,7 @@ void swb_tbe_dec_fx( move16(); set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ Q_shb = 0; /* high band target Q factor set to zero */ - + move16(); L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); #ifdef BASOP_NOGLOB tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); @@ -1912,7 +2067,7 @@ void swb_tbe_dec_fx( /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ /* o: tilt_swb_fec in Q11 */ test(); - IF( st_fx->bfi && NE_16( st_fx->clas_dec, UNVOICED_CLAS ) ) + if ( st_fx->bfi && st_fx->clas_dec != UNVOICED_CLAS ) { tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; move16(); @@ -1921,7 +2076,7 @@ void swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) + IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && ( st_fx->clas_dec == UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) { test(); test(); @@ -1930,7 +2085,8 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( ( st_fx->prev_fractive == 0 && + test(); + IF( ( ( st_fx->prev_fractive == 0 ) && ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || ( EQ_16( st_fx->prev_fractive, 1 ) && GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ @@ -1951,8 +2107,10 @@ void swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ IF( st_fx->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ + f_fx = 1489; /*Q15*/ + move16(); inc_fx = 1489; /*Q15*/ + move16(); IF( EQ_16( is_fractive, 1 ) ) { Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); @@ -1974,8 +2132,8 @@ void swb_tbe_dec_fx( test(); test(); IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && - !( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 && L_sub( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) || - sub( st_fx->last_core, ACELP_CORE ) != 0 || ( sub( st_fx->last_core, ACELP_CORE ) == 0 && L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) || sub( ( is_fractive ^ st_fx->prev_fractive ), 1 ) == 0 ) + !( ( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 ) && L_sub( st_fx->prev_enerLH_fx, ( L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) ) || + ( sub( st_fx->last_core, ACELP_CORE ) != 0 ) || ( ( sub( st_fx->last_core, ACELP_CORE ) == 0 ) && ( L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) ) || ( sub( s_xor( is_fractive, st_fx->prev_fractive ), 1 ) == 0 ) ) { set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); } @@ -2017,11 +2175,10 @@ void swb_tbe_dec_fx( { hBWE_TD->GainFrame_prevfrm_fx = 0; move16(); + f_fx = 1489 /*0.045454f Q15*/; move16(); - move16(); - f_fx = 1489 /*0.045454f Q15*/; /*Q15*/ inc_fx = 1489 /*0.045454f Q15*/; - ; /*Q15*/ + move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->lsp_prevfrm_fx[i] = f_fx; @@ -2042,7 +2199,13 @@ void swb_tbe_dec_fx( frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) { /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); @@ -2057,30 +2220,42 @@ void swb_tbe_dec_fx( { case 0: GainFrame = 131072; /* 0.5f in Q18 */ - IF( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); + if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 1: GainFrame = 524288; /* 2.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 2: GainFrame = 1048576; /* 4.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; case 3: GainFrame = 2097152; /* 8.0f in Q18 */ - IF( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) - temp = 26214 /*0.8 Q15*/; - move16(); + move32(); test(); + if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) + { + temp = 26214 /*0.8 Q15*/; + move16(); + } BREAK; default: fprintf( stderr, "RF SWB-TBE gain bits not supported." ); @@ -2089,9 +2264,14 @@ void swb_tbe_dec_fx( { GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); } - IF( EQ_16( st_fx->core, ACELP_CORE ) && EQ_16( st_fx->last_core, ACELP_CORE ) ) + test(); + IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) ) { - IF( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) + test(); + test(); + test(); + test(); + if ( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) { GainFrame = Mult_32_16( GainFrame, 9830 ); } @@ -2130,11 +2310,11 @@ void swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape[i * 4 + j] = mult_r( st_fx->cummulative_damping, st_fx->GainShape_Delay[4 + i] ); + GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, st_fx->GainShape_Delay[4 + i] ); move16(); } } - IF( GT_16( tilt_swb_fec, 8 << 11 ) ) /* tilt_swb_fec in Q11 */ + IF( GT_16( tilt_swb_fec, ( 8 << 11 ) ) ) /* tilt_swb_fec in Q11 */ { IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) { @@ -2169,7 +2349,7 @@ void swb_tbe_dec_fx( tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ i = sub( norm_s( tmp1 ), 1 ); tmp1 = shl( tmp1, i ); /* Qi */ - if ( tmp == 0 ) + IF( tmp == 0 ) { tmp = 32767 /*1.0f Q15*/; move16(); /*Q15*/ @@ -2180,7 +2360,7 @@ void swb_tbe_dec_fx( scale = s_max( scale, 0 ); /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ #ifdef BASOP_NOGLOB - tmp = shl_sat( scale, 15 - exp - i ); /*Q15*/ + tmp = shl_sat( scale, sub( sub( 15, exp ), i ) ); /*Q15*/ #else tmp = shl( scale, 15 - exp - i ); /*Q15*/ #endif @@ -2225,6 +2405,7 @@ void swb_tbe_dec_fx( shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); mixFactors = hBWE_TD->prev_mixFactors_fx; + move16(); IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { @@ -2300,15 +2481,15 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( st_fx->bws_cnt == 0 && st_fx->bws_cnt1 == 0 && st_fx->prev_use_partial_copy == 0 && st_fx->use_partial_copy == 0 ) + IF( ( st_fx->bws_cnt == 0 ) && ( st_fx->bws_cnt1 == 0 ) && ( st_fx->prev_use_partial_copy == 0 ) && ( st_fx->use_partial_copy == 0 ) ) { lsf_diff[0] = 16384; move16(); /*Q15*/ - lsf_diff[sub( LPC_SHB_ORDER, 1 )] = 16384; + lsf_diff[LPC_SHB_ORDER - 1] = 16384; move16(); /*Q15*/ FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff[i] = sub( lsf_shb[i], lsf_shb[sub( i, 1 )] ); + lsf_diff[i] = sub( lsf_shb[i], lsf_shb[i - 1] ); move16(); } @@ -2346,11 +2527,12 @@ void swb_tbe_dec_fx( tmp = mult( 26214, lsf_diff[i] ); test(); - IF( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ { st_fx->BER_detect = 1; move16(); tmp = 0; + move16(); } ELSE { @@ -2366,11 +2548,12 @@ void swb_tbe_dec_fx( tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); test(); - IF( lsf_diff[i] <= 0 || tmp < 0 ) /* safety check in case of bit errors */ + IF( ( lsf_diff[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ { st_fx->BER_detect = 1; move16(); tmp = 0; + move16(); } ELSE { @@ -2383,7 +2566,9 @@ void swb_tbe_dec_fx( } } w[0] = w[1]; - w[sub( LPC_SHB_ORDER, 1 )] = w[sub( LPC_SHB_ORDER, 2 )]; + move16(); + w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; + move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -2401,6 +2586,7 @@ void swb_tbe_dec_fx( Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = tilt_para; + move16(); } ELSE { @@ -2427,7 +2613,7 @@ void swb_tbe_dec_fx( /* convert from lsp to lsf */ /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - tmp = i_mult( j, ( LPC_SHB_ORDER + 1 ) ); + tmp = i_mult( j, LPC_SHB_ORDER + 1 ); /* convert LSPs to LP coefficients */ E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); /* Bring the LPCs to Q12 */ @@ -2447,10 +2633,15 @@ void swb_tbe_dec_fx( /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; + move32(); hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; + move32(); hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; + move32(); hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; + move16(); hBWE_TD->prev_mixFactors_fx = mixFactors; + move16(); /* SWB CNG/DTX - update memories */ Copy( st_fx->lsp_shb_prev_fx, st_fx->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ @@ -2468,6 +2659,7 @@ void swb_tbe_dec_fx( /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ Lmax = 0; + move32(); FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); @@ -2476,6 +2668,7 @@ void swb_tbe_dec_fx( if ( Lmax == 0 ) { Q_bwe_exc = 31; + move16(); } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); @@ -2486,6 +2679,7 @@ void swb_tbe_dec_fx( if ( GT_16( Q_bwe_exc, tmp ) ) { Q_bwe_exc = tmp; + move16(); } /* rescale the memories if Q_bwe_exc is different from previous frame */ @@ -2526,7 +2720,7 @@ void swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - Copy( lpc_shb, &lpc_shb_sf[j * ( LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); + Copy( lpc_shb, &lpc_shb_sf[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); } } @@ -2539,6 +2733,7 @@ void swb_tbe_dec_fx( &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); *Q_white_exc = Q_bwe_exc_fb; + move16(); IF( EQ_16( st_fx->extl, FB_TBE ) ) { st_fx->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; @@ -2554,7 +2749,7 @@ void swb_tbe_dec_fx( /* rescale the TBE post proc memory */ FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], Q_bwe_exc - st_fx->prev_Q_bwe_syn ); + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); move16(); } @@ -2600,11 +2795,13 @@ void swb_tbe_dec_fx( { L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); } IF( exp < 0 ) { Lscale = L_shl( Lscale, exp ); exp = 0; + move16(); } FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { @@ -2619,6 +2816,7 @@ void swb_tbe_dec_fx( Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); } /* Update SHB excitation */ @@ -2626,17 +2824,19 @@ void swb_tbe_dec_fx( l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; L_ener = 0; + move32(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { L_tmp = 0; + move32(); ener_tmp[i] = 0; - + move32(); { Word64 tmp64 = 0; move64(); FOR( j = 0; j < l_subframe_fx; j++ ) { - tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[i * l_subframe_fx + j], shaped_shb_excitation[i * l_subframe_fx + j] ); /* 2*Q_bwe_exc */ + tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )], shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )] ); /* 2*Q_bwe_exc */ } L_tmp = W_sat_l( tmp64 ); } @@ -2646,7 +2846,7 @@ void swb_tbe_dec_fx( { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - ( 2 * Q_bwe_exc ) ); + exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); @@ -2691,7 +2891,7 @@ void swb_tbe_dec_fx( move16(); } test(); - if ( st_fx->prev_fractive == 1 && GT_16( st_fx->tilt_wb_fx, 1024 ) ) + if ( EQ_16( st_fx->prev_fractive, 1 ) && GT_16( st_fx->tilt_wb_fx, 1024 ) ) { st_fx->tilt_wb_fx = 1024; move16(); @@ -2704,15 +2904,18 @@ void swb_tbe_dec_fx( IF( st_fx->prev_fractive == 0 ) { st_fx->tilt_wb_fx = 8192; + move16(); } ELSE { st_fx->tilt_wb_fx = 16384; + move16(); } } ELSE { st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); + move16(); } } @@ -2731,6 +2934,7 @@ void swb_tbe_dec_fx( #else st_fx->tilt_wb_fx = extract_h( L_shr( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ #endif + move16(); /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ } ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) @@ -2740,6 +2944,7 @@ void swb_tbe_dec_fx( #else st_fx->tilt_wb_fx = extract_h( L_shr( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ #endif + move16(); /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ @@ -2752,19 +2957,20 @@ void swb_tbe_dec_fx( ELSE { GainFrame_prevfrm_fx = 0; + move32(); } IF( EQ_16( is_fractive, 1 ) ) { - GainFrame = L_shl( (Word32) st_fx->tilt_wb_fx, 10 ); + GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 10 ); } ELSE { - GainFrame = L_shl( (Word32) st_fx->tilt_wb_fx, 8 ); + GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 8 ); } test(); - IF( EQ_16( ( is_fractive & st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) + IF( EQ_16( s_and( is_fractive, st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) { GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ } @@ -2774,14 +2980,14 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( is_fractive ^ st_fx->prev_fractive ) == 0 ) + IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st_fx->prev_fractive ) == 0 ) ) { GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); } ELSE { test(); - IF( is_fractive == 0 && EQ_16( st_fx->prev_fractive, 1 ) ) + IF( ( is_fractive == 0 ) && EQ_16( st_fx->prev_fractive, 1 ) ) { L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ @@ -2798,7 +3004,7 @@ void swb_tbe_dec_fx( } ELSE { - IF( st_fx->bws_cnt1 > 0 ) + if ( st_fx->bws_cnt1 > 0 ) { GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ } @@ -2827,7 +3033,7 @@ void swb_tbe_dec_fx( test(); test(); test(); - IF( NE_16( st_fx->clas_dec, UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && + IF( ( st_fx->clas_dec != UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) { IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ @@ -2844,7 +3050,7 @@ void swb_tbe_dec_fx( } test(); - IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && hBWE_TD->tilt_swb_fec_fx > 0 ) + IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) { exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ @@ -2853,7 +3059,7 @@ void swb_tbe_dec_fx( GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } } - ELSE IF( ( NE_16( st_fx->clas_dec, UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && + ELSE IF( ( ( st_fx->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) { GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); @@ -2934,7 +3140,7 @@ void swb_tbe_dec_fx( { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - GainShape_tmp[i] = GainShape[shl( i, 2 )]; /* Q15 */ + GainShape_tmp[i] = GainShape[i * 4]; /* Q15 */ move16(); } @@ -2954,6 +3160,7 @@ void swb_tbe_dec_fx( /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ /* tmp = L_tmp2/ener_tmp_fx[i]*/ L_tmp = L_tmp2; + move32(); if ( L_tmp2 < 0 ) { L_tmp = L_negate( L_tmp2 ); @@ -2965,11 +3172,11 @@ void swb_tbe_dec_fx( #else fracb = round_fx( L_shl( L_tmp, expb ) ); #endif - expb = 30 - expb; /* - (2*Q_bwe_exc_ext); */ + expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ expa = norm_l( ener_tmp[i] ); fraca = extract_h( L_shl( ener_tmp[i], expa ) ); - expa = 30 - expa; + expa = sub( 30, expa ); scale = shr( sub( fraca, fracb ), 15 ); fracb = shl( fracb, scale ); @@ -2979,15 +3186,25 @@ void swb_tbe_dec_fx( exp = sub( sub( expb, expa ), 1 ); tmp = shl( tmp, exp ); GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ + move16(); } hBWE_TD->prev_ener_fx = ener_tmp[i]; + move32(); hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; + move16(); st_fx->prev_ener_fx_Q = Q_bwe_exc; + move16(); } FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) { - GainShape[i] = GainShape_tmp[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + GainShape[i] = GainShape_tmp[idx]; move16(); } } @@ -3019,6 +3236,7 @@ void swb_tbe_dec_fx( max = 0; + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ @@ -3035,6 +3253,7 @@ void swb_tbe_dec_fx( { n = norm_s( max ); max = 0; + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { #ifdef BASOP_NOGLOB @@ -3047,6 +3266,7 @@ void swb_tbe_dec_fx( } curr_frame_pow = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ @@ -3062,9 +3282,12 @@ void swb_tbe_dec_fx( IF( GT_16( tmp, 32 ) ) { st_fx->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); + move16(); tmp = 32; + move16(); } hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); + move32(); st_fx->prev_frame_pow_exp = curr_frame_pow_exp; move16(); } @@ -3074,9 +3297,11 @@ void swb_tbe_dec_fx( { curr_frame_pow_exp = sub( st_fx->prev_frame_pow_exp, 32 ); tmp = -32; + move16(); } curr_frame_pow = L_shr( curr_frame_pow, -tmp ); curr_frame_pow_exp = st_fx->prev_frame_pow_exp; + move16(); } test(); IF( !st_fx->bfi && st_fx->prev_bfi ) @@ -3092,9 +3317,9 @@ void swb_tbe_dec_fx( L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ } ELSE @@ -3106,11 +3331,11 @@ void swb_tbe_dec_fx( { GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); move16(); - GainShape[2 * j + 1] = mult_r( GainShape[2 * j + 1], scale ); + GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { - shaped_shb_excitation[i + j * L_FRAME16k / 8] = mult_r( shaped_shb_excitation[i + j * L_FRAME16k / 8], scale ); + shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )], scale ); move16(); } @@ -3154,18 +3379,18 @@ void swb_tbe_dec_fx( test(); IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && NE_16( st_fx->prev_coder_type, UNVOICED ) && - NE_16( st_fx->last_good, UNVOICED_CLAS ) ) + ( st_fx->last_good != UNVOICED_CLAS ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || EQ_16( st_fx->last_good, UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); #ifdef BASOP_NOGLOB @@ -3173,9 +3398,9 @@ void swb_tbe_dec_fx( #else scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #endif - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } @@ -3190,9 +3415,9 @@ void swb_tbe_dec_fx( { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); #ifdef BASOP_NOGLOB temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ #else @@ -3201,18 +3426,18 @@ void swb_tbe_dec_fx( } ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) + ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) { L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); #ifdef BASOP_NOGLOB - L_tmp = L_min( L_tmp, L_shl_sat( 2, ( 31 - exp ) ) ); /*31 - exp*/ + L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ #else L_tmp = L_min( L_tmp, L_shl( 2, ( 31 - exp ) ) ); /*31 - exp*/ #endif scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); - L_tmp = root_a_fx( L_tmp, 31 - exp, &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); + L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ } } @@ -3225,7 +3450,7 @@ void swb_tbe_dec_fx( #endif move16(); /* 15 +12 +3-15 =15*/ #ifdef BASOP_NOGLOB - GainShape[2 * j + 1] = shl_sat( mult_r( GainShape[2 * j + 1], scale ), 3 ); + GainShape[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape[add( 2 * j, 1 )], scale ), 3 ); #else GainShape[2 * j + 1] = shl( mult_r( GainShape[2 * j + 1], scale ), 3 ); #endif @@ -3233,7 +3458,7 @@ void swb_tbe_dec_fx( FOR( i = 0; i < 40; i++ ) { #ifdef BASOP_NOGLOB - shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl_sat( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); + shaped_shb_excitation[add( i, j * 40 )] = shl_sat( mult_r( shaped_shb_excitation[add( i, j * 40 )], scale ), 3 ); #else shaped_shb_excitation[add( i, i_mult( j, 40 ) )] = shl( mult_r( shaped_shb_excitation[add( i, i_mult( j, 40 ) )], scale ), 3 ); #endif @@ -3288,7 +3513,7 @@ void swb_tbe_dec_fx( { exp = norm_l( L_prev_ener_shb ); tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); - exp = sub( exp, 30 - ( 2 * Q_bwe_exc + 8 ) ); + exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); @@ -3298,15 +3523,17 @@ void swb_tbe_dec_fx( #else st_fx->prev_ener_shb_fx = round_fx( L_shl( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ #endif + move16(); } /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ tmp = 0; + move16(); IF( L_tmp != 0 ) { exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, 30 - ( curr_frame_pow_exp + 8 ) ); + exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); tmp = div_s( 16384, tmp ); L_tmp = L_deposit_h( tmp ); @@ -3338,11 +3565,11 @@ void swb_tbe_dec_fx( move32(); } } - IF( st_fx->output_Fs == 48000 ) + IF( EQ_32( st_fx->output_Fs, 48000 ) ) { Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); } - IF( st_fx->output_Fs == 16000 ) + IF( EQ_32( st_fx->output_Fs, 16000 ) ) { Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); } @@ -3373,22 +3600,32 @@ void swb_tbe_dec_fx( if ( GainFrame == 0 ) { tmp = 31; + move16(); } L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ tmp1 = 0; + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { - L_tmp1 = Mult_32_16( L_tmp, GainShape[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + Word16 idx = 0; + IF( i != 0 ) + { + idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); + } + L_tmp1 = Mult_32_16( L_tmp, GainShape[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ + move16(); tmp = norm_s( tmp1 ); if ( tmp1 == 0 ) { tmp = 15; + move16(); } FOR( i = 0; i < L_FRAME16k; i++ ) @@ -3447,6 +3684,7 @@ void swb_tbe_dec_fx( hBWE_TD->GainFrame_prevfrm_fx = GainFrame; move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; + move16(); if ( !st_fx->bfi ) { @@ -3468,7 +3706,9 @@ void swb_tbe_dec_fx( } hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; + move32(); hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; + move32(); *Q_synth = Q_bwe_exc; move16(); st_fx->prev_Q_bwe_syn2 = Q_bwe_exc; @@ -3523,7 +3763,7 @@ static void gradientGainShape( /* get the first gainshape template */ test(); test(); - IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && GainGradFEC[0] > 0 ) + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && ( GainGradFEC[0] > 0 ) ) { GainShapeTemp[0] = add( shr( st_fx->GainShape_Delay[7], 1 ), GainGradFEC[0] ); move16(); @@ -3545,7 +3785,7 @@ static void gradientGainShape( tmp = mult_r( tmp, 26214 ); /* 0.8 in Q15 tmp*(8/10) */ test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] > 0 ) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] > 0 ) ) { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -3558,7 +3798,7 @@ static void gradientGainShape( ELSE { test(); - IF( ( GT_16( tmp, GainGrad1[1] ) ) && GainGrad1[1] < 0 ) + IF( ( GT_16( tmp, GainGrad1[1] ) ) && ( GainGrad1[1] < 0 ) ) { FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -3584,7 +3824,7 @@ static void gradientGainShape( test(); test(); test(); - IF( ( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) && st_fx->nbLostCmpt == 1 ) + IF( ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -3594,19 +3834,20 @@ static void gradientGainShape( IF( GT_16( 8192, tmp ) ) { - GainShape[i * 4 + j] = shl( tmp, 2 ); + GainShape[add( i * 4, j )] = shl( tmp, 2 ); move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape[i * 4 + j] = 32767; + GainShape[add( i * 4, j )] = 32767; move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); } - ELSE IF( st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS ) + ELSE IF( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -3614,29 +3855,31 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); + GainShape[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - GainShape[i * 4 + j] = 32767; + GainShape[add( i * 4, j )] = 32767; move16(); } } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + move16(); } - ELSE IF( st_fx->nbLostCmpt > 1 ) + ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { FOR( j = 0; j < 4; j++ ) { - GainShape[i * 4 + j] = GainShapeTemp[i]; + GainShape[add( i * 4, j )] = GainShapeTemp[i]; move16(); } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + move16(); } ELSE { @@ -3646,20 +3889,22 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape[i * 4 + j] = shl( GainShapeTemp[i], 1 ); + GainShape[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); move16(); } ELSE { - GainShape[i * 4 + j] = 32767; + GainShape[add( i * 4, j )] = 32767; move16(); } } } hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + move16(); } *GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, hBWE_TD->GainAttn_fx ); /* Q18 */ + move32(); } /*-------------------------------------------------------------------* @@ -3813,6 +4058,7 @@ void ivas_dequantizeSHBparams_fx_9_1( const Word16 *cb_stage; Word16 predictor_bits; Word16 nbits = NUM_BITS_SHB_MSLVQ; + move16(); hBWE_TD = st_fx->hBWE_TD; /* LSFs */ @@ -3824,29 +4070,29 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idxFrameGain = hBWE_TD->gFrame_WB; + move16(); idxLSF = hBWE_TD->lsf_WB; + move16(); } ELSE { - idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); - idxLSF = get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); + idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); } - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB ); + Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); Copy32( SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1 ); } ELSE { *uv_flag = (Word16) get_next_indice( st_fx, 1 ); - idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); move16(); + idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); - move16(); idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_WB_LSF ); - move16(); - Copy( wb_bwe_lsfvq_cbook_8bit_fx + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4 ); + Copy( wb_bwe_lsfvq_cbook_8bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_WB ), Q_lsf, LPC_SHB_ORDER_WB ); + Copy( HBCB_SubGain5bit_fx + i_mult( idxSubGain, NUM_SHB_SUBFR / 4 ), Q_combined_gains, NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -3858,6 +4104,7 @@ void ivas_dequantizeSHBparams_fx_9_1( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ + move16(); } FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) @@ -3877,40 +4124,47 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idxSubGain = hBWE_TD->idxSubGains; + move16(); idxFrameGain = hBWE_TD->idxFrameGain; + move16(); } ELSE { idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); - IF( st_fx->extl_brate == SWB_TBE_1k75 ) + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); + idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN_1k75 ); } ELSE { - idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); } } /* Multi Source Flag */ - IF( st_fx->element_mode >= IVAS_CPE_DFT && !( st_fx->element_mode == IVAS_CPE_TD && st_fx->tdm_LRTD_flag ) ) + test(); + test(); + IF( GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) { - *MSFlag = get_next_indice( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + *MSFlag = (Word16) get_next_indice( st_fx, STEREO_ICBWE_MSFLAG_BITS ); + move16(); } ELSE { *MSFlag = 0; + move16(); } - test(); - IF( st_fx->extl_brate >= SWB_TBE_2k8 ) + + IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) { IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; + move16(); } ELSE { - idx_shb_fr_gain = get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + idx_shb_fr_gain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); } temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ @@ -3921,7 +4175,8 @@ void ivas_dequantizeSHBparams_fx_9_1( L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); - *Q_shb_ener_sf = L_shl( L_tmp, exp - 14 + 0 ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /*exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + move32(); FOR( i = 0; i < 5; i++ ) { @@ -3932,7 +4187,7 @@ void ivas_dequantizeSHBparams_fx_9_1( } ELSE { - idx_res_gs[i] = get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); + idx_res_gs[i] = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], @@ -3959,17 +4214,20 @@ void ivas_dequantizeSHBparams_fx_9_1( ELSE { *Q_shb_ener_sf = L_deposit_l( 0 ); - IF( st_fx->extl_brate == SWB_TBE_1k10 || st_fx->extl_brate == SWB_TBE_1k75 ) + move32(); + test(); + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { - idx_mixFac = get_next_indice( st_fx, NUM_BITS_SHB_VF ); + idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); *Q_mixFactors = usdequant_fx( idx_mixFac, 0 /* 0.0f in Q15*/, 2341 /*1.0f / ((1 << NUM_BITS_SHB_VF) - 1) in Q14*/ ); + move16(); } ELSE { *Q_mixFactors = 0; + move16(); } //*Q_mixFactors = 0; - move16(); set16_fx( Q_shb_res_gshape, 0, 5 ); } @@ -3981,51 +4239,61 @@ void ivas_dequantizeSHBparams_fx_9_1( test(); test(); test(); - IF( ( st_fx->extl_brate == SWB_TBE_0k95 || st_fx->extl_brate == SWB_TBE_1k10 ) && st_fx->codec_mode == MODE1 ) + test(); + test(); + test(); + test(); + IF( ( EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) && EQ_16( st_fx->codec_mode, MODE1 ) ) { set16_fx( lsf_idx, 0, 5 ); - lsf_idx[0] = get_next_indice( st_fx, 8 ); + lsf_idx[0] = (Word16) get_next_indice( st_fx, 8 ); + move16(); grid_idx = 0; + move16(); m_idx = 0; + move16(); - Copy( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); + Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); } - ELSE IF( st_fx->rf_flag == 0 && !( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate == ACELP_9k60 ) || ( st_fx->element_mode == EVS_MONO && ( st_fx->total_brate == 0 ) && ( ( st_fx->last_total_brate == ACELP_9k60 ) || ( st_fx->last_total_brate == ACELP_13k20 && st_fx->rf_flag_last ) ) ) ) ) + ELSE IF( ( st_fx->rf_flag == 0 ) && !( ( ( st_fx->element_mode == EVS_MONO ) && EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->element_mode == EVS_MONO ) && ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && st_fx->rf_flag_last ) ) ) ) ) { - IF( st_fx->extl_brate == SWB_TBE_1k75 ) + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { /* read multi-stage LVQ quantizer */ - IF( nbits >= 19 ) + IF( GE_16( nbits, 19 ) ) { cb_stage = cb_LSF_BWE_fx[0]; + move16(); } ELSE { cb_stage = cb_LSF_BWE_fx[1]; + move16(); } set16_fx( lsf_q, 0, LPC_SHB_ORDER ); /* VQ part */ - num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; + num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; Idx = get_next_indice( st_fx, num_bits_lvq ); - v_add_16( lsf_q, cb_stage + Idx * 6, lsf_q, 6 ); + v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ - num_bits_lvq = nbits - num_bits_lvq - config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; - predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2]; + num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )] ); + predictor_bits = config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )]; Idx_pred = 0; + move16(); - IF( num_bits_lvq == 16 ) + IF( EQ_16( num_bits_lvq, 16 ) ) { /* MSLVQ part */ - Idx_lvq = get_next_indice( st_fx, num_bits_lvq - 1 ) + ( ( get_next_indice( st_fx, 1 ) ) << 15 ); + Idx_lvq = L_add( get_next_indice( st_fx, sub( num_bits_lvq, 1 ) ), L_shl( get_next_indice( st_fx, 1 ), 15 ) ); deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, 0 ); } ELSE { /* MSLVQ part */ Idx_lvq = get_next_indice( st_fx, num_bits_lvq ); - deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, ( nbits < 19 ) ); + deindex_lvq_SHB_fx( Idx_lvq, out, num_bits_lvq, extract_l( LT_16( nbits, 19 ) ) ); } /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */ @@ -4035,19 +4303,22 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( predictor_bits == 0 ) { lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, LastCoefPred_0bit_fx, LATTICE_DIM ); + move16(); lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_0bit_fx[LATTICE_DIM + 1], LATTICE_DIM ); + move16(); } ELSE { - Idx_pred = get_next_indice( st_fx, 1 ); - - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM ); + Idx_pred = (Word16) get_next_indice( st_fx, 1 ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); + move16(); + lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], LATTICE_DIM ); + move16(); } - IF( nbits < NUM_BITS_SHB_MSLVQ ) + IF( LT_16( nbits, NUM_BITS_SHB_MSLVQ ) ) { - Idx_pred = get_next_indice( st_fx, NUM_BITS_SHB_MSLVQ - nbits ); + Idx_pred = (Word16) get_next_indice( st_fx, sub( NUM_BITS_SHB_MSLVQ, nbits ) ); } v_add_16( SHB_LSF_mean_fx, lsf_q, lsf_q, LPC_SHB_ORDER ); @@ -4083,11 +4354,11 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { m_idx = hBWE_TD->m_idx; + move16(); } ELSE { m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); - move16(); } Dequant_mirror_point_fx( lsf_q, m_idx, &m ); @@ -4096,17 +4367,19 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( GT_16( m, MAX_LSF_FX ) ) { st_fx->BER_detect = 1; + move16(); m = MAX_LSF_FX - 1; + move16(); } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { grid_idx = hBWE_TD->grid_idx; + move16(); } ELSE { grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); - move16(); } Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); @@ -4117,7 +4390,9 @@ void ivas_dequantizeSHBparams_fx_9_1( IF( GT_16( lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX ) ) { st_fx->BER_detect = 1; + move16(); lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; + move16(); } Q_lsf[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); move16(); @@ -4128,14 +4403,16 @@ void ivas_dequantizeSHBparams_fx_9_1( set16_fx( lsf_idx, 0, 5 ); Copy( hBWE_TD->lsf_idx, lsf_idx, 5 ); grid_idx = 0; + move16(); m_idx = 0; - Copy( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); + move16(); + Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); } space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); /* Dequantize subgain indices */ - j = idxSubGain * NUM_SHB_SUBGAINS; + j = i_mult( idxSubGain, NUM_SHB_SUBGAINS ); move16(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -4153,24 +4430,32 @@ void ivas_dequantizeSHBparams_fx_9_1( FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) { - Q_subgain[i] = Q_subgain[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + Q_subgain[i] = Q_subgain[idx]; move16(); } /* Frame gain */ - IF( st_fx->extl_brate == SWB_TBE_1k75 ) + IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { *Q_framegrain = L_mac( SHB_GAIN_QLOW_1k75_FX, idxFrameGain, SHB_GAIN_QDELTA_1k75_FX ); + move32(); } ELSE { *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); - } - move32(); /*Q18*/ + move32(); + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ + move32(); } return; @@ -4233,23 +4518,23 @@ static void dequantizeSHBparams_fx_9_1( IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) { idxFrameGain = hBWE_TD->gFrame_WB; + move16(); idxLSF = hBWE_TD->lsf_WB; + move16(); - Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB ); + Copy( lbr_wb_bwe_lsfvq_cbook_2bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_LBR_WB ), Q_lsf, LPC_SHB_ORDER_LBR_WB ); set16_fx( Q_subgain, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); Copy32( SHBCB_FrameGain16_fx + idxFrameGain, Q_framegrain, 1 ); } ELSE { *uv_flag = (Word16) get_next_indice( st_fx, 1 ); - idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); move16(); + idxSubGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain ); - move16(); idxLSF = (Word16) get_next_indice( st_fx, NUM_BITS_WB_LSF ); - move16(); - Copy( wb_bwe_lsfvq_cbook_8bit_fx + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB ); - Copy( HBCB_SubGain5bit_fx + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4 ); + Copy( wb_bwe_lsfvq_cbook_8bit_fx + i_mult( idxLSF, LPC_SHB_ORDER_WB ), Q_lsf, LPC_SHB_ORDER_WB ); + Copy( HBCB_SubGain5bit_fx + i_mult( idxSubGain, NUM_SHB_SUBFR / 4 ), Q_combined_gains, NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -4261,6 +4546,7 @@ static void dequantizeSHBparams_fx_9_1( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ Q_combined_gains[i] = shl( tmp, add( exp, 1 ) ); /* Q15 */ + move16(); } FOR( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 ) @@ -4280,7 +4566,9 @@ static void dequantizeSHBparams_fx_9_1( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idxSubGain = hBWE_TD->idxSubGains; + move16(); idxFrameGain = hBWE_TD->idxFrameGain; + move16(); } ELSE { @@ -4294,10 +4582,11 @@ static void dequantizeSHBparams_fx_9_1( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain; + move16(); } ELSE { - idx_shb_fr_gain = get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + idx_shb_fr_gain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); } temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q12 */ @@ -4308,7 +4597,8 @@ static void dequantizeSHBparams_fx_9_1( L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); - *Q_shb_ener_sf = L_shl( L_tmp, exp - 14 + 0 ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + *Q_shb_ener_sf = L_shl( L_tmp, sub( exp, 14 ) /* exp - 14 + 0 */ ); /* In Q_ener: 2*Q_shb+1, Q_shb = 0; */ + move32(); FOR( i = 0; i < 5; i++ ) { @@ -4319,7 +4609,7 @@ static void dequantizeSHBparams_fx_9_1( } ELSE { - idx_res_gs[i] = get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); + idx_res_gs[i] = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], @@ -4346,6 +4636,7 @@ static void dequantizeSHBparams_fx_9_1( ELSE { *Q_shb_ener_sf = L_deposit_l( 0 ); + move32(); *Q_mixFactors = 0; move16(); set16_fx( Q_shb_res_gshape, 0, 5 ); @@ -4359,7 +4650,7 @@ static void dequantizeSHBparams_fx_9_1( test(); test(); test(); - IF( ( st_fx->rf_flag == 0 ) && !( ( EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( st_fx->total_brate == 0 ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && EQ_16( st_fx->rf_flag_last, 1 ) ) ) ) ) ) + IF( ( ( st_fx->rf_flag == 0 ) ) && !( ( EQ_32( st_fx->total_brate, ACELP_9k60 ) ) || ( ( ( st_fx->total_brate == 0 ) ) && ( ( EQ_32( st_fx->last_total_brate, ACELP_9k60 ) ) || ( EQ_32( st_fx->last_total_brate, ACELP_13k20 ) && EQ_16( st_fx->rf_flag_last, 1 ) ) ) ) ) ) { /* LSFs */ @@ -4390,11 +4681,11 @@ static void dequantizeSHBparams_fx_9_1( IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { m_idx = hBWE_TD->m_idx; + move16(); } ELSE { m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); - move16(); } Dequant_mirror_point_fx( lsf_q, m_idx, &m ); @@ -4403,17 +4694,19 @@ static void dequantizeSHBparams_fx_9_1( IF( GT_16( m, MAX_LSF_FX ) ) { st_fx->BER_detect = 1; + move16(); m = MAX_LSF_FX - 1; + move16(); } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { grid_idx = hBWE_TD->grid_idx; + move16(); } ELSE { grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); - move16(); } Map_higher_LSF_fx( lsf_q, m, lsf_grid_fx[grid_idx] ); @@ -4424,7 +4717,9 @@ static void dequantizeSHBparams_fx_9_1( IF( GT_16( lsf_q[LPC_SHB_ORDER - 1 - i], MAX_LSF_FX ) ) { st_fx->BER_detect = 1; + move16(); lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF_FX - 1; + move16(); } Q_lsf[i] = sub( 16384, lsf_q[LPC_SHB_ORDER - 1 - i] ); move16(); @@ -4435,20 +4730,23 @@ static void dequantizeSHBparams_fx_9_1( set16_fx( lsf_idx, 0, 5 ); Copy( hBWE_TD->lsf_idx, lsf_idx, 5 ); grid_idx = 0; + move16(); m_idx = 0; - Copy( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER ); + move16(); + Copy( swb_tbe_lsfvq_cbook_8b + i_mult( lsf_idx[0], LPC_SHB_ORDER ), Q_lsf, LPC_SHB_ORDER ); } space_lsfs_fx( Q_lsf, LPC_SHB_ORDER ); /* Dequantize subgain indices */ - j = idxSubGain * NUM_SHB_SUBGAINS; + j = i_mult( idxSubGain, NUM_SHB_SUBGAINS ); move16(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { /* Q_subgain[i] = (float) pow(10.0, SHBCB_SubGain5bit[j++]); */ - L_tmp = L_mult( SHBCB_SubGain5bit_fx[j++], 27213 ); /*Q28 3.321928 in Q13 */ + L_tmp = L_mult( SHBCB_SubGain5bit_fx[j], 27213 ); /*Q28 3.321928 in Q13 */ + j = add( j, 1 ); L_tmp = L_shr( L_tmp, 12 ); frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ @@ -4460,17 +4758,24 @@ static void dequantizeSHBparams_fx_9_1( FOR( i = NUM_SHB_SUBFR - 1; i >= 0; i-- ) { - Q_subgain[i] = Q_subgain[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR]; + Word16 idx = 0; + move16(); + IF( i != 0 ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + Q_subgain[i] = Q_subgain[idx]; move16(); } /* Frame gain */ - *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); - move32(); /*Q18*/ + *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); /*Q18*/ + move32(); L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); *Q_framegrain = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ + move32(); } return; @@ -4491,7 +4796,9 @@ void fb_tbe_dec_fx( { Word16 i; Word16 ratio = 0; + move16(); Word32 fb_exc_energy = 0; + move32(); Word16 fb_synth[L_FRAME48k]; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st->hBWE_TD; @@ -4516,7 +4823,7 @@ void fb_tbe_dec_fx( ratio = shl( 1, i ); #endif } - ELSE if ( EQ_16( st->extl, FB_TBE ) && st->bfi ) + ELSE IF( EQ_16( st->extl, FB_TBE ) && st->bfi ) { ratio = hBWE_TD->prev_fbbwe_ratio_fx; move16(); @@ -4554,16 +4861,18 @@ void fb_tbe_dec_ivas_fx( { Word16 i; Word16 ratio = 0; + move16(); Word32 fb_exc_energy = 0; + move32(); Word16 fb_synth[L_FRAME48k]; TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st->hBWE_TD; /* decode FB slope information */ - test(); - test(); - if ( output_frame == L_FRAME48k ) + IF( EQ_16( output_frame, L_FRAME48k ) ) { + test(); + test(); IF( EQ_16( st->extl, FB_TBE ) && !st->bfi ) { IF( EQ_16( st->codec_mode, MODE2 ) ) @@ -4581,7 +4890,7 @@ void fb_tbe_dec_ivas_fx( ratio = shl( 1, i ); #endif } - ELSE if ( EQ_16( st->extl, FB_TBE ) && st->bfi ) + ELSE IF( EQ_16( st->extl, FB_TBE ) && st->bfi ) { ratio = hBWE_TD->prev_fbbwe_ratio_fx; move16(); @@ -4592,6 +4901,7 @@ void fb_tbe_dec_ivas_fx( IF( !st->bfi ) { st->next_bit_pos = add( st->next_bit_pos, NUM_BITS_FB_FRAMEGAIN ); + move16(); } return; @@ -4601,7 +4911,8 @@ void fb_tbe_dec_ivas_fx( /* FB TBE synthesis */ synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp ); - IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 0 ) ) + test(); + IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->idchan == 0 ) ) { Copy_Scale_sig( fb_synth, fb_synth_ref, L_FRAME48k, sub( Q_fb_synth_ref, hb_synth_exp ) ); // scaling is required } @@ -4632,30 +4943,33 @@ void tbe_read_bitstream_fx( IF( ( EQ_16( st_fx->rf_flag, 1 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) && EQ_16( st_fx->bwidth, WB ) ) { /* WB LSF */ - hBWE_TD->lsf_WB = get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); + hBWE_TD->lsf_WB = (Word16) get_next_indice( st_fx, NUM_BITS_LBR_WB_LSF ); + move16(); /* WB frame gain */ - hBWE_TD->gFrame_WB = get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + hBWE_TD->gFrame_WB = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FrameGain_LBR_WB ); + move16(); } ELSE IF( ( GE_32( st_fx->total_brate, ACELP_9k60 ) ) && ( LE_32( st_fx->total_brate, ACELP_32k ) ) && ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) { test(); - IF( ( st_fx->rf_flag == 0 ) && ( GT_32( st_fx->total_brate, ACELP_9k60 ) ) ) + IF( ( ( st_fx->rf_flag == 0 ) ) && ( GT_32( st_fx->total_brate, ACELP_9k60 ) ) ) { FOR( i = 0; i < NUM_Q_LSF; i++ ) { - hBWE_TD->lsf_idx[i] = get_next_indice( st_fx, lsf_q_num_bits[i] ); + hBWE_TD->lsf_idx[i] = (Word16) get_next_indice( st_fx, lsf_q_num_bits[i] ); move16(); } - hBWE_TD->m_idx = get_next_indice( st_fx, MIRROR_POINT_BITS ); - - hBWE_TD->grid_idx = get_next_indice( st_fx, NUM_LSF_GRID_BITS ); + hBWE_TD->m_idx = (Word16) get_next_indice( st_fx, MIRROR_POINT_BITS ); + move16(); + hBWE_TD->grid_idx = (Word16) get_next_indice( st_fx, NUM_LSF_GRID_BITS ); + move16(); } ELSE { - hBWE_TD->lsf_idx[0] = get_next_indice( st_fx, 8 ); + hBWE_TD->lsf_idx[0] = (Word16) get_next_indice( st_fx, 8 ); move16(); hBWE_TD->m_idx = 0; move16(); @@ -4664,31 +4978,37 @@ void tbe_read_bitstream_fx( } /* shape gains */ - hBWE_TD->idxSubGains = get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); + hBWE_TD->idxSubGains = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_SUBGAINS ); + move16(); /* frame gain */ - hBWE_TD->idxFrameGain = get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + hBWE_TD->idxFrameGain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_FRAMEGAIN ); + move16(); IF( GE_32( st_fx->total_brate, ACELP_24k40 ) ) { /* sub frame energy*/ - hBWE_TD->idx_shb_fr_gain = get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + hBWE_TD->idx_shb_fr_gain = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_ENER_SF ); + move16(); /* gain shapes residual */ FOR( i = 0; i < NB_SUBFR16k; i++ ) { - hBWE_TD->idx_res_gs[i] = get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); + hBWE_TD->idx_res_gs[i] = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } /* voicing factor */ - hBWE_TD->idx_mixFac = get_next_indice( st_fx, NUM_BITS_SHB_VF ); + hBWE_TD->idx_mixFac = (Word16) get_next_indice( st_fx, NUM_BITS_SHB_VF ); + move16(); } IF( EQ_16( st_fx->tec_tfa, 1 ) ) { - st_fx->tec_flag = get_next_indice( st_fx, BITS_TEC ); - st_fx->tfa_flag = get_next_indice( st_fx, BITS_TFA ); + st_fx->tec_flag = (Word16) get_next_indice( st_fx, BITS_TEC ); + move16(); + st_fx->tfa_flag = (Word16) get_next_indice( st_fx, BITS_TFA ); + move16(); test(); IF( st_fx->tfa_flag && st_fx->tec_flag ) { @@ -4709,7 +5029,8 @@ void tbe_read_bitstream_fx( IF( EQ_16( st_fx->bwidth, FB ) ) { - hBWE_TD->idxGain = get_next_indice( st_fx, 4 ); + hBWE_TD->idxGain = (Word16) get_next_indice( st_fx, 4 ); + move16(); } } @@ -4767,12 +5088,14 @@ void GenTransition_fx( { L_tmp = L_mult( window_shb_32k_fx[i], old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i] ); output[i] = mac_r( L_tmp, window_shb_32k_fx[2 * L_SHB_LAHEAD - 1 - i], syn_overlap_32k[i] ); + move16(); } /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */ FOR( ; i < length; i++ ) { output[i] = old_hb_synth[L_SHB_TRANSITION_LENGTH - 1 - i]; + move16(); } IF( EQ_32( target_fs, 48000 ) ) @@ -4872,6 +5195,7 @@ void TBEreset_dec_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); st_fx->prev_Q_bwe_exc = 31; move16(); } @@ -4905,8 +5229,10 @@ void TBEreset_dec_fx( IF( EQ_16( bandwidth, FB ) ) { st_fx->prev_fb_ener_adjust_fx = 0; + move16(); set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; + move16(); fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } } @@ -4923,10 +5249,11 @@ void TBEreset_dec_ivas_fx( hBWE_TD = st->hBWE_TD; - IF( NE_16( st->last_core, ACELP_CORE ) ) + IF( st->last_core != ACELP_CORE ) { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); st->prev_Q_bwe_exc = 31; move16(); } @@ -4953,19 +5280,23 @@ void TBEreset_dec_ivas_fx( set16_fx( hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); set32_fx( hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /* Q0 1.f */ - hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ + move32(); + hBWE_TD->prev_mix_factor_fx = 32767; /* Q15 1.f */ + move16(); // swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); swb_tbe_reset_synth_ivas_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 ); IF( EQ_16( st->bwidth, FB ) ) { - IF( st->hBWE_FD != NULL ) + if ( st->hBWE_FD != NULL ) { st->prev_fb_ener_adjust_fx = 0; + move16(); } set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph_fx = 0; + move16(); fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } } @@ -5049,6 +5380,7 @@ void td_bwe_dec_init_ivas_fx( set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); + move32(); return; } @@ -5124,7 +5456,7 @@ void td_bwe_dec_init_fx( hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); - + move32(); return; } diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index d291ba3e4..67399e2dd 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -27,6 +27,7 @@ void syn_output_fx( /*tmp = sub(Q_syn2, 1); */ tmp = Q_syn2; + move16(); /*-----------------------------------------------------------------* * Output synthesis signal with compensation for saturation @@ -45,6 +46,7 @@ void syn_output_fx( #else synth_out[i] = round_fx( L_shr( L_tmp, tmp ) ); #endif + move16(); } } ELSE @@ -72,6 +74,7 @@ void unscale_AGC( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* @@ -109,6 +112,7 @@ void unscale_AGC( L_tmp = L_shr( L_tmp, -1 ); /* saturation can occur here */ y[0] = round_fx( L_tmp ); + move16(); FOR( i = 1; i < n; i++ ) { @@ -119,10 +123,11 @@ void unscale_AGC( L_tmp = L_msu( L_tmp, fac, x[i] ); L_tmp = L_msu( L_tmp, fac, x[i - 1] ); y[i] = round_fx( L_tmp ); + move16(); } mem[0] = fac; move16(); - mem[1] = shr( x[sub( i, 1 )], 1 ); + mem[1] = shr( x[i - 1], 1 ); move16(); } diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 894372201..0e3fa5f90 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -34,6 +34,7 @@ void tcq_core_LR_dec_fx( Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; Word16 flag_wbnb = 0; + move16(); Word16 USQ_TCQ[NB_SFM]; /* TCQ is selected by default*/ Word16 nb_bytes, pulsesnum, nz; @@ -45,19 +46,28 @@ void tcq_core_LR_dec_fx( TCQ_BITSTREAM bs_fx, *pbs_fx; Word16 nzb = 0; + move16(); Word16 nzbands = 0; + move16(); Word16 lsbtcq_bits = TCQ_AMP; + move16(); Word16 tcq_arbits = 2; + move16(); /* LSB TCQ variables*/ Word16 dpath[280]; Word16 bcount = 0; + move16(); Word32 bsub_fx = 0; + move32(); Word16 mbuffer_fx[560]; Word32 leftbits = 0; + move32(); Word32 sepbits = 0; + move32(); Word32 divider = 0; + move32(); #ifndef BASOP_NOGLOB_DECLARE_LOCAL if ( Overflow == 1 ) @@ -74,7 +84,7 @@ void tcq_core_LR_dec_fx( test(); test(); - IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && *is_transient == 0 ) + IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { flag_wbnb = 1; move16(); @@ -89,7 +99,9 @@ void tcq_core_LR_dec_fx( pbs_fx->curPos = 7; move16(); pbs_fx->numbits = L_deposit_l( 0 ); + move32(); pbs_fx->numByte = L_deposit_l( 0 ); + move32(); /* Bits distribution analysis*/ FOR( i = 0; i < BANDS; i++ ) @@ -125,15 +137,17 @@ void tcq_core_LR_dec_fx( { bsub_fx = L_add( bsub_fx, 2048 ); } - FOR( j = BANDS - 1; j >= 0; j-- ) + FOR( j = sub( BANDS, 1 ); j >= 0; j-- ) { IF( Rk_fx[j] > 0 ) { Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + move32(); IF( Rk_fx[j] < 0 ) { bsub_fx = L_sub( bsub_fx, L_add( ar_div( bsub_fx, nzb ), Rk_fx[j] ) ); Rk_fx[j] = L_deposit_l( 0 ); + move32(); } ELSE { @@ -157,8 +171,9 @@ void tcq_core_LR_dec_fx( IF( k > 0 ) { Word16 tmp; - tmp = (UWord8) get_next_indice( st_fx, k ); + tmp = (Word16) get_next_indice( st_fx, k ); pbs_fx->buf[nb_bytes] = (UWord8) shl( tmp, sub( 8, k ) ); + move16(); /* i++; nb_bytes++; */ i = add( i, 1 ); @@ -183,7 +198,7 @@ void tcq_core_LR_dec_fx( test(); test(); - IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && *is_transient == 0 ) + IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { surplus_fx = -131072; move32(); /*16 */ @@ -194,6 +209,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( j = 0; j < BANDS; j++ ) { + test(); IF( EQ_16( j, k_num[0] ) || EQ_16( j, k_num[1] ) ) { sepbits = L_add( sepbits, Rk_fx[k_sort[j]] ); @@ -215,7 +231,7 @@ void tcq_core_LR_dec_fx( { test(); test(); - IF( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) + IF( ( Rk_fx[k_sort[k]] > 0 ) && ( USQ_TCQ[k_sort[k]] == 0 ) ) { /* When number of bits per band is less than arithmetic bits overhead, this band is not encoded. @@ -228,7 +244,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; + inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; move16(); } IF( surplus_fx != 0 ) @@ -253,7 +269,7 @@ void tcq_core_LR_dec_fx( nzbands--; move16(); } - ELSE IF( Rk_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) + ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) { /* When number of bits per band is less than arithmetic bits overhead, this band is not encoded. @@ -266,7 +282,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; + inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; move16(); } IF( surplus_fx != 0 ) @@ -295,7 +311,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; + inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; move16(); } } @@ -305,25 +321,28 @@ void tcq_core_LR_dec_fx( delta_fx = L_deposit_l( 0 ); test(); - IF( Rk_fx[k_sort[k]] > 0 && surplus_fx < 0 ) + IF( ( Rk_fx[k_sort[k]] > 0 ) && ( surplus_fx < 0 ) ) { - IF( nzbands <= 1 ) + IF( LE_16( nzbands, 1 ) ) { divider = 0; + move32(); } ELSE { divider = 2; + move32(); } IF( L_add( L_add( surplus_fx, sepbits ), ar_div( leftbits, divider ) ) < 0 ) { /* Overflow possible => start to distribute negative surplus */ - delta_fx = ar_div( surplus_fx + sepbits, nzbands ); + delta_fx = ar_div( L_add( surplus_fx, sepbits ), nzbands ); } - else + ELSE { delta_fx = 0; + move32(); } surplus_fx = L_sub( surplus_fx, delta_fx ); } @@ -336,13 +355,16 @@ void tcq_core_LR_dec_fx( IF( ( GT_32( surplus_fx, 524288 ) && EQ_16( input_frame, L_FRAME8k ) ) || ( GT_32( surplus_fx, 786432 ) && EQ_16( input_frame, L_FRAME16k ) ) ) { bit_surplus_fx[0] = Mult_32_16( surplus_fx, 24576 ); /* Q16 */ - bit_surplus_fx[1] = Mult_32_16( surplus_fx, 8192 ); /* Q16 */ + move32(); + bit_surplus_fx[1] = Mult_32_16( surplus_fx, 8192 ); /* Q16 */ + move32(); } ELSE { bit_surplus_fx[0] = surplus_fx; move32(); bit_surplus_fx[1] = L_deposit_l( 0 ); + move32(); } FOR( k = 0; k < BANDS; k++ ) @@ -356,7 +378,7 @@ void tcq_core_LR_dec_fx( test(); test(); - IF( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 0 ) + IF( ( Rk_fx[k_sort[k]] > 0 ) && ( USQ_TCQ[k_sort[k]] == 0 ) ) { /* get number of pulses */ pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); @@ -366,7 +388,7 @@ void tcq_core_LR_dec_fx( decode_mangitude_tcq_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, nz, &positions_fx[band_start[k_sort[k]]], &inp_vector_fx[band_start[k_sort[k]]], &surplus_fx ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - ELSE IF( Rk_fx[k_sort[k]] > 0 && USQ_TCQ[k_sort[k]] == 1 ) + ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) { pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]], &surplus_fx ); @@ -381,7 +403,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; + inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; move16(); } } @@ -398,7 +420,7 @@ void tcq_core_LR_dec_fx( { IF( Rk_fx[k_sort[k]] > 0 ) { - pulsesnum = GetScale_fx( band_width[k_sort[k]], Rk_fx[k_sort[k]] + delta_fx, &surplus_fx ); + pulsesnum = GetScale_fx( band_width[k_sort[k]], L_add( Rk_fx[k_sort[k]], delta_fx ), &surplus_fx ); decode_position_ari_fx( pardec_fx, band_width[k_sort[k]], pulsesnum, &nz, &positions_fx[band_start[k_sort[k]]] ); @@ -414,7 +436,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[band_start[k_sort[k]] + i] = 0; + inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; move16(); } } @@ -424,7 +446,7 @@ void tcq_core_LR_dec_fx( /* surplus distribution */ test(); - IF( surplus_fx > 0 && nzbands > 0 ) + IF( ( surplus_fx > 0 ) && ( nzbands > 0 ) ) { delta_fx = ar_div( surplus_fx, nzbands ); surplus_fx = L_sub( surplus_fx, delta_fx ); @@ -435,7 +457,7 @@ void tcq_core_LR_dec_fx( /* Load TCQ path from bitstream */ LoadTCQdata_fx( pardec_fx, dpath, lsbtcq_bits ); - TCQLSBdec_fx( dpath, mbuffer_fx, 2 * lsbtcq_bits ); + TCQLSBdec_fx( dpath, mbuffer_fx, i_mult( 2, lsbtcq_bits ) ); ar_decoder_done_fx( pardec_fx ); @@ -456,7 +478,7 @@ void tcq_core_LR_dec_fx( { test(); test(); - IF( Rk_fx[k_sort[k]] > 0 && k != k_num[0] && k != k_num[1] ) + IF( ( Rk_fx[k_sort[k]] > 0 ) && NE_16( k, k_num[0] ) && NE_16( k, k_num[1] ) ) { RestoreTCQdec_fx( &inp_vector_fx[band_start[k_sort[k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); } @@ -466,7 +488,7 @@ void tcq_core_LR_dec_fx( { test(); test(); - IF( Rk_fx[k_sort[k]] > 0 && ( k == k_num[0] || k == k_num[1] ) ) + IF( ( Rk_fx[k_sort[k]] > 0 ) && ( EQ_16( k, k_num[0] ) || EQ_16( k, k_num[1] ) ) ) { RestoreTCQdec_fx( &inp_vector_fx[band_start[k_sort[k]]], band_width[k_sort[k]], &bcount, mbuffer_fx ); } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index be8d5237d..7eb2d7576 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -1,385 +1,399 @@ -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - - -#include -#include -#include -#include -#include "options.h" -#include "prot_fx1.h" -#include "prot_fx2.h" -#include "rom_basop_util.h" -#include "basop_util.h" -#include "rom_com.h" - -/*--------------------------------------------------------------- - * tcx_decoder_memory_update() - * - * - *--------------------------------------------------------------*/ -void tcx_decoder_memory_update( - Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ - Word16 *synthout, /* o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, /* i/o: decoder memory state */ - Word8 fb /* i: fullband flag */ -) -{ - Word16 tmp; - Word16 *synth; - Word16 buf[1 + M + LFAC + L_FRAME_PLUS]; - Word16 L_frame_glob; - Word16 preemph; - - L_frame_glob = st->L_frame; - preemph = st->preemph_fac; - move16(); - - /* Output synth */ - Copy( xn_buf, synthout, L_frame_glob ); - - /* Update synth */ - - synth = buf + M + 1; - Copy( st->syn, buf, M + 1 ); - Copy( xn_buf, synth, L_frame_glob ); - Copy( synth + sub( L_frame_glob, M + 1 ), st->syn, M + 1 ); - -#ifndef FIX_778_STEREO_BRATE_SWITCHING - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) -#endif - { - IF( !fb ) /* TV2FhG -> Condition differs from floating point */ - { - - /* Emphasis of synth -> synth_pe */ - tmp = synth[-M - 1]; - move16(); -#ifdef FIX_778_STEREO_BRATE_SWITCHING - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { -#endif - st->Q_syn = E_UTIL_f_preemph3( synth - M, preemph, add( M, L_frame_glob ), &tmp, 1 ); - st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; -#ifdef FIX_778_STEREO_BRATE_SWITCHING - } - ELSE - { - E_UTIL_f_preemph2( 2, synth - M, preemph, add( M, L_frame_glob ), &tmp ); - st->prev_Q_syn = st->Q_syn = 0; /* in case of MDCT, Q0 seems to be used*/ - } -#endif - Copy( synth + sub( L_frame_glob, M ), st->mem_syn2_fx, M ); - Copy( synth + sub( L_frame_glob, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); -#ifdef FIX_778_STEREO_BRATE_SWITCHING - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { -#endif - test(); - IF( st->tcxonly == 0 || LE_16( L_frame_glob, L_FRAME16k ) ) - { - /* Update excitation */ - IF( NE_16( st->Q_syn + 1, st->Q_exc ) ) - { - Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, sub( st->Q_syn + 1, st->Q_exc ) ); - } - st->Q_exc = st->Q_syn + 1; - st->Q_subfr[0] = st->Q_subfr[1] = st->Q_subfr[2] = st->Q_subfr[3] = st->Q_subfr[4] = st->Q_exc; - - assert( L_frame_glob < L_EXC_MEM_DEC ); - Copy( st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub( L_EXC_MEM_DEC, L_frame_glob ) ); - Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); - } - /* Update old_Aq */ - Copy( A, st->old_Aq_12_8_fx, M + 1 ); -#ifdef FIX_778_STEREO_BRATE_SWITCHING - } -#endif - } - } - return; -} - -/* Returns: number of bits used (including "bits") */ -Word16 tcx_ari_res_invQ_spec( - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ - Word16 L_frame, /* i: number of lines Q0 */ - const Word16 prm[], /* i: bitstream Q0 */ - Word16 target_bits, /* i: number of bits available Q0 */ - Word16 bits, /* i: number of bits used so far Q0 */ - Word16 deadzone, /* i: quantizer deadzone Q15 */ - const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ -) -{ - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; - Word32 L_tmp; - Word16 s; - - - /* Limit the number of residual bits */ - target_bits = s_min( target_bits, NPRM_RESQ ); - - - /* Requantize the spectrum line-by-line */ - /* fac_m = deadzone * 0.5f; */ - num_zeros = 0; - move16(); - - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, target_bits ) ) /* no bits left */ - { - BREAK; - } - - IF( x_Q[i] != 0 ) - { - sign = x_fac[i]; - move16(); - if ( x_Q[i] < 0 ) - sign = negate( sign ); - - /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ - x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); - move32(); - bits = add( bits, 1 ); - } - ELSE - { - zeros[num_zeros] = i; - move16(); - num_zeros = add( num_zeros, 1 ); - } - } - - /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r( 1417339264l /*0.33f*2.0f Q31*/, deadzone, 21627 /*0.33f*2.0f Q15*/ ); /* Q15 */ - target_bits = sub( target_bits, 1 ); /* reserve 1 bit for the check below */ - - s = sub( x_Q_e, 1 ); - FOR( j = 0; j < num_zeros; j++ ) - { - IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */ - { - BREAK; - } - - i = zeros[j]; - move16(); - - IF( prm[bits] != 0 ) - { - bits = add( bits, 1 ); - L_tmp = L_mult( fac_p, x_fac[i] ); /* Q30 */ - if ( prm[bits] == 0 ) - L_tmp = L_negate( L_tmp ); - x_Q[i] = L_shr( L_tmp, s ); - move32(); - } - bits = add( bits, 1 ); - } - - - return bits; -} -/*--------------------------------------------------------------- - * tcx_res_invQ_gain() - * - * - *--------------------------------------------------------------*/ -Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, - Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits ) -{ - Word16 bits; - Word16 gain, tmp1, tmp2; - - - gain = *gain_tcx; - move16(); - - /* make sure we have a bit of headroom */ - IF( GT_16( gain, 0x7000 ) ) - { - gain = shr( gain, 1 ); - *gain_tcx_e = add( *gain_tcx_e, 1 ); - move16(); - } - - /*Refine the gain quantization*/ - tmp1 = s_min( resQBits, TCX_RES_Q_BITS_GAIN ); - FOR( bits = 0; bits < tmp1; bits++ ) - { - tmp2 = gain_corr_fac[bits]; - move16(); - if ( prm[bits] == 0 ) - { - tmp2 = gain_corr_inv_fac[bits]; - move16(); - } - - gain = mult_r( gain, tmp2 ); - if ( prm[bits] != 0 ) - gain = shl( gain, 1 ); - } - - *gain_tcx = gain; - move16(); - - - return bits; -} - -/*--------------------------------------------------------------- - * tcx_res_invQ_spec() - * - * - *--------------------------------------------------------------*/ -Word16 tcx_res_invQ_spec( - Word32 *x, - Word16 x_e, - Word16 L_frame, - Word16 *prm, - Word16 resQBits, - Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ) -{ - Word16 i; - Word16 fac_m, fac_p; - Word16 lf_deemph_factor, c, s; - Word32 tmp; - - - /* Limit the number of residual bits */ - resQBits = s_min( resQBits, NPRM_RESQ ); - - /* Requantize the spectrum line-by-line */ - fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); - - lf_deemph_factor = 0x4000; - move16(); - s = sub( x_e, 1 ); - - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, resQBits ) ) - { - BREAK; - } - - test(); - test(); - IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) - { - if ( lf_deemph_factors != NULL ) - { - lf_deemph_factor = lf_deemph_factors[i]; - move16(); - } - - IF( prm[bits] == 0 ) - { - - /* Debug initialization to catch illegal cases of x[i] */ - tmp = 0; - - if ( x[i] > 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); - if ( x[i] < 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); - - assert( tmp != 0 ); - - x[i] = L_sub( x[i], L_shr( tmp, s ) ); - move32(); - } - ELSE - { - - /* Debug initialization to catch illegal cases of x[i] */ - tmp = 0; - - if ( x[i] > 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); - if ( x[i] < 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); - - assert( tmp != 0 ); - - x[i] = L_add( x[i], L_shr( tmp, s ) ); - move32(); - } - bits = add( bits, 1 ); - } - } - - /*Quantize zeroed-line of the spectrum*/ - resQBits = sub( resQBits, 1 ); - - IF( lf_deemph_factors == NULL ) - { - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, resQBits ) ) - { - BREAK; - } - - IF( x[i] == 0 ) - { - IF( prm[bits] != 0 ) - { - bits = add( bits, 1 ); - - tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); - if ( prm[bits] == 0 ) - tmp = L_negate( tmp ); - - x[i] = L_shr( tmp, s ); - move32(); - } - bits = add( bits, 1 ); - } - } - } - ELSE - { - c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); - - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, resQBits ) ) - { - BREAK; - } - - test(); - IF( ( x[i] == 0 ) && ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) - { - IF( prm[bits] != 0 ) - { - bits = add( bits, 1 ); - - tmp = L_mult( c, lf_deemph_factors[i] ); - if ( prm[bits] == 0 ) - tmp = L_negate( tmp ); - - x[i] = L_shr( tmp, s ); - move32(); - } - bits = add( bits, 1 ); - } - } - } - - return bits; -} +/*==================================================================================== + EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + ====================================================================================*/ + + +#include +#include +#include +#include +#include "options.h" +#include "prot_fx1.h" +#include "prot_fx2.h" +#include "rom_basop_util.h" +#include "basop_util.h" +#include "rom_com.h" + +/*--------------------------------------------------------------- + * tcx_decoder_memory_update() + * + * + *--------------------------------------------------------------*/ +void tcx_decoder_memory_update( + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer */ + Word16 *synthout, /* o: synth */ + Word16 *A, /* i: Quantized LPC coefficients */ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ +) +{ + Word16 tmp; + Word16 *synth; + Word16 buf[1 + M + LFAC + L_FRAME_PLUS]; + Word16 L_frame_glob; + Word16 preemph; + + L_frame_glob = st->L_frame; + move16(); + preemph = st->preemph_fac; + move16(); + + /* Output synth */ + Copy( xn_buf, synthout, L_frame_glob ); + + /* Update synth */ + + synth = buf + M + 1; + Copy( st->syn, buf, M + 1 ); + Copy( xn_buf, synth, L_frame_glob ); + Copy( synth + sub( L_frame_glob, M + 1 ), st->syn, M + 1 ); + +#ifndef FIX_778_STEREO_BRATE_SWITCHING + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) +#endif + { + IF( !fb ) /* TV2FhG -> Condition differs from floating point */ + { + + /* Emphasis of synth -> synth_pe */ + tmp = synth[-M - 1]; + move16(); +#ifdef FIX_778_STEREO_BRATE_SWITCHING + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { +#endif + st->Q_syn = E_UTIL_f_preemph3( synth - M, preemph, add( M, L_frame_glob ), &tmp, 1 ); + move16(); + st->prev_Q_syn = st->Q_syn = sub( st->Q_syn, 1 ); + move16(); + move16(); +#ifdef FIX_778_STEREO_BRATE_SWITCHING + } + ELSE + { + E_UTIL_f_preemph2( 2, synth - M, preemph, add( M, L_frame_glob ), &tmp ); + st->prev_Q_syn = st->Q_syn = 0; /* in case of MDCT, Q0 seems to be used*/ + move16(); + move16(); + } +#endif + Copy( synth + sub( L_frame_glob, M ), st->mem_syn2_fx, M ); + Copy( synth + sub( L_frame_glob, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); +#ifdef FIX_778_STEREO_BRATE_SWITCHING + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { +#endif + test(); + IF( ( st->tcxonly == 0 ) || LE_16( L_frame_glob, L_FRAME16k ) ) + { + /* Update excitation */ + IF( NE_16( add( st->Q_syn, 1 ), st->Q_exc ) ) + { + Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, sub( add( st->Q_syn, 1 ), st->Q_exc ) ); + } + st->Q_exc = add( st->Q_syn, 1 ); + move16(); + st->Q_subfr[0] = st->Q_subfr[1] = st->Q_subfr[2] = st->Q_subfr[3] = st->Q_subfr[4] = st->Q_exc; + move16(); + move16(); + move16(); + move16(); + move16(); + + assert( L_frame_glob < L_EXC_MEM_DEC ); + Copy( st->old_exc_fx + L_frame_glob, st->old_exc_fx, sub( L_EXC_MEM_DEC, L_frame_glob ) ); + Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, L_frame_glob ), L_frame_glob, 1 ); + } + /* Update old_Aq */ + Copy( A, st->old_Aq_12_8_fx, M + 1 ); +#ifdef FIX_778_STEREO_BRATE_SWITCHING + } +#endif + } + } + return; +} + +/* Returns: number of bits used (including "bits") */ +Word16 tcx_ari_res_invQ_spec( + Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ + Word16 x_Q_e, /* i: quantized spectrum exponent Q0 */ + Word16 L_frame, /* i: number of lines Q0 */ + const Word16 prm[], /* i: bitstream Q0 */ + Word16 target_bits, /* i: number of bits available Q0 */ + Word16 bits, /* i: number of bits used so far Q0 */ + Word16 deadzone, /* i: quantizer deadzone Q15 */ + const Word16 x_fac[] /* i: spectrum post-quantization factors Q14 */ +) +{ + Word16 i, j, num_zeros; + Word16 zeros[L_FRAME_PLUS]; + Word16 fac_p, sign; + Word32 L_tmp; + Word16 s; + + + /* Limit the number of residual bits */ + target_bits = s_min( target_bits, NPRM_RESQ ); + + + /* Requantize the spectrum line-by-line */ + /* fac_m = deadzone * 0.5f; */ + num_zeros = 0; + move16(); + + FOR( i = 0; i < L_frame; i++ ) + { + IF( GE_16( bits, target_bits ) ) /* no bits left */ + { + BREAK; + } + + IF( x_Q[i] != 0 ) + { + sign = x_fac[i]; + move16(); + if ( x_Q[i] < 0 ) + sign = negate( sign ); + + /* x_Q[i] += sign*(prm[bits++] * 0.5f - fac_m); */ + x_Q[i] = L_sub( x_Q[i], L_shr( L_mult( sign, add( deadzone, lshl( prm[bits], 15 ) ) ), x_Q_e ) ); + move32(); + bits = add( bits, 1 ); + } + ELSE + { + zeros[num_zeros] = i; + move16(); + num_zeros = add( num_zeros, 1 ); + } + } + + /* Requantize zeroed-lines of the spectrum */ + fac_p = msu_r( 1417339264l /*0.33f*2.0f Q31*/, deadzone, 21627 /*0.33f*2.0f Q15*/ ); /* Q15 */ + target_bits = sub( target_bits, 1 ); /* reserve 1 bit for the check below */ + + s = sub( x_Q_e, 1 ); + FOR( j = 0; j < num_zeros; j++ ) + { + IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */ + { + BREAK; + } + + i = zeros[j]; + move16(); + + IF( prm[bits] != 0 ) + { + bits = add( bits, 1 ); + L_tmp = L_mult( fac_p, x_fac[i] ); /* Q30 */ + if ( prm[bits] == 0 ) + L_tmp = L_negate( L_tmp ); + x_Q[i] = L_shr( L_tmp, s ); + move32(); + } + bits = add( bits, 1 ); + } + + + return bits; +} +/*--------------------------------------------------------------- + * tcx_res_invQ_gain() + * + * + *--------------------------------------------------------------*/ +Word16 tcx_res_invQ_gain( + Word16 *gain_tcx, + Word16 *gain_tcx_e, + Word16 *prm, + Word16 resQBits ) +{ + Word16 bits; + Word16 gain, tmp1, tmp2; + + + gain = *gain_tcx; + move16(); + + /* make sure we have a bit of headroom */ + IF( GT_16( gain, 0x7000 ) ) + { + gain = shr( gain, 1 ); + *gain_tcx_e = add( *gain_tcx_e, 1 ); + move16(); + } + + /*Refine the gain quantization*/ + tmp1 = s_min( resQBits, TCX_RES_Q_BITS_GAIN ); + FOR( bits = 0; bits < tmp1; bits++ ) + { + tmp2 = gain_corr_fac[bits]; + move16(); + if ( prm[bits] == 0 ) + { + tmp2 = gain_corr_inv_fac[bits]; + move16(); + } + + gain = mult_r( gain, tmp2 ); + if ( prm[bits] != 0 ) + gain = shl( gain, 1 ); + } + + *gain_tcx = gain; + move16(); + + + return bits; +} + +/*--------------------------------------------------------------- + * tcx_res_invQ_spec() + * + * + *--------------------------------------------------------------*/ +Word16 tcx_res_invQ_spec( + Word32 *x, + Word16 x_e, + Word16 L_frame, + Word16 *prm, + Word16 resQBits, + Word16 bits, + Word16 sq_round, + const Word16 lf_deemph_factors[] ) +{ + Word16 i; + Word16 fac_m, fac_p; + Word16 lf_deemph_factor, c, s; + Word32 tmp; + + + /* Limit the number of residual bits */ + resQBits = s_min( resQBits, NPRM_RESQ ); + + /* Requantize the spectrum line-by-line */ + fac_m = shr( sq_round, 1 ); + fac_p = sub( 0x4000, fac_m ); + + lf_deemph_factor = 0x4000; + move16(); + s = sub( x_e, 1 ); + + FOR( i = 0; i < L_frame; i++ ) + { + IF( GE_16( bits, resQBits ) ) + { + BREAK; + } + + test(); + test(); + IF( ( x[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) + { + if ( lf_deemph_factors != NULL ) + { + lf_deemph_factor = lf_deemph_factors[i]; + move16(); + } + + IF( prm[bits] == 0 ) + { + + /* Debug initialization to catch illegal cases of x[i] */ + tmp = 0; + move32(); + + if ( x[i] > 0 ) + tmp = L_mult( fac_m, lf_deemph_factor ); + if ( x[i] < 0 ) + tmp = L_mult( fac_p, lf_deemph_factor ); + + assert( tmp != 0 ); + + x[i] = L_sub( x[i], L_shr( tmp, s ) ); + move32(); + } + ELSE + { + + /* Debug initialization to catch illegal cases of x[i] */ + tmp = 0; + move32(); + + if ( x[i] > 0 ) + tmp = L_mult( fac_p, lf_deemph_factor ); + if ( x[i] < 0 ) + tmp = L_mult( fac_m, lf_deemph_factor ); + + assert( tmp != 0 ); + + x[i] = L_add( x[i], L_shr( tmp, s ) ); + move32(); + } + bits = add( bits, 1 ); + } + } + + /*Quantize zeroed-line of the spectrum*/ + resQBits = sub( resQBits, 1 ); + + IF( lf_deemph_factors == NULL ) + { + FOR( i = 0; i < L_frame; i++ ) + { + IF( GE_16( bits, resQBits ) ) + { + BREAK; + } + + IF( x[i] == 0 ) + { + IF( prm[bits] != 0 ) + { + bits = add( bits, 1 ); + + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + if ( prm[bits] == 0 ) + tmp = L_negate( tmp ); + + x[i] = L_shr( tmp, s ); + move32(); + } + bits = add( bits, 1 ); + } + } + } + ELSE + { + c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); + + FOR( i = 0; i < L_frame; i++ ) + { + IF( GE_16( bits, resQBits ) ) + { + BREAK; + } + + test(); + IF( ( x[i] == 0 ) && ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) + { + IF( prm[bits] != 0 ) + { + bits = add( bits, 1 ); + + tmp = L_mult( c, lf_deemph_factors[i] ); + if ( prm[bits] == 0 ) + tmp = L_negate( tmp ); + + x[i] = L_shr( tmp, s ); + move32(); + } + bits = add( bits, 1 ); + } + } + } + + return bits; +} -- GitLab