diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h index db593758b3a584e397435d336abb51f134fb53d8..d560a67a78f86c39ace4866f0d241f6045bf6cb1 100644 --- a/lib_com/prot_fx1.h +++ b/lib_com/prot_fx1.h @@ -524,7 +524,7 @@ void hp400_12k8_fx( Word16 mem[] /* i/o: filter memory [6] */ ); -#ifdef IVAS_FLOAT_FIXED +#if 0 void hp400_12k8_ivas_fx( Word16 signal[], /* i/o: input signal / output is divided by 16 */ const Word16 lg, /* i : lenght of signal */ diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 582dc217b2a7b2c72be4889833ecd81b2deddeaa..ede212bb13841aa67fbec6363525de17c183edd4 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -56,9 +56,6 @@ static void create_random_vector( float output[], const int16_t length, int16_t seed[] ); static void flip_spectrum( const float input[], float output[], const int16_t length ); static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, float *tmpi_I, const int16_t length, const int16_t HB_stage_id ); -#ifdef IVAS_FLOAT_FIXED -static void Hilbert_transform_fx_32( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); -#endif static void Estimate_mix_factors( const float *shb_res, const float *exc16kWhtnd, const float *White_exc16k, const float pow1, const float pow22, float *vf_modified, int16_t *vf_ind ); /*-------------------------------------------------------------------* @@ -241,133 +238,6 @@ void flip_and_downmix_generic( return; } -#ifdef IVAS_FLOAT_FIXED -void flip_and_downmix_generic_fx_32( - Word32 input[], /* i : input spectrum Qx*/ - Word32 output[], /* o : output spectrum Qx*/ - const Word16 length, /* i : length of spectra */ - Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/ - Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ - Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ - Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ -) -{ - Word16 i, j; - Word32 tmp[L_FRAME32k + HILBERT_ORDER1]; - Word32 tmpi_R[L_FRAME32k]; - Word32 tmpi_I[L_FRAME32k]; - Word32 tmpi2_R[L_FRAME32k + HILBERT_ORDER2]; - Word32 tmpi2_I[L_FRAME32k + HILBERT_ORDER2]; - Word32 tmp_R[L_FRAME32k + HILBERT_ORDER2]; - Word32 tmp_I[L_FRAME32k + HILBERT_ORDER2]; - - /*Word16 s_tmp[L_FRAME32k];*/ - /*Word16 factor;*/ - Word16 period; - Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, - -26319, -17530, -6393, 6393, 17530, 26319, - 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ - Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, - -19519, -27683, -32137, -32137, -27683, - -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ - Word16 *local_negsin_table, *local_cos_table; - Word32 L_tmp; - - /* 1850 Hz downmix */ - period = 17; - move16(); - local_negsin_table = local_negsin_table17; - local_cos_table = local_cos_table17; - - - FOR( i = 0; i < length; i = i + 2 ) - { - input[i] = L_negate( input[i] ); - move16(); - } - - Copy32( input, tmp + HILBERT_ORDER1, length ); - Copy32( mem1_ext, tmp, HILBERT_ORDER1 ); - - /* Hilber transform stage - 0 - single precision */ - Hilbert_transform_fx_32( tmp, /* i: Real component of HB */ - tmp, /* i: Imag component of HB */ - tmpi_R, /* o: Real component of HB */ - tmpi_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 0 ); /* i: HB transform stage */ - - - Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 ); - Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 ); - - /* Hilber transform stage - 1 */ - Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */ - tmpi_I, /* i: Imag component of HB */ - tmpi2_R, /* o: Real component of HB */ - tmpi2_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 1 ); /* i: HB transform stage */ - Copy32( tmp + length, mem1_ext, HILBERT_ORDER1 ); - Copy32( mem2_ext + HILBERT_ORDER2, tmp_R, HILBERT_ORDER2 ); - Copy32( mem3_ext + HILBERT_ORDER2, tmp_I, HILBERT_ORDER2 ); - - /* Hilber transform stage - 2 */ - Hilbert_transform_fx_32( tmpi2_R, /* i: Real component of HB */ - tmpi2_I, /* i: Imag component of HB */ - tmpi_R, /* o: Real component of HB */ - tmpi_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 2 ); /* i: HB transform stage */ - - Copy32( tmpi2_R + length, mem2_ext, HILBERT_ORDER2 ); - Copy32( tmpi2_I + length, mem3_ext, HILBERT_ORDER2 ); - - /* Hilber transform stage - 3 */ - Hilbert_transform_fx_32( tmpi_R, /* i: Real component of HB */ - tmpi_I, /* i: Imag component of HB */ - tmp_R, /* o: Real component of HB */ - tmp_I, /* o: Imag. component of HB */ - length, /* i: length of the spectra */ - 3 ); /* i: HB transform stage */ - - Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); - Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); - - if ( *phase_state >= period ) - { - *phase_state = 0; - move16(); - } - - i = 0; - move16(); - j = *phase_state; - move16(); - - WHILE( i < length ) - { - WHILE( ( j < period ) && ( i < length ) ) - { - L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ - output[i] = L_tmp; /*Qx */ - i++; - j++; - } - - if ( j >= period ) - { - j = 0; - move16(); - } - } - - *phase_state = j; - move16(); - return; -} -#endif /*---------------------------------------------- * Hilbert_transform() @@ -411,66 +281,6 @@ static void Hilbert_transform( return; } -#ifdef IVAS_FLOAT_FIXED -static void Hilbert_transform_fx_32( - Word32 tmp_R[], /* i: Real component of HB */ - Word32 tmp_I[], /* i: Real component of HB */ - Word32 tmpi_R[], /* o: Real component of HB */ - Word32 tmpi_I[], /* o: Imag. component of HB */ - const Word16 length, /* i: input length */ - const Word16 HB_stage_id /* i: HB transform stage */ -) -{ - Word16 i, hb_filter_stage, offset; - Word32 L_tmp; - - hb_filter_stage = 2 * HB_stage_id; - offset = 0; - move16(); - if ( HB_stage_id == 0 ) - { - offset = 1; - move16(); - } - - test(); - test(); - IF( HB_stage_id == 0 || HB_stage_id == 2 ) - { - FOR( i = 0; i < length; i++ ) - { - L_tmp = Mult_32_16( tmp_R[i + 4], Hilbert_coeffs_fx[hb_filter_stage][0 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2 + offset] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_R[i], Hilbert_coeffs_fx[hb_filter_stage][4 + offset] ); /*Qx+15 */ - tmpi_R[i] = L_shl( L_tmp, 1 ); - move32(); /*Qx+16 */ - - L_tmp = Mult_32_16( tmp_I[i + 4 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][0] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + 2 + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmp_I[i + offset], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */ - tmpi_I[i] = L_shl( L_tmp, 1 ); - move32(); /*Qx+16 */ - } - } - ELSE IF( HB_stage_id == 1 || HB_stage_id == 3 ) - { - FOR( i = 0; i < length; i++ ) - { - - L_tmp = Mult_32_16( tmpi_R[i + 2], Hilbert_coeffs_fx[hb_filter_stage][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_R[i], Hilbert_coeffs_fx[hb_filter_stage][4] ); /*Qx+15 */ - tmpi_R[i + 4] = L_sub( tmp_R[i], L_shl( L_tmp, 1 ) ); - move32(); /*Qx+16 */ - - L_tmp = Mult_32_16( tmpi_I[i + 2], Hilbert_coeffs_fx[hb_filter_stage + 1][2] ); /*Qx+15 */ - L_tmp = Madd_32_16( L_tmp, tmpi_I[i], Hilbert_coeffs_fx[hb_filter_stage + 1][4] ); /*Qx+15 */ - tmpi_I[i + 4] = L_sub( tmp_I[i], L_shl( L_tmp, 1 ) ); - move32(); /*Qx+16 */ - } - } -} -#endif - /*-------------------------------------------------------------------* * flip_spectrum() * diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index ffb96c5dfc8cb61c835fa1a47bb8cbfffb42a919..fe77f49185cc8aa3b197088d25a5d18a34fe780c 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -483,6 +483,131 @@ void flip_and_downmix_generic_fx( return; } +void flip_and_downmix_generic_fx_32( + Word32 input[], /* i : input spectrum Qx*/ + Word32 output[], /* o : output spectrum Qx*/ + const Word16 length, /* i : length of spectra */ + Word32 mem1_ext[HILBERT_ORDER1], /* i/o: memory Qx*/ + Word32 mem2_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ + Word32 mem3_ext[2 * HILBERT_ORDER2], /* i/o: memory Qx*/ + Word16 *phase_state /* i/o: Phase state in case frequency isn't multiple of 50 Hz */ +) +{ + Word16 i, j; + Word32 tmp[L_FRAME32k + HILBERT_ORDER1]; + Word32 tmpi_R[L_FRAME32k]; + Word32 tmpi_I[L_FRAME32k]; + Word32 tmpi2_R[L_FRAME32k + HILBERT_ORDER2]; + Word32 tmpi2_I[L_FRAME32k + HILBERT_ORDER2]; + Word32 tmp_R[L_FRAME32k + HILBERT_ORDER2]; + Word32 tmp_I[L_FRAME32k + HILBERT_ORDER2]; + + /*Word16 s_tmp[L_FRAME32k];*/ + /*Word16 factor;*/ + Word16 period; + Word16 local_negsin_table17[17] = { 0, -11793, -22005, -29268, -32609, -31580, + -26319, -17530, -6393, 6393, 17530, 26319, + 31580, 32609, 29268, 22005, 11793 }; /* Q15 */ + Word16 local_cos_table17[17] = { 32767, 30571, 24279, 14732, 3212, -8739, + -19519, -27683, -32137, -32137, -27683, + -19519, -8739, 3212, 14732, 24279, 30571 }; /* Q15 */ + Word16 *local_negsin_table, *local_cos_table; + Word32 L_tmp; + + /* 1850 Hz downmix */ + period = 17; + move16(); + local_negsin_table = local_negsin_table17; + local_cos_table = local_cos_table17; + + + FOR( i = 0; i < length; i = i + 2 ) + { + input[i] = L_negate( input[i] ); + move16(); + } + + Copy32( input, tmp + HILBERT_ORDER1, length ); + Copy32( mem1_ext, tmp, HILBERT_ORDER1 ); + + /* Hilber transform stage - 0 - single precision */ + Hilbert_transform_fx( tmp, /* i: Real component of HB */ + tmp, /* i: Imag component of HB */ + tmpi_R, /* o: Real component of HB */ + tmpi_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 0 ); /* i: HB transform stage */ + + + Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 ); + Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 ); + + /* Hilber transform stage - 1 */ + Hilbert_transform_fx( tmpi_R, /* i: Real component of HB */ + tmpi_I, /* i: Imag component of HB */ + tmpi2_R, /* o: Real component of HB */ + tmpi2_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 1 ); /* i: HB transform stage */ + Copy32( tmp + length, mem1_ext, HILBERT_ORDER1 ); + Copy32( mem2_ext + HILBERT_ORDER2, tmp_R, HILBERT_ORDER2 ); + Copy32( mem3_ext + HILBERT_ORDER2, tmp_I, HILBERT_ORDER2 ); + + /* Hilber transform stage - 2 */ + Hilbert_transform_fx( tmpi2_R, /* i: Real component of HB */ + tmpi2_I, /* i: Imag component of HB */ + tmpi_R, /* o: Real component of HB */ + tmpi_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 2 ); /* i: HB transform stage */ + + Copy32( tmpi2_R + length, mem2_ext, HILBERT_ORDER2 ); + Copy32( tmpi2_I + length, mem3_ext, HILBERT_ORDER2 ); + + /* Hilber transform stage - 3 */ + Hilbert_transform_fx( tmpi_R, /* i: Real component of HB */ + tmpi_I, /* i: Imag component of HB */ + tmp_R, /* o: Real component of HB */ + tmp_I, /* o: Imag. component of HB */ + length, /* i: length of the spectra */ + 3 ); /* i: HB transform stage */ + + Copy32( tmp_R + length, mem2_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); + Copy32( tmp_I + length, mem3_ext + HILBERT_ORDER2, HILBERT_ORDER2 ); + + if ( *phase_state >= period ) + { + *phase_state = 0; + move16(); + } + + i = 0; + move16(); + j = *phase_state; + move16(); + + WHILE( i < length ) + { + WHILE( ( j < period ) && ( i < length ) ) + { + L_tmp = Mult_32_16( tmp_R[i + 4], local_cos_table[j] ); /*//Qx+16 */ + L_tmp = Madd_32_16( L_tmp, tmp_I[i + 4], local_negsin_table[j] ); /*Qx+16 */ + output[i] = L_tmp; /*Qx */ + i++; + j++; + } + + if ( j >= period ) + { + j = 0; + move16(); + } + } + + *phase_state = j; + move16(); + return; +} /*---------------------------------------------- * Hilbert transform - Double precision @@ -779,7 +904,6 @@ static void filt_mu_fx( Overflow = 0; } #endif - #else sig_out[n] = shl( mult_r( ga, temp ), 1 ); #endif diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index bba84cdb92117c2cfdd33af36359f3df616a44ad..98568a301befe27688588394dba35826d8bd8bdc 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -3545,7 +3545,7 @@ void hp400_12k8_fx( return; } -#ifdef IVAS_FLOAT_FIXED +#if 0 void hp400_12k8_ivas_fx( Word16 signal[], /* i/o: input signal / output is divided by 16 */ const Word16 lg, /* i : lenght of signal */ diff --git a/lib_dec/FEC_HQ_core.c b/lib_dec/FEC_HQ_core.c index 23b587ac1dbe2f6a5cecfe407b8084ecad7e995c..f87cc884f1525119815b33eb104d93e246bc0204 100644 --- a/lib_dec/FEC_HQ_core.c +++ b/lib_dec/FEC_HQ_core.c @@ -1551,68 +1551,79 @@ void save_synthesis_hq_fec_fx( { case EVS_MONO: post_hq_delay = NS2SA( st->output_Fs, POST_HQ_DELAY_NS ); + move16(); BREAK; case IVAS_SCE: post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + move16(); BREAK; case IVAS_CPE_DFT: - IF( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) { post_hq_delay = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + move16(); } ELSE { post_hq_delay = 0; + move16(); } BREAK; default: post_hq_delay = 0; + move16(); BREAK; } + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { - Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, output_frame - post_hq_delay + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); - FOR( int i = 0; i < output_frame; i++ ) + Copy( st->hTcxDec->synth_history_fx + output_frame, st->hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ) ); + FOR( Word16 i = 0; i < output_frame; i++ ) { - st->hTcxDec->old_synthFB_fx[i + output_frame - post_hq_delay] = extract_h( output_fx[i] ); + st->hTcxDec->old_synthFB_fx[sub( add( i, output_frame ), post_hq_delay )] = extract_h( output_fx[i] ); + move16(); } - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { /* reset the remaining buffer, which is read in TCX concealment the necessary samples to fill this buffer are not available for all cases, the impact on the output is limited */ - set16_fx( st->hTcxDec->old_synthFB_fx + 2 * output_frame - post_hq_delay, 0, post_hq_delay ); + set16_fx( st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), 0, post_hq_delay ); IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy( st->prev_synth_buffer_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + Copy( st->prev_synth_buffer_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); } ELSE { - Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame, 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 + shl( output_frame, 1 ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } - IF( NE_16( st->core, ACELP_CORE ) ) + IF( st->core != ACELP_CORE ) { IF( GE_16( output_frame, L_FRAME16k ) ) { - Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } ELSE { - Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } } } ELSE { - IF( NE_16( st->core, ACELP_CORE ) ) + IF( st->core != ACELP_CORE ) { - Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + 2 * output_frame - post_hq_delay, post_hq_delay ); - Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + Copy( st->delay_buf_out_fx, st->hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), post_hq_delay ); + Copy( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); } } } diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 6d709b728c2e4df0c883de89835d0541ebceace5..2a375498e27a83f7a4cf0b78a49c630e67401caa 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -49,10 +49,11 @@ static void Regression_Anal_fx( Word32 b_p_fx[MAX_PGF + 1]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Initialize */ - FOR( i = 0; i < num_pgf + 1; i++ ) + FOR( i = 0; i < add( num_pgf, 1 ); i++ ) { aindex_fx[i] = 0; move16(); @@ -69,19 +70,24 @@ static void Regression_Anal_fx( /*aindex[0]=num_pgf; */ aindex_fx[0] = num_pgf; move16(); - FOR( i = 1; i < num_pgf + 1; i++ ) + FOR( i = 1; i < add( num_pgf, 1 ); i++ ) { aindex_fx[1] = add( aindex_fx[1], i ); + move16(); aindex_fx[2] = add( aindex_fx[2], i_mult( i, i ) ); + move16(); } /* Calculate b[] */ FOR( i = 0; i < num_pgf; i++ ) { b_p_fx[0] = L_add( b_p_fx[0], L_shr( values_fx[i], 2 ) ); /*10 */ + move32(); #ifdef BASOP_NOGLOB b_p_fx[1] = L_add( b_p_fx[1], Mult_32_16( values_fx[i], shl_o( sub( num_pgf, i ), 13, &Overflow ) ) ); /*10 */ + move32(); #else b_p_fx[1] = L_add( b_p_fx[1], Mult_32_16( values_fx[i], shl( sub( num_pgf, i ), 13 ) ) ); /*10 */ + move32(); #endif } @@ -91,7 +97,9 @@ static void Regression_Anal_fx( L_tmp1 = L_sub( Mult_32_16( b_p_fx[0], shl( aindex_fx[2], 10 ) ), Mult_32_16( b_p_fx[1], shl( aindex_fx[1], 10 ) ) ); /*5 */ L_tmp2 = L_sub( Mult_32_16( b_p_fx[1], shl( aindex_fx[0], 10 ) ), Mult_32_16( b_p_fx[0], shl( aindex_fx[1], 10 ) ) ); /*5 */ r_p_fx[0] = Mult_32_16( L_tmp1, tmp ); + move32(); r_p_fx[1] = Mult_32_16( L_tmp2, tmp ); + move32(); return; } @@ -112,6 +120,7 @@ static void FEC_scaling_fx( FOR( j = start_band[i]; j < end_band[i]; j++ ) { t_audio_q_fx[j] = Mult_32_16( old_coeffs_fx[j], Norm_gain_fx[i] ); /*12 */ + move32(); } } @@ -122,10 +131,12 @@ static void FEC_scaling_fx( IF( Random( HQ_FEC_seed ) < 0 ) { t_audio_q_fx[j] = Mult_32_16( L_negate( old_coeffs_fx[j] ), Norm_gain_fx[i] ); /*12*/ + move32(); } ELSE { t_audio_q_fx[j] = Mult_32_16( old_coeffs_fx[j], Norm_gain_fx[i] ); /*12*/ + move32(); } } } @@ -159,6 +170,7 @@ void HQ_FEC_processing_fx( HQ_DEC_HANDLE hHQ_core; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif hHQ_nbfec = st_fx->hHQ_nbfec; hHQ_core = st_fx->hHQ_core; @@ -186,9 +198,10 @@ void HQ_FEC_processing_fx( } test(); test(); - if ( EQ_16( st_fx->prev_old_bfi, 1 ) && EQ_16( st_fx->nbLostCmpt, 1 ) && EQ_16( output_frame, L_FRAME8k ) ) + IF( EQ_16( st_fx->prev_old_bfi, 1 ) && EQ_16( st_fx->nbLostCmpt, 1 ) && EQ_16( output_frame, L_FRAME8k ) ) { st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); + move32(); } /* Frequency-domain FEC */ @@ -209,6 +222,7 @@ void HQ_FEC_processing_fx( FOR( i = 0; i < output_frame; i++ ) { hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); /*23170, 3dB, Q15*/ + move32(); t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } @@ -225,7 +239,7 @@ void HQ_FEC_processing_fx( { FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) { - t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] = L_negate( t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] ); + t_audio_q_fx[add( i, imult1616( sfm, HQ_FEC_BAND_SIZE ) )] = L_negate( t_audio_q_fx[add( i, imult1616( sfm, HQ_FEC_BAND_SIZE ) )] ); move32(); } } @@ -239,7 +253,7 @@ void HQ_FEC_processing_fx( { FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) { - t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] = L_negate( t_audio_q_fx[i + sfm * HQ_FEC_BAND_SIZE] ); + t_audio_q_fx[add( i, imult1616( sfm, HQ_FEC_BAND_SIZE ) )] = L_negate( t_audio_q_fx[add( i, imult1616( sfm, HQ_FEC_BAND_SIZE ) )] ); move32(); } } @@ -265,6 +279,7 @@ void HQ_FEC_processing_fx( FOR( i = 0; i < output_frame; i++ ) { hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); + move32(); t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } @@ -274,6 +289,7 @@ void HQ_FEC_processing_fx( FOR( i = 0; i < RANDOM_START * 8; i++ ) { hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); + move32(); t_audio_q_fx[i] = hHQ_nbfec->old_coeffs_fx[i]; move32(); } @@ -281,6 +297,7 @@ void HQ_FEC_processing_fx( FOR( i = RANDOM_START * 8; i < output_frame; i++ ) { hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16( hHQ_nbfec->old_coeffs_fx[i], 23170 ); + move32(); IF( Random( &hHQ_nbfec->HQ_FEC_seed ) < 0 ) { t_audio_q_fx[i] = L_negate( hHQ_nbfec->old_coeffs_fx[i] ); @@ -345,12 +362,14 @@ void HQ_FEC_processing_fx( IF( r_p_fx[1] > 0 ) { r_p_fx[1] = L_deposit_l( 0 ); + move32(); norm_p_fx[i] = L_shr( norm_values_fx[0], 7 ); /*5*/ move32(); } ELSE { norm_p_fx[i] = L_add( r_p_fx[0], L_mult0( extract_l( r_p_fx[1] ), sub( add( st_fx->nbLostCmpt, num_pgf ), 1 ) ) ); + move32(); } test(); @@ -363,7 +382,7 @@ void HQ_FEC_processing_fx( #ifdef BASOP_NOGLOB tmp_fx = shl_sat( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ #else - tmp_fx = shl( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ + tmp_fx = shl( tmp_fx, add( 6, sub( exp2, exp1 ) ) ); /*14*/ #endif if ( GT_16( tmp_fx, 16384 ) ) { @@ -374,7 +393,9 @@ void HQ_FEC_processing_fx( FOR( j = 0; j < Num_bands_p[i]; j++ ) { #ifdef BASOP_NOGLOB - hHQ_nbfec->Norm_gain_fx[k++] = shl_o( tmp_fx, 1, &Overflow ); + hHQ_nbfec->Norm_gain_fx[k] = shl_o( tmp_fx, 1, &Overflow ); + move16(); + k = add( k, 1 ); #else hHQ_nbfec->Norm_gain_fx[k++] = shl( tmp_fx, 1 ); #endif @@ -388,7 +409,7 @@ void HQ_FEC_processing_fx( { hHQ_nbfec->Norm_gain_fx[k] = mult_r( hHQ_nbfec->Norm_gain_fx[k], 23170 ); move16(); - k++; + k = add( k, 1 ); } } } @@ -435,7 +456,9 @@ void ivas_HQ_FEC_Mem_update_fx( hHQ_core = st_fx->hHQ_core; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif + move32(); // for tmp_energy_fx IF( EQ_16( output_frame, L_FRAME8k ) ) { @@ -458,7 +481,7 @@ void ivas_HQ_FEC_Mem_update_fx( test(); test(); test(); - IF( ( GT_32( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) && LT_32( t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) ) || ( LT_32( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) && GT_32( t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) ) ) + IF( ( hHQ_nbfec->old_coeffs_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] > 0 && t_audio_q_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] < 0 ) || ( hHQ_nbfec->old_coeffs_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] < 0 && t_audio_q_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] > 0 ) ) { hHQ_nbfec->prev_sign_switch[j] = add( hHQ_nbfec->prev_sign_switch[j], 1 ); move16(); @@ -473,7 +496,7 @@ void ivas_HQ_FEC_Mem_update_fx( IF( ( EQ_16( hqswb_clas, HQ_HVQ ) ) || ( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) ) { /* First group */ - logqnorm_fx( t_audio_q_fx, 12, ynrm, 32, WID_G1, ( hqswb_clas == HQ_HVQ ) ); + logqnorm_fx( t_audio_q_fx, 12, ynrm, 32, WID_G1, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); j = ynrm[0]; move16(); offset = WID_G1; @@ -481,17 +504,15 @@ void ivas_HQ_FEC_Mem_update_fx( FOR( i = 1; i < SFM_G1; i++ ) { - logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G1, ( hqswb_clas == HQ_HVQ ) ); - offset += WID_G1; - move16(); + logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G1, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); + offset = add( offset, WID_G1 ); } /* Second group */ FOR( i = SFM_G1; i < SFM_G1 + 2; i++ ) { - logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G2, ( hqswb_clas == HQ_HVQ ) ); - offset += WID_G2; - move16(); + logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G2, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); + offset = add( offset, WID_G2 ); } } @@ -511,7 +532,8 @@ void ivas_HQ_FEC_Mem_update_fx( L_tmp = L_deposit_l( 0 ); FOR( j = 0; j < Num_bands_p[i]; j++ ) { - L_tmp = L_add( L_tmp, L_shr( normq_fx[k++], 3 ) ); /*11*/ + L_tmp = L_add( L_tmp, L_shr( normq_fx[k], 3 ) ); /*11*/ + k = add( k, 1 ); } #ifdef BASOP_NOGLOB tmp_fx = shl_o( inv_tbl_fx[Num_bands_p[i]], 1, &Overflow ); /*16*/ @@ -524,7 +546,7 @@ void ivas_HQ_FEC_Mem_update_fx( } test(); test(); - IF( ( c_switching_flag ) || ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && ( EQ_16( st_fx->core, HQ_CORE ) ) ) ) + IF( ( c_switching_flag ) || ( ( st_fx->last_core == ACELP_CORE ) && ( EQ_16( st_fx->core, HQ_CORE ) ) ) ) { FOR( i = 0; i < MAX_SB_NB; i++ ) { @@ -549,11 +571,14 @@ void ivas_HQ_FEC_Mem_update_fx( /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ hHQ_nbfec->diff_energy_fx = abs_s( sub( hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0] ) ); + move16(); exp1 = sub( norm_l( hHQ_nbfec->diff_energy_fx ), 1 ); exp2 = norm_l( hHQ_nbfec->energy_MA_Curr_fx[0] ); hHQ_nbfec->diff_energy_fx = div_s( extract_h( L_shl( hHQ_nbfec->diff_energy_fx, exp1 ) ), extract_h( L_shl( hHQ_nbfec->energy_MA_Curr_fx[0], exp2 ) ) ); + move16(); exp = add( 15, sub( exp1, exp2 ) ); hHQ_nbfec->diff_energy_fx = shl( hHQ_nbfec->diff_energy_fx, sub( 11, exp ) ); /*11*/ + move16(); /* Classify the stationary mode : 12% */ IF( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_12P_fx ) ) @@ -568,7 +593,7 @@ void ivas_HQ_FEC_Mem_update_fx( } /* Apply Hysteresis to prevent frequent mode changing */ - IF( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) + if ( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) { hHQ_nbfec->stat_mode_out = stat_mode_curr; move16(); @@ -595,7 +620,7 @@ void ivas_HQ_FEC_Mem_update_fx( /* Find max. coeff in band 0 */ Max_ind = 0; move16(); - IF( EQ_16( Min_ind, 0 ) ) + IF( Min_ind == 0 ) { Max_coeff_fx = L_deposit_l( 0 ); FOR( i = 0; i < 8; i++ ) @@ -617,6 +642,7 @@ void ivas_HQ_FEC_Mem_update_fx( FOR( i = k; i < num_Sb; i++ ) { en_high_fx[i] = L_deposit_l( 0 ); + move32(); FOR( j = 0; j < 2; j++ ) { /*en_high[i] += 0.5f*st->ynrm_values[i][j+1];*/ @@ -639,8 +665,10 @@ void ivas_HQ_FEC_Mem_update_fx( #else *mean_en_high_fx = add( *mean_en_high_fx, shr( tmp_fx, sub( exp, 5 ) ) ); #endif + move16(); } - *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[num_Sb - k] ); + *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[sub( num_Sb, k )] ); + move16(); test(); test(); @@ -656,7 +684,7 @@ void ivas_HQ_FEC_Mem_update_fx( hHQ_nbfec->phase_mat_flag = 1; move16(); test(); - IF( ( EQ_16( Min_ind, 0 ) ) && ( LT_16( Max_ind, 3 ) ) ) + if ( ( Min_ind == 0 ) && ( LT_16( Max_ind, 3 ) ) ) { hHQ_nbfec->phase_mat_flag = 0; move16(); @@ -722,7 +750,9 @@ void HQ_FEC_Mem_update_fx( hHQ_core = st_fx->hHQ_core; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif + move32(); // tmp_energy_fx #ifdef ADD_IVAS_HQ_CODE_FEC IF( EQ_16( output_frame, L_FRAME8k ) ) { @@ -747,7 +777,7 @@ void HQ_FEC_Mem_update_fx( test(); test(); test(); - IF( ( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE] > 0 && t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE] < 0 ) || ( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE] < 0 && t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE] > 0 ) ) + IF( ( hHQ_nbfec->old_coeffs_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] > 0 && t_audio_q_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] < 0 ) || ( hHQ_nbfec->old_coeffs_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] < 0 && t_audio_q_fx[add( i, imult1616( j, HQ_FEC_BAND_SIZE ) )] > 0 ) ) { hHQ_nbfec->prev_sign_switch[j] = add( hHQ_nbfec->prev_sign_switch[j], 1 ); move16(); @@ -758,7 +788,7 @@ void HQ_FEC_Mem_update_fx( } } #ifndef ADD_IVAS_HQ_CODE_FEC - IF( EQ_16( output_frame, L_FRAME8k ) ) + if ( EQ_16( output_frame, L_FRAME8k ) ) { #endif /* if LR MDCT core is used, recalculate norms from decoded MDCT spectrum (using code from hq_hr_enc_fx()) */ @@ -766,7 +796,7 @@ void HQ_FEC_Mem_update_fx( IF( ( EQ_16( hqswb_clas, HQ_HVQ ) ) || ( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) ) { /* First group */ - logqnorm_fx( t_audio_q_fx, 12, ynrm, 32, WID_G1, ( hqswb_clas == HQ_HVQ ) ); + logqnorm_fx( t_audio_q_fx, 12, ynrm, 32, WID_G1, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); j = ynrm[0]; move16(); offset = WID_G1; @@ -774,17 +804,15 @@ void HQ_FEC_Mem_update_fx( FOR( i = 1; i < SFM_G1; i++ ) { - logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G1, ( hqswb_clas == HQ_HVQ ) ); - offset += WID_G1; - move16(); + logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G1, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); + offset = add( offset, WID_G1 ); } /* Second group */ FOR( i = SFM_G1; i < SFM_G1 + 2; i++ ) { - logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G2, ( hqswb_clas == HQ_HVQ ) ); - offset += WID_G2; - move16(); + logqnorm_fx( &t_audio_q_fx[offset], 12, &ynrm[i], 40, WID_G2, (const Word16) EQ_16( hqswb_clas, HQ_HVQ ) ); + offset = add( offset, WID_G2 ); } } @@ -804,7 +832,8 @@ void HQ_FEC_Mem_update_fx( L_tmp = L_deposit_l( 0 ); FOR( j = 0; j < Num_bands_p[i]; j++ ) { - L_tmp = L_add( L_tmp, L_shr( normq_fx[k++], 3 ) ); /*11*/ + L_tmp = L_add( L_tmp, L_shr( normq_fx[k], 3 ) ); /*11*/ + k = add( k, 1 ); } #ifdef BASOP_NOGLOB tmp_fx = shl_o( inv_tbl_fx[Num_bands_p[i]], 1, &Overflow ); /*16*/ @@ -817,7 +846,7 @@ void HQ_FEC_Mem_update_fx( } test(); test(); - IF( ( c_switching_flag ) || ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && ( EQ_16( st_fx->core, HQ_CORE ) ) ) ) + IF( ( c_switching_flag ) || ( ( st_fx->last_core == ACELP_CORE ) && ( EQ_16( st_fx->core, HQ_CORE ) ) ) ) { FOR( i = 0; i < MAX_SB_NB; i++ ) { @@ -836,19 +865,24 @@ void HQ_FEC_Mem_update_fx( #ifdef BASOP_NOGLOB hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl_sat( L_tmp, 16 - 8 ) ); + move16(); #else hHQ_nbfec->energy_MA_Curr_fx[1] = extract_h( L_shl( L_tmp, 16 - 8 ) ); #endif /* Moving Average */ hHQ_nbfec->energy_MA_Curr_fx[0] = s_max( 1, add( mult_r( 26214, hHQ_nbfec->energy_MA_Curr_fx[0] ), mult_r( 6554, hHQ_nbfec->energy_MA_Curr_fx[1] ) ) ); + move16(); /*st->diff_energy = (float)fabs((st->energy_MA_Curr[1] - st->energy_MA_Curr[0])/st->energy_MA_Curr[0]); */ hHQ_nbfec->diff_energy_fx = abs_s( sub( hHQ_nbfec->energy_MA_Curr_fx[1], hHQ_nbfec->energy_MA_Curr_fx[0] ) ); + move16(); exp1 = sub( norm_l( hHQ_nbfec->diff_energy_fx ), 1 ); exp2 = norm_l( hHQ_nbfec->energy_MA_Curr_fx[0] ); hHQ_nbfec->diff_energy_fx = div_s( extract_h( L_shl( hHQ_nbfec->diff_energy_fx, exp1 ) ), extract_h( L_shl( hHQ_nbfec->energy_MA_Curr_fx[0], exp2 ) ) ); + move16(); exp = add( 15, sub( exp1, exp2 ) ); hHQ_nbfec->diff_energy_fx = shl( hHQ_nbfec->diff_energy_fx, sub( 11, exp ) ); /*11*/ + move16(); /* Classify the stationary mode : 12% */ IF( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_12P_fx ) ) @@ -863,7 +897,7 @@ void HQ_FEC_Mem_update_fx( } /* Apply Hysteresis to prevent frequent mode changing */ - IF( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) + if ( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) { hHQ_nbfec->stat_mode_out = stat_mode_curr; move16(); @@ -912,6 +946,7 @@ void HQ_FEC_Mem_update_fx( FOR( i = k; i < num_Sb; i++ ) { en_high_fx[i] = L_deposit_l( 0 ); + move16(); FOR( j = 0; j < 2; j++ ) { /*en_high[i] += 0.5f*st->ynrm_values[i][j+1];*/ @@ -934,8 +969,10 @@ void HQ_FEC_Mem_update_fx( #else *mean_en_high_fx = add( *mean_en_high_fx, shr( tmp_fx, sub( exp, 5 ) ) ); #endif + move16(); } - *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[num_Sb - k] ); + *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[sub( num_Sb, k )] ); + move16(); test(); test(); @@ -946,12 +983,12 @@ void HQ_FEC_Mem_update_fx( test(); test(); test(); - IF( ( LT_16( Min_ind, 5 ) ) && ( LT_16( abs_s( sub( Min_ind, hHQ_nbfec->old_Min_ind ) ), 2 ) ) && ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_90P_fx ) ) && ( !st_fx->bfi ) && ( !st_fx->prev_bfi ) && ( !st_fx->prev_old_bfi ) && ( !is_transient ) && ( !hHQ_core->old_is_transient[1] ) && ( hHQ_nbfec->prev_last_core == HQ_CORE ) && ( st_fx->last_core == HQ_CORE ) ) + IF( ( LT_16( Min_ind, 5 ) ) && ( LT_16( abs_s( sub( Min_ind, hHQ_nbfec->old_Min_ind ) ), 2 ) ) && ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_90P_fx ) ) && ( !st_fx->bfi ) && ( !st_fx->prev_bfi ) && ( !st_fx->prev_old_bfi ) && ( !is_transient ) && ( !hHQ_core->old_is_transient[1] ) && EQ_16( hHQ_nbfec->prev_last_core, HQ_CORE ) && EQ_16( st_fx->last_core, HQ_CORE ) ) { hHQ_nbfec->phase_mat_flag = 1; move16(); test(); - if ( ( Min_ind == 0 ) && ( LT_16( Max_ind, 3 ) ) ) + if ( Min_ind == 0 && ( LT_16( Max_ind, 3 ) ) ) { hHQ_nbfec->phase_mat_flag = 0; move16(); @@ -1005,20 +1042,22 @@ void HQ_FEC_Mem_update_fx( Word32 Rxy_fx[MAXDELAY_FEC], Ryy_fx[MAXDELAY_FEC]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif + move16(); // d1m d1 = mind1; move16(); - FOR( k = 0; k < ( maxd1 - mind1 ) / delta; k++ ) + FOR( k = 0; k < idiv1616( sub( maxd1, mind1 ), delta ); k++ ) { accA_fx = L_deposit_l( 0 ); accB_fx = L_deposit_l( 0 ); FOR( i = 0; i < lin; i += delta ) { #ifdef BASOP_NOGLOB - accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); - accB_fx = L_add_sat( accB_fx, L_shr( L_mult_sat( mu_o_fx[d1 + i], in_fx[i] ), 2 ) ); + accA_fx = L_add_sat( accA_fx, L_shr( L_mult_sat( mu_o_fx[add( d1, i )], mu_o_fx[add( d1, i )] ), 2 ) ); + accB_fx = L_add_sat( accB_fx, L_shr( L_mult_sat( mu_o_fx[add( d1, i )], in_fx[i] ), 2 ) ); #else accA_fx = L_add( accA_fx, L_shr( L_mult( mu_o_fx[d1 + i], mu_o_fx[d1 + i] ), 2 ) ); accB_fx = L_add( accB_fx, L_shr( L_mult( mu_o_fx[d1 + i], in_fx[i] ), 2 ) ); @@ -1041,7 +1080,7 @@ void HQ_FEC_Mem_update_fx( move16(); FOR( d1 = 0; d1 < ( maxd1 - mind1 ) / delta; d1++ ) { - IF( L_abs( Rxy_fx[d1] ) > L_abs( Ryy_fx[d1] ) ) + IF( GT_32( L_abs( Rxy_fx[d1] ), L_abs( Ryy_fx[d1] ) ) ) exp1 = norm_l( Rxy_fx[d1] ); ELSE exp1 = norm_l( Ryy_fx[d1] ); @@ -1120,7 +1159,7 @@ void HQ_FEC_Mem_update_fx( maxd1 = mult_r( L, 19661 ); /* max value of delay d1 to search for */ /*in = mu_o + 2*L -lin; */ - in_fx = mu_o_fx + 2 * L - lin; + in_fx = mu_o_fx + sub( shl( L, 1 ), lin ); move16(); /* generate correlation */ @@ -1158,7 +1197,7 @@ void HQ_FEC_Mem_update_fx( lin = mult_r( L, 9830 ); mind1 = mult_r( L, 14746 ); /* min value of delay d1 to search for */ maxd1 = mult_r( L, 22938 ); /* max value of delay d1 to search for */ - in_fx = mu_o_fx + 2 * L - lin; + in_fx = mu_o_fx + sub( shl( L, 1 ), lin ); move16(); /* generate correlation */ @@ -1216,23 +1255,23 @@ void HQ_FEC_Mem_update_fx( L = L_FRAME8k; move16(); - ol_size = 2 * L / 20; + ol_size = idiv1616( shl( L, 1 ), 20 ); move16(); - L_overlap = 3 * L / 20; + L_overlap = idiv1616( imult1616( 3, L ), 20 ); move16(); FOR( i = 0; i < L_overlap; i++ ) { - SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[i * 3]; + SmoothingWin_NB3_fx[i] = SmoothingWin_NB875_fx[imult1616( i, 3 )]; move16(); } - FOR( i = 0; i < L + 25; i++ ) + FOR( i = 0; i < add( L, 25 ); i++ ) { - win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); } - set16_fx( ImdctOutWin_fx, 0, 2 * L ); + set16_fx( ImdctOutWin_fx, 0, shl( L, 1 ) ); pos = Search_Max_Corr_fx( st_fx->old_auOut_2fr_fx, st_fx->old_Min_ind, L ); @@ -1242,27 +1281,28 @@ void HQ_FEC_Mem_update_fx( } /* Repetition */ - remain = L + N_Z_L_NB - ( ( 2 * L ) - pos ); - move16(); - Copy( &st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], ( 2 * L ) - pos ); + remain = sub( add( L, N_Z_L_NB ), sub( shl( L, 1 ), pos ) ); + Copy( &st_fx->old_auOut_2fr_fx[pos], &ImdctOutWin_fx[N_ZERO_NB], sub( shl( L, 1 ), pos ) ); /* OldauOut without windowing */ - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { - OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[L / 2 - 1 - i] ), 6 ) ); + OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); } - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( st_fx->oldIMDCTout_fx[i] ), 6 ) ); + move16(); } - Copy( OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB + ( 2 * L ) - pos], remain ); + Copy( OldauOutnoWin_fx, &ImdctOutWin_fx[add( N_ZERO_NB, sub( shl( L, 1 ), pos ) )], remain ); pow1_fx = L_deposit_l( 0 ); pow22_fx = L_deposit_l( 0 ); FOR( i = 0; i < L; i++ ) { - pow1_fx = L_add( pow1_fx, shr( abs_s( st_fx->old_auOut_2fr_fx[L + i] ), 1 ) ); + pow1_fx = L_add( pow1_fx, shr( abs_s( st_fx->old_auOut_2fr_fx[add( L, i )] ), 1 ) ); pow22_fx = L_add( pow22_fx, shr( abs_s( ImdctOutWin_fx[N_ZERO_NB + i] ), 1 ) ); } IF( pow22_fx != 0 ) @@ -1271,40 +1311,43 @@ void HQ_FEC_Mem_update_fx( exp2 = norm_l( pow22_fx ); tmp = div_s( extract_h( L_shl( pow1_fx, exp1 ) ), extract_h( L_shl( pow22_fx, exp2 ) ) ); /*15 + exp1 - exp2*/ tmp = shl( tmp, sub( sub( exp2, exp1 ), 1 ) ); /*14*/ - FOR( i = N_ZERO_NB; i < 2 * L; i++ ) + FOR( i = N_ZERO_NB; i < shl( L, 1 ); i++ ) { #ifdef BASOP_NOGLOB ImdctOutWin_fx[i] = shl_sat( mult( ImdctOutWin_fx[i], tmp ), 1 ); #else ImdctOutWin_fx[i] = shl( mult( ImdctOutWin_fx[i], tmp ), 1 ); #endif + move16(); } } Smoothing_vector_NB_fx( OldauOutnoWin_fx, &ImdctOutWin_fx[N_ZERO_NB], SmoothingWin_NB2_fx, auOut_fx, ol_size ); - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { /*ImdctOutWin[3*L/2 + i] *= win_NB[L/2-i-1];*/ - ImdctOutWin_fx[3 * L / 2 + i] = mult( ImdctOutWin_fx[3 * L / 2 + i], win_NB_fx[L / 2 - i - 1] ); + ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = mult( ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )], win_NB_fx[sub( sub( shr( L, 1 ), i ), 1 )] ); move16(); } - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { /*ImdctOutWin_fx[L + i] *= win_NB_fx[(L-1-i)];*/ - ImdctOutWin_fx[L + i] = mult( ImdctOutWin_fx[L + i], win_NB_fx[( L - 1 - i )] ); + ImdctOutWin_fx[add( L, i )] = mult( ImdctOutWin_fx[add( L, i )], win_NB_fx[sub( sub( L, 1 ), i )] ); move16(); } Copy( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut_pha_fx[0][0], N_LEAD_NB ); - Copy( &ImdctOutWin_fx[ol_size + N_ZERO_NB], &auOut_fx[ol_size], N_Z_L_NB - ol_size ); + Copy( &ImdctOutWin_fx[add( ol_size, N_ZERO_NB )], &auOut_fx[ol_size], sub( N_Z_L_NB, ol_size ) ); Copy( &ImdctOutWin_fx[L], &auOut_fx[N_Z_L_NB], N_ZERO_NB ); Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { - OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); - OldauOut2_fx[L / 2 + i] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + OldauOut2_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + move16(); } Smoothing_vector_NB_fx( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap ); @@ -1338,7 +1381,7 @@ void HQ_FEC_Mem_update_fx( FOR( i = 0; i < L + 25; i++ ) { /* win_NB[i] = window_48kHz[i*6+3]; */ - win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); } @@ -1361,7 +1404,7 @@ void HQ_FEC_Mem_update_fx( FOR( i = 0; i < N_LEAD_NB; i++ ) { /* OldOut_pha[i] *= SmoothingWin_NB875[L_overlap-i-1]; */ - OldOut_pha_fx[i] = mult( OldOut_pha_fx[i], SmoothingWin_NB875_fx[L_overlap - i - 1] ); + OldOut_pha_fx[i] = mult( OldOut_pha_fx[i], SmoothingWin_NB875_fx[sub( sub( L_overlap, i ), 1 )] ); move16(); } @@ -1408,7 +1451,7 @@ void HQ_FEC_Mem_update_fx( L = L_FRAME8k; move16(); - L_overlap = 3 * L / 20; + L_overlap = idiv1616( imult1616( 3, L ), 20 ); move16(); FOR( i = 0; i < L_overlap; i++ ) @@ -1417,9 +1460,9 @@ void HQ_FEC_Mem_update_fx( move16(); } - FOR( i = 0; i < L + 25; i++ ) + FOR( i = 0; i < add( L, 25 ); i++ ) { - win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); } @@ -1439,12 +1482,14 @@ void HQ_FEC_Mem_update_fx( Copy( &ImdctOutWin_fx[L], OldauOut_fx, L ); Scaledown_fx( prev_oldauOut_fx, prev_oldauOut_fx, 23170, L ); - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { /* OldauOut2[i] = -ImdctOut[L/2 - 1 - i];*/ /* OldauOut2[L/2+i] = -ImdctOut[i];*/ - OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); - OldauOut2_fx[L / 2 + i] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + OldauOut2_fx[i] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); + OldauOut2_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + move16(); } Smoothing_vector_NB_fx( &ImdctOutWin_fx[N_Z_L_O_NB], &OldauOut2_fx[N_ZERO_NB], SmoothingWin_NB3_fx, &OldauOut_pha_fx[1][0], L_overlap ); @@ -1480,19 +1525,21 @@ void HQ_FEC_Mem_update_fx( FOR( i = 0; i < L_FRAME8k + 25; i++ ) { /*win_NB[i] = window_48kHz[i*6+3];*/ - win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); } - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { /*OldauOut[i-N_ZERO_NB] = -OldImdctOut[L/2 - 1 - i];*/ - OldauOut_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); /* Q6 -> Q0 */ + OldauOut_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); /* Q6 -> Q0 */ + move16(); } - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 2 ); i++ ) { /*OldauOut[i+N_ZERO_O_NB] = -OldImdctOut[i];*/ OldauOut_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); /* Q6 -> Q0 */ + move16(); } /* Overlapping with next good frame : Overlapping to remove the discontinuity */ @@ -1501,21 +1548,23 @@ void HQ_FEC_Mem_update_fx( ol_size = N_LEAD_NB; move16(); - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { /* ImdctOutWin[i+L] = -ImdctOut[L/2 - 1 - i]; */ - ImdctOutWin_fx[i + L] = extract_l( L_shr( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); + ImdctOutWin_fx[add( i, L )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); } - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { - ImdctOutWin_fx[i + 3 * L / 2] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + ImdctOutWin_fx[add( i, shr( imult1616( 3, L ), 1 ) )] = extract_l( L_shr( L_negate( ImdctOut_fx[i] ), 6 ) ); + move16(); } /*a = (float)(1./(float)(ol_size)); y = ax */ Smoothing_vector_scaledown_NB_fx( OldauOut_fx, &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, OldauOut_fx, ol_size ); /* Scale down the overlapped signal */ - Scaledown_fx( &ImdctOutWin_fx[ol_size + N_Z_L_O_NB], &OldauOut_fx[ol_size], 23170, N_Z_L_NB - ol_size ); + Scaledown_fx( &ImdctOutWin_fx[add( ol_size, N_Z_L_O_NB )], &OldauOut_fx[ol_size], 23170, sub( N_Z_L_NB, ol_size ) ); } L_overlap = overlap_time; @@ -1523,7 +1572,7 @@ void HQ_FEC_Mem_update_fx( FOR( i = 0; i < L_overlap; i++ ) { /*OldauOut[i] *= SmoothingWin_NB875[L_overlap-i-1];*/ - OldauOut_fx[i] = mult( OldauOut_fx[i], SmoothingWin_NB875_fx[L_overlap - i - 1] ); + OldauOut_fx[i] = mult( OldauOut_fx[i], SmoothingWin_NB875_fx[sub( sub( L_overlap, i ), 1 )] ); move16(); } FOR( i = L_overlap; i < L; i++ ) @@ -1574,7 +1623,7 @@ void HQ_FEC_Mem_update_fx( FOR( i = 0; i < L_FRAME8k + 25; i++ ) { /*win_NB[i] = window_48kHz[i*6+3];*/ - win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); } @@ -1586,13 +1635,15 @@ void HQ_FEC_Mem_update_fx( common_overlapping_fx( auOut_fx, ImdctOutWin_fx, prev_oldauOut_fx, N_Z_L_NB, 0, N_Z_L_NB, L, N_ZERO_NB, 0 ); /* OldauOut without windowing */ - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { - OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); + OldauOutnoWin_fx[i - N_ZERO_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); } - FOR( i = 0; i < L / 2; i++ ) + FOR( i = 0; i < shr( L, 1 ); i++ ) { OldauOutnoWin_fx[i + N_ZERO_O_NB] = extract_l( L_shr( L_negate( OldImdctOut_fx[i] ), 6 ) ); + move16(); } /* data transition from OldauOut to auOut using smoothing win*/ @@ -1600,14 +1651,14 @@ void HQ_FEC_Mem_update_fx( pow1_fx = L_deposit_l( 0 ); pow22_fx = L_deposit_l( 0 ); - FOR( i = 0; i < 4 * L / 20; i++ ) + FOR( i = 0; i < idiv1616( imult1616( 4, L ), 20 ); i++ ) { - pow1_fx = L_add( pow1_fx, Mult_32_32( L_shl( (Word32) auOut_fx[1 * L / 20 + i], 6 ), L_shl( (Word32) auOut_fx[1 * L / 20 + i], 6 ) ) ); + pow1_fx = L_add( pow1_fx, Mult_32_32( L_shl( (Word32) auOut_fx[add( idiv1616( L, 20 ), i )], 6 ), L_shl( (Word32) auOut_fx[add( idiv1616( L, 20 ), i )], 6 ) ) ); pow22_fx = L_add( pow22_fx, Mult_32_32( L_shl( (Word32) auOut_fx[N_LEAD_NB + i], 6 ), L_shl( (Word32) auOut_fx[N_LEAD_NB + i], 6 ) ) ); } - IF( pow22_fx > L_add( pow1_fx, L_shl( pow1_fx, 1 ) ) ) + IF( GT_32( pow22_fx, L_add( pow1_fx, L_shl( pow1_fx, 1 ) ) ) ) { return 1; } @@ -1637,7 +1688,7 @@ void HQ_FEC_Mem_update_fx( { /*auOut_fx[i] = L_add(ImdctOutWin_fx[i+7*L/20], OldauOut_fx[i+offset1]);*/ #ifdef BASOP_NOGLOB - auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); + auOut_fx[i] = add_sat( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[add( i, offset1 )] ); #else auOut_fx[i] = add( ImdctOutWin_fx[i + N_ZERO_NB], OldauOut_fx[i + offset1] ); #endif @@ -1646,7 +1697,7 @@ void HQ_FEC_Mem_update_fx( FOR( i = start2; i < end2; i++ ) { /*auOut_fx[i+offset2] = ImdctOutWin_fx[i+offset_i2]; move32();*/ - auOut_fx[i + offset2] = ImdctOutWin_fx[i + offset_i2]; + auOut_fx[add( i, offset2 )] = ImdctOutWin_fx[add( i, offset_i2 )]; move16(); } @@ -1692,34 +1743,40 @@ void HQ_FEC_Mem_update_fx( move16(); IF( smoothing_flag == 0 ) { - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { /*ImdctOutWin[i] = ImdctOut[L/2 + i] * win[(2*L-1-i)-N_LEAD_O_NB];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[L / 2 + i], win_fx[( 2 * L - 1 - i ) - N_LEAD_O_NB] ), 6 ) ); + ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[add( shr( L, 1 ), i )], win_fx[sub( sub( sub( shl( L, 1 ), 1 ), i ), N_LEAD_O_NB )] ), 6 ) ); + move16(); } FOR( i = 0; i < N_ZERO_O_NB; i++ ) { /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * win[(3*L/2-1-i)-N_LEAD_O_NB];*/ /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[L - 1 - i] ), win_fx[( 3 * L / 2 - 1 - i ) - N_LEAD_O_NB] ), 6 ) ); - ImdctOutWin_fx[3 * L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[( L / 2 - i - 1 )] ), 6 ) ); + ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), win_fx[sub( ( sub( sub( shr( imult1616( 3, L ), 1 ), 1 ), i ) ), N_LEAD_O_NB )] ), 6 ) ); + move16(); + ImdctOutWin_fx[add( idiv1616( imult1616( 3, L ), 2 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); + move16(); } } ELSE { - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { - /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ - ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[L / 2 + i], smoothingWin_fx[( i - N_ZERO_NB )] ), 6 ) ); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + /*ImdctOutWin[i] = ImdctOut[L/2 + i] * smoothingWin[(i-N_ZERO_NB)];*/ /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + ImdctOutWin_fx[i] = extract_l( L_shr( Mult_32_16( ImdctOut_fx[add( shr( L, 1 ), i )], smoothingWin_fx[sub( i, N_ZERO_NB )] ), 6 ) ); /*win[(2*L-i)*decimate-1-decay-14*L_FRAME48k/20];*/ + move16(); } FOR( i = 0; i < N_ZERO_O_NB; i++ ) { /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i] * smoothingWin[(i+N_ZERO_O_NB)];*/ /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[(L/2-i-1)];*/ - ImdctOutWin_fx[L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[L - 1 - i] ), smoothingWin_fx[( i + N_ZERO_O_NB )] ), 6 ) ); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ - ImdctOutWin_fx[3 * L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[( L / 2 - i - 1 )] ), 6 ) ); + ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), smoothingWin_fx[add( i, N_ZERO_O_NB )] ), 6 ) ); /*win[(3*L/2-1-i)*decimate+decay-L_FRAME48k*14/20];*/ + move16(); + ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); + move16(); } } @@ -1736,24 +1793,28 @@ void HQ_FEC_Mem_update_fx( L = L_FRAME8k; move16(); - FOR( i = N_ZERO_O_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_O_NB; i < shr( L, 1 ); i++ ) { /*ImdctOutWin[L/2 + i] = -ImdctOut[L - 1 - i];*/ /*ImdctOutWin[3*L/2 + i] = -ImdctOut[i] * win[L/2-i-1];*/ - ImdctOutWin_fx[L / 2 + i] = extract_l( L_shr( L_negate( ImdctOut_fx[L - 1 - i] ), 6 ) ); - ImdctOutWin_fx[3 * L / 2 + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[L / 2 - i - 1] ), 6 ) ); + ImdctOutWin_fx[add( shr( L, 1 ), i )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( L, 1 ), i )] ), 6 ) ); + move16(); + ImdctOutWin_fx[add( shr( imult1616( 3, L ), 1 ), i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[i] ), win_fx[sub( sub( shr( L, 1 ), i ), 1 )] ), 6 ) ); + move16(); } FOR( i = 0; i < N_ZERO_NB; i++ ) { /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i];*/ - ImdctOutWin_fx[L + i] = extract_l( L_shr( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), 6 ) ); + ImdctOutWin_fx[add( L, i )] = extract_l( L_shr( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), 6 ) ); + move16(); } - FOR( i = N_ZERO_NB; i < L / 2; i++ ) + FOR( i = N_ZERO_NB; i < shr( L, 1 ); i++ ) { /*ImdctOutWin[L + i] = -ImdctOut[L/2 - 1 - i] * win[L - 1 - i];*/ - ImdctOutWin_fx[L + i] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[L / 2 - 1 - i] ), win_fx[L - 1 - i] ), 6 ) ); + ImdctOutWin_fx[add( L, i )] = extract_l( L_shr( Mult_32_16( L_negate( ImdctOut_fx[sub( sub( shr( L, 1 ), 1 ), i )] ), win_fx[sub( sub( L, 1 ), i )] ), 6 ) ); + move16(); } return; @@ -1828,7 +1889,7 @@ void HQ_FEC_Mem_update_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_flag, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_next, 0 ) ) ) + IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) && ( EQ_16( hHQ_nbfec->phase_mat_flag, 1 ) ) && ( hHQ_nbfec->phase_mat_next == 0 ) ) { IF( FEC_phase_matching_fx( hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx ) ) { @@ -1874,9 +1935,11 @@ void HQ_FEC_Mem_update_fx( Word16 tmp; tmp = 0; + move16(); if ( GT_16( st_fx->old_bfi_cnt, 1 ) ) { tmp = 1; + move16(); } Repetition_smoothing_nextgood_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, tmp, N_LEAD_NB ); *Q_synth = 0; @@ -1939,9 +2002,9 @@ void HQ_FEC_Mem_update_fx( L = L_FRAME8k; move16(); - FOR( i = 0; i < L + 25; i++ ) + FOR( i = 0; i < add( L, 25 ); i++ ) { - win_NB_fx[i] = window_48kHz_fx[i * 6 + 3]; + win_NB_fx[i] = window_48kHz_fx[add( imult1616( i, 6 ), 3 )]; move16(); } @@ -1953,7 +2016,7 @@ void HQ_FEC_Mem_update_fx( Smoothing_vector_scaledown_NB_fx( &OldauOut_fx[N_ZERO_NB], &ImdctOutWin_fx[N_Z_L_O_NB], SmoothingWin_NB875_fx, &OldauOut_fx[N_ZERO_NB], ol_size ); /* Scale down the overlapped signal */ - Scaledown_fx( &ImdctOutWin_fx[ol_size + N_Z_L_O_NB], &OldauOut_fx[ol_size + N_ZERO_NB], 23170, N_Z_L_NB - ol_size ); + Scaledown_fx( &ImdctOutWin_fx[add( ol_size, N_Z_L_O_NB )], &OldauOut_fx[add( ol_size, N_ZERO_NB )], 23170, sub( N_Z_L_NB, ol_size ) ); /* Common Overlapping */ common_overlapping_fx( auOut_fx, ImdctOutWin_fx, OldauOut_fx, N_Z_L_NB, N_ZERO_NB, 0, N_ZERO_NB, L, N_Z_L_NB ); diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index e43cf7f25c08a08096f04a7f1f6b73e8100c18e1..7d75f0029e5deca8e1b070c487aa12ade6225207 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -193,7 +193,7 @@ static Word16 ivas_imax2_jacobsen_mag_fx( denom = L_add( L_mult0( D_re, D_re ), L_mult0( D_im, D_im ) ); test(); - IF( NE_32( numer, 0 ) && NE_32( denom, 0 ) ) + IF( numer != 0 && denom != 0 ) { tmp = BASOP_Util_Divide3232_Scale( numer, denom, &tmp_e ); tmp = shl_sat( tmp, tmp_e ); // Q15 @@ -202,6 +202,7 @@ static Word16 ivas_imax2_jacobsen_mag_fx( ELSE { posi = 0; /* flat top, division is not possible choose center freq */ + move16(); } return posi; @@ -296,6 +297,7 @@ static void fft_spec2_fx( pMagSq = &xMagSq[0]; pRe = &x[0]; *pMagSq++ = L_mult0( *pRe, *pRe ); + move32(); pRe++; /* Non-fractional multiply gives subsequent group power accumulation a bit headroom. */ /* From 1 to (N/2 - 1). */ @@ -357,7 +359,16 @@ static void trans_ana_fx( Word32 acc; Lgw = 0; + move16(); LtranaLogMinus1 = 0; + move16(); + + move16(); // att_always + move16(); // burst_phdith_thresh + move16(); // burst_att_thresh + move16(); // att_per_frame + move16(); // burst_phdith_rampup_len + pFftTbl = NULL; /* Initialisation to prevent warnings */ @@ -385,13 +396,11 @@ static void trans_ana_fx( oneOverFrame = 51; /* 1/640 in Q15 */ move16(); w_hamm = w_hamm32k_2_fx; - move16(); Lgw = LGW32K; move16(); Lprot = 1024; move16(); pFftTbl = FFT_W128; /* Table for 256 real input radix-2 FFT */ - move16(); LtranaLogMinus1 = LTRANALOG32K - 1; move16(); } @@ -400,13 +409,11 @@ static void trans_ana_fx( oneOverFrame = 102; /* 1/320 in Q15 */ move16(); w_hamm = w_hamm16k_2_fx; - move16(); Lgw = LGW16K; move16(); Lprot = 512; move16(); pFftTbl = FFT_W64; /* Table for 128 real input radix-2 FFT */ - move16(); LtranaLogMinus1 = LTRANALOG16K - 1; move16(); } @@ -516,7 +523,9 @@ static void trans_ana_fx( /* band powers in frequency groups * exclude bin at PI from calculation */ magSqLeft[Ltrana_2] = L_deposit_l( 0 ); + move32(); magSqRight[Ltrana_2] = L_deposit_l( 0 ); + move32(); } pGrPowLeft = &gr_pow_left[0]; @@ -536,7 +545,9 @@ static void trans_ana_fx( pLeft = magSqLeft + lowerEdge; pRight = magSqRight + lowerEdge; *pGrPowLeft = L_deposit_l( 0 ); + move32(); *pGrPowRight = L_deposit_l( 0 ); + move32(); FOR( i = 0; i < l; i++ ) { acc = L_shr( *pLeft++, headroom ); /* Scale down to prevent from saturation. */ @@ -561,6 +572,7 @@ static void trans_ana_fx( expo = shr( expo, 1 ); Xavg[k] = round_fx( L_shl( acc, sub( sub( 16, expo ), 2 ) ) ); /* Q0, additional right shift by 2 to account for that Xavg is calculated using lenght N/4 fft but is applied on a fft of length N */ + move16(); /*dither phase in case of transient */ /* separate transition detection and application of forced burst dithering */ @@ -598,7 +610,7 @@ static void trans_ana_fx( #endif att_val = 32767; move16(); - IF( GT_32( *pGrPowRight, 0 ) ) + IF( *pGrPowRight > 0 ) { IF( LT_32( *pGrPowRight, *pGrPowLeft ) ) /* i.e., (gr_pow_right/gr_pow_left) < 1.0 */ { @@ -652,10 +664,12 @@ static void trans_ana_fx( move16(); } mag_chg[k] = mult_r( mag_chg_1st[k], att_val ); /* Q15 */ + move16(); - if ( GT_16( burst_len, BETA_MUTE_THR ) ) + IF( GT_16( burst_len, BETA_MUTE_THR ) ) { *beta_mute = shr( *beta_mute, 1 ); + move16(); } alpha[k] = mag_chg[k]; move16(); @@ -674,10 +688,12 @@ static void trans_ana_fx( IF( GE_16( k, LGW32K - 1 ) ) { beta[k] = mult_r( beta[k], 3277 ); /* 0.1 in Q15 */ + move16(); } ELSE IF( GE_16( k, LGW16K - 1 ) ) { beta[k] = mult_r( beta[k], 16384 ); /* 0.5 in Q15 */ + move16(); } } pGrPowLeft++; @@ -721,7 +737,7 @@ static void ivas_peakfinder_fx( FOR( i = 0; i < len0Minus1; i++ ) { - IF( EQ_16( dx0[i], 0 ) ) + if ( dx0[i] == 0 ) { dx0[i] = -1; move16(); @@ -756,6 +772,7 @@ static void ivas_peakfinder_fx( IF( s_xor( *pDx01++, *pDx0++ ) < 0 ) /* Detect sign change. */ { *pInd++ = add( i, 1 ); + move16(); *pX++ = *pX0; move16(); len = add( len, 1 ); @@ -775,7 +792,7 @@ static void ivas_peakfinder_fx( pInd = indarr; test(); test(); - IF( GT_16( len, 2 ) || ( !endpoints && ( GT_16( len, 0 ) ) ) ) + IF( GT_16( len, 2 ) || ( !endpoints && ( len > 0 ) ) ) { /* Set initial parameters for loop */ tempMag = minMag; @@ -786,7 +803,7 @@ static void ivas_peakfinder_fx( move16(); threshold = add( leftMin, sel ); - IF( GT_16( len, 0 ) ) + IF( len > 0 ) { /* Deal with first point a little differently since tacked it on Calculate the sign of the derivative since we took the first point @@ -819,6 +836,7 @@ static void ivas_peakfinder_fx( ELSE /* First point is smaller than the second */ { ii = 0; + move16(); IF( LT_16( xAt1, xAt2 ) ) /* x[1] is not extremum -> overwrite with x[0] */ { *pX = xAt0; /* x[1] = x[0] */ @@ -836,11 +854,13 @@ static void ivas_peakfinder_fx( { // PMTE () ii = -1; /* First point is a peak */ + move16(); IF( GE_16( len, 2 ) ) { - IF( GE_16( x[1], x[0] ) ) + if ( GE_16( x[1], x[0] ) ) { ii = 0; /* First point is a valley, skip it */ + move16(); } } } @@ -860,7 +880,7 @@ static void ivas_peakfinder_fx( /*Reset peak finding if we had a peak and the next peak is bigger than the last or the left min was small enough to reset.*/ - IF( GT_16( foundPeak, 0 ) ) + IF( foundPeak > 0 ) { tempMag = minMag; move16(); @@ -885,7 +905,7 @@ static void ivas_peakfinder_fx( pX++; /* Come down at least sel from peak */ - IF( EQ_16( foundPeak, 0 ) ) + IF( foundPeak == 0 ) { IF( GT_16( tempMag, add( sel, *pX ) ) ) { @@ -899,9 +919,10 @@ static void ivas_peakfinder_fx( peakMag[*cInd] = tempMag; move16(); *cInd = add( *cInd, 1 ); + move16(); } } - IF( EQ_16( foundPeak, 0 ) ) /* The above IF-block has not found the peak yet. */ + IF( foundPeak == 0 ) /* The above IF-block has not found the peak yet. */ { IF( LT_16( *pX, leftMin ) ) /* New left minimum */ { @@ -922,11 +943,12 @@ static void ivas_peakfinder_fx( peakMag[*cInd] = x[lenMinus1]; move16(); *cInd = add( *cInd, 1 ); + move16(); foundPeak = 1; move16(); } } - IF( EQ_16( foundPeak, 0 ) ) /* Check if we still need to add the last point */ + IF( foundPeak == 0 ) /* Check if we still need to add the last point */ { IF( GT_16( tempMag, minMag ) ) { @@ -935,6 +957,7 @@ static void ivas_peakfinder_fx( peakMag[*cInd] = tempMag; move16(); *cInd = add( *cInd, 1 ); + move16(); } } @@ -943,7 +966,6 @@ static void ivas_peakfinder_fx( { plocs[i] = *( indarr + peakLoc[i] ); move16(); - move16(); } } ELSE /* This is a monotone function where an endpoint is the only peak */ @@ -952,7 +974,7 @@ static void ivas_peakfinder_fx( { xInd = 1; move16(); - IF( GT_16( x[0], x[1] ) ) + if ( GT_16( x[0], x[1] ) ) { xInd = 0; move16(); @@ -1004,6 +1026,7 @@ static void peakfinder_fx( Word16 *pInd; tempLoc = 0; + move16(); /* Find derivative */ len0Minus1 = sub( len0, 1 ); @@ -1049,6 +1072,7 @@ static void peakfinder_fx( IF( s_xor( *pDx01++, *pDx0++ ) < 0 ) /* Detect sign change. */ { *pInd++ = add( i, 1 ); + move16(); *pX++ = *pX0; move16(); len = add( len, 1 ); @@ -1120,6 +1144,7 @@ static void peakfinder_fx( ELSE /* First point is smaller than the second */ { ii = 0; + move16(); IF( LT_16( xAt1, xAt2 ) ) /* x[1] is not extremum -> overwrite with x[0] */ { *pX = xAt0; /* x[1] = x[0] */ @@ -1163,7 +1188,7 @@ static void peakfinder_fx( /*Reset peak finding if we had a peak and the next peak is bigger than the last or the left min was small enough to reset.*/ - IF( GT_16( foundPeak, 0 ) ) + IF( foundPeak > 0 ) { tempMag = minMag; move16(); @@ -1202,6 +1227,7 @@ static void peakfinder_fx( peakMag[*cInd] = tempMag; move16(); *cInd = add( *cInd, 1 ); + move16(); } } IF( foundPeak == 0 ) /* The above IF-block has not found the peak yet. */ @@ -1238,6 +1264,7 @@ static void peakfinder_fx( peakMag[*cInd] = tempMag; move16(); *cInd = add( *cInd, 1 ); + move16(); } } @@ -1246,7 +1273,6 @@ static void peakfinder_fx( { plocs[i] = *( indarr + peakLoc[i] ); move16(); - move16(); } } ELSE /* This is a monotone function where an endpoint is the only peak */ @@ -1304,6 +1330,7 @@ static Word16 imax_fx( /* o: The location, relative to the Word32 numer, denom, sign, acc, y3_y1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Seek the extremum of the parabola P(x) defined by 3 consecutive points so that P([-1 0 1]) = [y1 y2 y3] */ @@ -1350,11 +1377,11 @@ static Word16 imax_fx( /* o: The location, relative to the /* For both edges (left and right), the extremum found above may be minimum. * It needs to reject the minimum. */ - IF( NE_16( special, 0 ) ) /* Either edge specical case. */ + IF( special != 0 ) /* Either edge specical case. */ { edge = 0x7fff; /* 1 in Q15 for the right edge special case */ move16(); - if ( LT_16( special, 0 ) ) + if ( special < 0 ) { edge = 0; /* Left edge special case */ move16(); @@ -1366,7 +1393,7 @@ static Word16 imax_fx( /* o: The location, relative to the * Therefore, the slope at y=0 is simply B. Use this slope to determine * if the parabola is concave upward or downward. */ - IF( GT_16( posi, 0 ) ) /* The extremum is in between the middle and the right given data points. */ + IF( posi > 0 ) /* The extremum is in between the middle and the right given data points. */ { IF( LE_16( y3, y1 ) ) /* Check the slope at y=0, i.e., at the middle given data point. */ { @@ -1430,10 +1457,13 @@ static void ivas_spec_ana_fx( Word16 currPlocs, endPlocs, nJacob, k, i; Word32 sig, noise, st_point, end_point; + move16(); // LprotLog2Minus1 + move16(); // hamm_len2 Lprot = 512; /* 1536=(2*output_frame)*1024/1280; */ move16(); sinTblOffset = 0; + move16(); IF( EQ_16( output_frame, L_FRAME48k ) ) { @@ -1482,7 +1512,7 @@ static void ivas_spec_ana_fx( IF( EQ_16( output_frame, L_FRAME48k ) ) { /* Apply hamming-rect window */ - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { windowing( xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2 ); } @@ -1490,12 +1520,13 @@ static void ivas_spec_ana_fx( { // PMTE() window_corr = w_hamm[0]; - window_corr_step = w_hamm[0] / hamm_len2; + move16(); + window_corr_step = idiv1616( w_hamm[0], hamm_len2 ); FOR( i = 0; i < hamm_len2; i++ ) { xfp[i] = mult_r( shl( prevsynth[i], *Q ), sub( w_hamm[i], window_corr ) ); move16(); - xfp[Lprot - i - 1] = mult_r( shl( prevsynth[Lprot - i - 1], *Q ), sub( w_hamm[i], window_corr ) ); + xfp[sub( sub( Lprot, i ), 1 )] = mult_r( shl( prevsynth[sub( sub( Lprot, i ), 1 )], *Q ), sub( w_hamm[i], window_corr ) ); move16(); window_corr = sub( window_corr, window_corr_step ); } @@ -1505,7 +1536,7 @@ static void ivas_spec_ana_fx( } ELSE { - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { /* Apply hamming-rect window */ windowing_ROM_optimized( xfp, xfp, sinTblOffset, rectLength, hamm_len2 ); @@ -1514,12 +1545,13 @@ static void ivas_spec_ana_fx( { // PMTE() window_corr = w_hamm[0]; - window_corr_step = w_hamm[0] / hamm_len2; + move16(); + window_corr_step = idiv1616( w_hamm[0], hamm_len2 ); FOR( i = 0; i < hamm_len2; i++ ) { xfp[i] = mult_r( shl( prevsynth[i], *Q ), sub( w_hamm[i], window_corr ) ); move16(); - xfp[Lprot - i - 1] = mult_r( shl( prevsynth[Lprot - i - 1], *Q ), sub( w_hamm[i], window_corr ) ); + xfp[sub( sub( Lprot, i ), 1 )] = mult_r( shl( prevsynth[sub( sub( Lprot, i ), 1 )], *Q ), sub( w_hamm[i], window_corr ) ); move16(); window_corr = sub( window_corr, window_corr_step ); } @@ -1557,6 +1589,7 @@ static void ivas_spec_ana_fx( IF( *pMagSq == 0 ) { *pXfp++ = extract_l( *pMagSq++ ); /* magSq[] is zero */ + move16(); } ELSE { @@ -1577,7 +1610,7 @@ static void ivas_spec_ana_fx( /* Find maximum and minimum. */ maximum_fx( xfp, Lprot2_1, &Xmax ); minimum_fx( xfp, Lprot2_1, &Xmin ); - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_PFIND_SENS_FX ); } @@ -1589,12 +1622,13 @@ static void ivas_spec_ana_fx( /* Currently not the pitch correlation but some LF correlation */ - IF( element_mode != EVS_MONO && *num_plocs > 50 && pcorr < 19661 /* 0.6f in Q15 */ ) + if ( element_mode != EVS_MONO && *num_plocs > 50 && pcorr < 19661 /* 0.6f in Q15 */ ) { *num_plocs = 0; + move16(); } - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { /* Refine peaks */ @@ -1602,7 +1636,7 @@ static void ivas_spec_ana_fx( pPlocs = plocs; n = sub( *num_plocs, 1 ); /* -1 so as to exclude the very last peak. */ /* Special case-- The very 1st peak if it is at 0 index position */ - IF( EQ_16( *pPlocs, 0 ) ) /* Only the very 1st peak is possible the peak at 0 index position. */ + IF( *pPlocs == 0 ) /* Only the very 1st peak is possible the peak at 0 index position. */ { fraction = imax_fx( xfp, -1 ); /* -1 signifies special left edge case. */ acc = L_deposit_h( *pPlocs++ ); /* N.B., (*pPlocs) must be zero here. */ @@ -1656,7 +1690,7 @@ static void ivas_spec_ana_fx( /* With DELTA_CORR_F0_INT == 2 one needs to handle both *pPlocs==0 and *pPlocs==1 */ // IF( n > 0 && *pPlocs == 0 ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ test(); - IF( GT_16( n, 0 ) && EQ_16( *pPlocs, 0 ) ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ + IF( n > 0 && *pPlocs == 0 ) /* Very 1st peak position possible to have a peak at 0/DC index position. */ { fraction = imax_fx( &xfp[*pPlocs], -1 ); /* in Q15 */ acc = L_deposit_h( *pPlocs ); @@ -1667,7 +1701,7 @@ static void ivas_spec_ana_fx( } test(); - IF( GT_16( n, 0 ) && EQ_16( *pPlocs, 1 ) ) /* Also 2nd peak position uses DC which makes jacobsen unsuitable. */ + IF( n > 0 && EQ_16( *pPlocs, 1 ) ) /* Also 2nd peak position uses DC which makes jacobsen unsuitable. */ { fraction = imax_fx( &xfp[*pPlocs - 1], -1 ); /* in Q15 */ acc = L_deposit_h( *pPlocs - 1 ); @@ -1684,18 +1718,18 @@ static void ivas_spec_ana_fx( endPlocs = sub( Lprot2_1, DELTA_CORR_F0_INT ); /* last *pPlocs position for Jacobsen */ /* precompute number of turns based on endpoint integer location and make into a proper for loop */ - IF( GT_16( n, 0 ) ) + IF( n > 0 ) { nJacob = n; move16(); - IF( LE_16( sub( endPlocs, plocs[sub( *num_plocs, 1 )] ), 0 ) ) + if ( sub( endPlocs, plocs[sub( *num_plocs, 1 )] <= 0 ) ) { nJacob = sub( nJacob, 1 ); } FOR( k = 0; k < nJacob; k++ ) { - fraction = ivas_imax2_jacobsen_mag_fx( &( X_sav[currPlocs - 1] ), &( X_sav[Lprot - 1 - currPlocs] ) ); /* in Q15 */ + fraction = ivas_imax2_jacobsen_mag_fx( &( X_sav[currPlocs - 1] ), &( X_sav[sub( sub( Lprot, 1 ), currPlocs )] ) ); /* in Q15 */ acc = L_deposit_h( currPlocs ); *pPlocsi++ = L_mac( acc, fraction, 1 ); move32(); @@ -1707,7 +1741,7 @@ static void ivas_spec_ana_fx( /* At this point there should at most two plocs left to process */ /* the position before fs/2 and fs/2 both use the same magnitude points */ - IF( GT_16( n, 0 ) ) + IF( n > 0 ) { /* [ . . . . . . . ] Lprot/2+1 positions */ /* | | | */ @@ -1716,7 +1750,7 @@ static void ivas_spec_ana_fx( IF( EQ_16( currPlocs, ( sub( Lprot2_1, DELTA_CORR_F0_INT ) ) ) ) /* Also 2nd last peak position uses fs/2 which makes jacobsen less suitable. */ { fraction = imax_fx( &xfp[currPlocs - 1], 0 ); /* in Q15 */ - acc = L_deposit_h( currPlocs - 1 ); + acc = L_deposit_h( sub( currPlocs, 1 ) ); *pPlocsi++ = L_mac( acc, fraction, 1 ); move32(); currPlocs = *pPlocs++; @@ -1727,10 +1761,10 @@ static void ivas_spec_ana_fx( /* Here the only remaining point would be a fs/2 plocs */ /* pXfp = xfp + sub(Lprot2,1); already set just a reminder where it * whould point */ - IF( GT_16( n, 0 ) ) /* fs/2 which makes special case . */ + IF( n > 0 ) /* fs/2 which makes special case . */ { fraction = imax_fx( &xfp[currPlocs - 2], 0 ); /* in Q15 */ - acc = L_deposit_h( currPlocs - 2 ); + acc = L_deposit_h( sub( currPlocs, 2 ) ); *pPlocsi++ = L_mac( acc, fraction, 1 ); move32(); currPlocs = *pPlocs++; @@ -1741,18 +1775,18 @@ static void ivas_spec_ana_fx( /* For few peaks decide noise floor attenuation */ test(); - IF( LT_16( *num_plocs, 3 ) && GT_16( *num_plocs, 0 ) ) + IF( LT_16( *num_plocs, 3 ) && *num_plocs > 0 ) { - sig = sum16_32_fx( xfp, Lprot2_1 ) + 1; + sig = L_add( sum16_32_fx( xfp, Lprot2_1 ), 1 ); /*excluding peaks and neighboring bins*/ FOR( i = 0; i < *num_plocs; i++ ) { - st_point = s_max( 0, plocs[i] - DELTA_CORR ); - end_point = s_min( Lprot2_1 - 1, plocs[i] + DELTA_CORR ); - set16_fx( &xfp[st_point], 0, (Word16) ( end_point - st_point + 1 ) ); + st_point = s_max( 0, sub( plocs[i], DELTA_CORR ) ); + end_point = s_min( sub( Lprot2_1, 1 ), add( plocs[i], DELTA_CORR ) ); + set16_fx( &xfp[st_point], 0, extract_l( L_add( L_sub( end_point, st_point ), 1 ) ) ); } - noise = sum16_32_fx( xfp, Lprot2_1 ) + 1; + noise = L_add( sum16_32_fx( xfp, Lprot2_1 ), 1 ); IF( LT_32( noise, Mpy_32_32( 64424509 /* 0.03 in Q31 */, sig ) ) ) { @@ -1798,10 +1832,13 @@ static void spec_ana_fx( Word16 stop_band_start; Word16 stop_band_length; + move16(); // LprotLog2Minus1 + move16(); // hamm_len2 Lprot = 512; /* 1536=(2*output_frame)*1024/1280; */ move16(); sinTblOffset = 0; + move16(); IF( EQ_16( output_frame, L_FRAME48k ) ) { @@ -1984,7 +2021,7 @@ static void spec_ana_fx( pPlocs = plocs; n = sub( *num_plocs, 1 ); /* -1 so as to exclude the very last peak. */ /* Special case-- The very 1st peak if it is at 0 index position */ - IF( EQ_16( *pPlocs, 0 ) ) /* Only the very 1st peak is possible the peak at 0 index position. */ + IF( *pPlocs == 0 ) /* Only the very 1st peak is possible the peak at 0 index position. */ { fraction = imax_fx( xfp, -1 ); /* -1 signifies special left edge case. */ acc = L_deposit_h( *pPlocs++ ); /* N.B., (*pPlocs) must be zero here. */ @@ -2210,6 +2247,7 @@ static void ivas_subst_spec_fx( { // tmp = NS2SA(output_frame*50,PH_ECU_ALDO_OLP2_NS-PH_ECU_LOOKAHEAD_NS); tmp = NS2SA( output_frame * 50, PH_ECU_ALDO_OLP2_NS ); + move16(); tmp = sub( tmp, ph_ecu_lookahead ); tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); tmp = sub( tmp, shr( output_frame, 1 ) ); @@ -2228,19 +2266,19 @@ static void ivas_subst_spec_fx( } one_peak_flag_mask = 32767 /* 1.0f in Q15 */; /* all ones mask -> keep */ move16(); - IF( NE_16( element_mode, EVS_MONO ) ) + IF( element_mode != EVS_MONO ) { test(); - IF( ( GT_16( *num_plocs, 0 ) ) && LT_16( sub( *num_plocs, 3 ), 0 ) ) + if ( ( *num_plocs > 0 ) && ( sub( *num_plocs, 3 ) < 0 ) ) { one_peak_flag_mask = noise_fac; /* all zeroes mask -> zero */ move16(); } - IF( EQ_16( *num_plocs, 0 ) ) + IF( *num_plocs == 0 ) { X[0] = 0; /* reset DC if there are no peaks */ move16(); - X[shr( Lprot, 1 )] = 0; /* also reset fs/2 if there are no peaks */ + X[Lprot / 2] = 0; /* also reset fs/2 if there are no peaks */ move16(); } } @@ -2273,10 +2311,10 @@ static void ivas_subst_spec_fx( move16(); pkLocation1 = *pPlocs++; /* plocs[m + 1] */ move16(); - IF( GT_16( m, 0 ) ) + IF( m > 0 ) { delta_tmp = shr( sub( sub( pkLocation, pkLocation_1 ), 1 ), 1 ); - IF( LT_16( delta_tmp, DELTA_CORR ) ) + if ( LT_16( delta_tmp, DELTA_CORR ) ) { delta_corr_dn = delta_tmp; move16(); @@ -2286,7 +2324,7 @@ static void ivas_subst_spec_fx( IF( LT_16( m, lastPeak ) ) { delta_tmp = shr( sub( sub( pkLocation1, pkLocation ), 1 ), 1 ); - IF( LT_16( delta_tmp, DELTA_CORR ) ) + if ( LT_16( delta_tmp, DELTA_CORR ) ) { delta_corr_up = delta_tmp; move16(); @@ -2304,7 +2342,7 @@ static void ivas_subst_spec_fx( move16(); im = *pImX; move16(); - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); @@ -2317,6 +2355,7 @@ static void ivas_subst_spec_fx( IF( LT_16( alpha[k], 32766 ) ) { *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); tmp2 = mult_r( beta[k], Xavg[k] ); *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); move16(); @@ -2331,20 +2370,21 @@ static void ivas_subst_spec_fx( move16(); } i = add( i, 1 ); - IF( GE_16( i, ivas_gwlpr[k + 1] ) ) + if ( GE_16( i, ivas_gwlpr[k + 1] ) ) { k = add( k, 1 ); } } e = add( pkLocation, delta_corr_up ); - IF( GT_16( e, lprotBy2Minus1 ) ) + if ( GT_16( e, lprotBy2Minus1 ) ) { e = lprotBy2Minus1; move16(); } Xph = *pCorrPhase; + move32(); Xph_short = s_and( extract_l( L_shr( Xph, 16 - 10 ) ), 0x3ff ); /* 10 bits precision after radix point */ IF( GE_16( Xph_short, 512 ) ) { @@ -2380,15 +2420,16 @@ static void ivas_subst_spec_fx( { mag_chg_local = mag_chg[k]; move16(); - IF( NE_16( ph_dith, 0 ) ) + IF( ph_dith != 0 ) { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + move32(); Random( seed ); /* in Q0 */ acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); Xph = L_add( Xph, acc ); /* in Q16. */ - IF( GT_16( ph_dith, 0 ) ) /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized ) */ + IF( ph_dith > 0 ) /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized ) */ { /* mag_chg_local *= 0.5 + (1.0 - ph_dith[i])/2 where 0.5~= sqrt((float)pow(10.0,-6/10.0)) and ph_dith=0..1.0--> scale=1.0 ...5 */ mag_chg_local = mult_r( mag_chg_local, sub( 32767, shr( ph_dith, 1 ) ) ); @@ -2437,7 +2478,7 @@ static void ivas_subst_spec_fx( acc = L_sub( 1073741824L, L_mult0( alpha_local, alpha_local ) ); acc = Sqrt_l( acc, &expo ); expo = add( 30, add( 31, expo ) ); - IF( EQ_16( s_and( expo, 1 ), 1 ) ) + if ( EQ_16( s_and( expo, 1 ), 1 ) ) { acc = Mult_32_16( acc, 23170 ); /* 1/sqrt(2) in Q15 */ } @@ -2454,6 +2495,7 @@ static void ivas_subst_spec_fx( } *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); tmp2 = mult_r( beta_local, Xavg[k] ); *pReX++ = add( mult_r( alpha_local, tmp ), mult_r( tmp2, cos_F ) ); move16(); @@ -2469,7 +2511,7 @@ static void ivas_subst_spec_fx( } i = add( i, 1 ); - IF( GE_16( i, ivas_gwlpr[k + 1] ) ) + if ( GE_16( i, ivas_gwlpr[k + 1] ) ) { k = add( k, 1 ); } @@ -2481,6 +2523,7 @@ static void ivas_subst_spec_fx( FOR( j = 0; j < segmentLen; j++ ) { *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); re = *pReX; move16(); @@ -2488,7 +2531,7 @@ static void ivas_subst_spec_fx( move16(); - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); @@ -2501,6 +2544,7 @@ static void ivas_subst_spec_fx( IF( LT_16( alpha[k], 32766 ) ) { *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); tmp2 = mult_r( beta[k], Xavg[k] ); *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); move16(); @@ -2516,7 +2560,7 @@ static void ivas_subst_spec_fx( } i = add( i, 1 ); - IF( GE_16( i, ivas_gwlpr[k + 1] ) ) + if ( GE_16( i, ivas_gwlpr[k + 1] ) ) { k = add( k, 1 ); } @@ -2609,6 +2653,7 @@ static void subst_spec_fx( ELSE { tmp = NS2SA( output_frame * 50, PH_ECU_ALDO_OLP2_NS - PH_ECU_LOOKAHEAD_NS ); + move16(); tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); tmp = sub( tmp, shr( output_frame, 1 ) ); tmp = add( tmp, time_offs ); @@ -2717,6 +2762,7 @@ static void subst_spec_fx( IF( LT_16( alpha[k], 32766 ) ) { *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); tmp2 = mult_r( beta[k], Xavg[k] ); *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); move16(); @@ -2745,6 +2791,7 @@ static void subst_spec_fx( } Xph = *pCorrPhase; + move32(); Xph_short = s_and( extract_l( L_shr( Xph, 16 - 10 ) ), 0x3ff ); /* 10 bits precision after radix point */ IF( GE_16( Xph_short, 512 ) ) { @@ -2782,7 +2829,8 @@ static void subst_spec_fx( move16(); IF( ph_dith != 0 ) { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + move32(); Random( seed ); /* in Q0 */ acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); @@ -2866,12 +2914,13 @@ static void subst_spec_fx( { beta_local = mult_r( beta_local, 3277 ); /* 0.1 in Q15 */ } - ELSE if ( GE_16( k, LGW16K - 1 ) ) + ELSE IF( GE_16( k, LGW16K - 1 ) ) { beta_local = mult_r( beta_local, 16384 ); /* 0.5 in Q15 */ } *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); tmp2 = mult_r( beta_local, Xavg[k] ); *pReX++ = add( mult_r( alpha_local, tmp ), mult_r( tmp2, cos_F ) ); move16(); @@ -2899,6 +2948,7 @@ static void subst_spec_fx( FOR( j = 0; j < segmentLen; j++ ) { *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); re = *pReX; move16(); @@ -2909,6 +2959,7 @@ static void subst_spec_fx( IF( LT_16( alpha[k], 32766 ) ) { *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); + move16(); tmp2 = mult_r( beta[k], Xavg[k] ); *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); move16(); @@ -2968,8 +3019,10 @@ static void ivas_rec_wtda_fx( Word16 copy_len; Word16 ola_len; - copy_len = NS2SA( output_frame * FRAMES_PER_SEC, ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */ + copy_len = NS2SA( output_frame * FRAMES_PER_SEC, ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */ + move16(); ola_len = NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */ + move16(); xf_len = 26; move16(); @@ -2979,6 +3032,7 @@ static void ivas_rec_wtda_fx( { w_hamm = w_hamm_sana48k_2_fx; hamm_len2 = L_PROT_HAMM_LEN2_48k; + move16(); xf_len = 78; move16(); tbl_delta = 3361; /* Q12 */ @@ -2988,6 +3042,7 @@ static void ivas_rec_wtda_fx( { w_hamm = w_hamm_sana32k_2_fx; hamm_len2 = L_PROT_HAMM_LEN2_32k; + move16(); xf_len = 52; move16(); tbl_delta = 5041; /* Q12 */ @@ -2997,15 +3052,16 @@ static void ivas_rec_wtda_fx( { w_hamm = w_hamm_sana16k_2_fx; hamm_len2 = L_PROT_HAMM_LEN2_16k; + move16(); } test(); test(); - IF( NE_16( element_mode, EVS_MONO ) && GT_16( *num_p, 0 ) && GT_16( plocs[0], 3 ) ) + IF( element_mode != EVS_MONO && *num_p > 0 && GT_16( plocs[0], 3 ) ) { /* Perform inverse windowing of hammrect */ pX_start = X; - pX_end = X + Lprot - 1; + pX_end = X + sub( Lprot, 1 ); FOR( i = 0; i < hamm_len2; i++ ) { tmp = BASOP_Util_Divide1616_Scale( 1, *w_hamm, &tmp_e ); @@ -3021,22 +3077,22 @@ static void ivas_rec_wtda_fx( } /* extract reconstructed frame with aldo window */ - timesh = NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ) - ( 2 * output_frame - Lprot ) / 2; + timesh = sub( NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ), shr( sub( shl( output_frame, 1 ), Lprot ), 1 ) ); - set16_fx( xsubst_, 0, 2 * output_frame - Lprot + timesh ); - Copy( X, xsubst_ + 2 * output_frame - Lprot + timesh, Lprot - timesh ); + set16_fx( xsubst_, 0, add( sub( shl( output_frame, 1 ), Lprot ), timesh ) ); + Copy( X, xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ), sub( Lprot, timesh ) ); /* Copy and OLA look ahead zero part of MDCT window from decoded signal */ - IF( NE_16( element_mode, EVS_MONO ) ) + IF( element_mode != EVS_MONO ) { Copy( old_dec, xsubst_ + NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ), copy_len ); /* also need to scale to Q0 ?? */ pOld = old_dec + copy_len; - pNew = xsubst_ + copy_len + NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); + pNew = xsubst_ + add( copy_len, NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ) ); tmp = div_s( 1, shl( ola_len, 1 ) ); // Q15 tmp = round_fx( L_shl( L_mult( tmp, EVS_PI_FX ), 2 ) ); // Q15 sinq_fx( tmp, 0, ola_len, xfwin ); v_mult16_fixed( xfwin, xfwin, xfwin, ola_len ); /* xfwin = sin^2 of 0..pi/4 */ - pOldW = xfwin + ola_len - 1; + pOldW = xfwin + sub( ola_len, 1 ); pNewW = xfwin; FOR( i = 0; i < ola_len; i++ ) { @@ -3051,11 +3107,12 @@ static void ivas_rec_wtda_fx( ELSE { /* Smoothen onset of ECU frame */ - p_ecu = xsubst_ + 2 * output_frame - Lprot + timesh; + p_ecu = xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ); FOR( i = 0; i < xf_len; ( i++, p_ecu++ ) ) { idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); g = sincos_t_fx[idx]; + move16(); g = mult( g, g ); *p_ecu = mult( g, ( *p_ecu ) ); move16(); @@ -3211,11 +3268,12 @@ static void rec_wtda_fx( set16_fx( xsubst_ + add( output_frame, Lprot2 ), 0, l ); /* Smoothen onset of ECU frame */ - p_ecu = xsubst_ + ( output_frame - Lprot2 ); + p_ecu = xsubst_ + sub( output_frame, Lprot2 ); FOR( i = 0; i < xf_len; i++ ) { idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); g = sincos_t_fx[idx]; + move16(); g = mult( g, g ); *p_ecu = mult( g, ( *p_ecu ) ); move16(); @@ -3223,9 +3281,11 @@ static void rec_wtda_fx( } timesh = NS2SA_fx2( fs, 10000000L - PH_ECU_ALDO_OLP2_NS ); + move16(); set16_fx( rec_buf, 0, output_frame ); Qin = 0; + move16(); out_ptr = rec_buf + sub( shl( output_frame, 1 ), timesh ); wtda_fx( out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); @@ -3353,11 +3413,12 @@ static Word32 mult_32_32_q( const Word32 a, const Word32 b, const Word16 q ) UWord32 lo; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Mpy_32_32_ss( a, b, &hi, &lo ); #ifdef BASOP_NOGLOB - return L_or( L_shl_o( hi, 32 - q - 1, &Overflow ), L_lshr( lo, q + 1 ) ); + return L_or( L_shl_o( hi, sub( 32 - 1, q ), &Overflow ), L_lshr( lo, add( q, 1 ) ) ); #else return L_or( L_shl( hi, 32 - q - 1 ), L_lshr( lo, q + 1 ) ); #endif @@ -3390,8 +3451,7 @@ static void fir_dwn_fx( { s = L_deposit_l( 0 ); ptr_h = h + 1; - ptr_x = x + i - 1; - move16(); + ptr_x = x + sub( i, 1 ); FOR( j = 1; j <= i; j++ ) { @@ -3404,6 +3464,7 @@ static void fir_dwn_fx( #ifdef BASOP_NOGLOB *ptr_y++ = extract_h( L_shl_sat( s, centering ) ); + move16(); #else *ptr_y++ = extract_h( L_shl( s, centering ) ); #endif @@ -3412,7 +3473,7 @@ static void fir_dwn_fx( { s = L_deposit_l( 0 ); ptr_h = h + 1; - ptr_x = x + i - 1; + ptr_x = x + sub( i, 1 ); move16(); FOR( j = 1; j <= K; j++ ) @@ -3426,6 +3487,7 @@ static void fir_dwn_fx( #ifdef BASOP_NOGLOB *ptr_y++ = extract_h( L_shl_sat( s, centering ) ); + move16(); #else *ptr_y++ = extract_h( L_shl( s, centering ) ); #endif @@ -3434,9 +3496,9 @@ static void fir_dwn_fx( FOR( i = i; i < tmp; i += decimation ) { s = L_deposit_l( 0 ); - ptr_h = h + i - L + 1; + ptr_h = h + add( sub( i, L ), 1 ); move16(); - ptr_x = x + L - 1; + ptr_x = x + sub( L, 1 ); move16(); FOR( j = add( sub( i, L ), 1 ); j <= K; j++ ) @@ -3450,6 +3512,7 @@ static void fir_dwn_fx( #ifdef BASOP_NOGLOB *ptr_y++ = extract_h( L_shl_sat( s, centering ) ); + move16(); #else *ptr_y++ = extract_h( L_shl( s, centering ) ); #endif @@ -3590,26 +3653,34 @@ static void fec_ecu_pitch_fx( } - IF( HqVoicing == 1 ) + IF( EQ_16( HqVoicing, 1 ) ) { cb_start = 0; + move16(); cb_end = Lon20mul33; + move16(); } ELSE { cb_start = 0; + move16(); cb_end = Lon20mul28; + move16(); } accB = 0; + move16(); delay_ind = cb_start; + move16(); FOR( i = cb_start; i < cb_end; i++ ) /* cb_end = 35 let 6 ms min of loop size */ { accA = 0; - IF( i == cb_start ) + move16(); + IF( EQ_16( i, cb_start ) ) { accB = 0; + move16(); ptr_LP = prevsynth_LP_fx; ptr_LP2 = prevsynth_LP_fx + Lon20mul34; FOR( k = 0; k < Lon20mul6; k++ ) @@ -3646,26 +3717,28 @@ static void fec_ecu_pitch_fx( accCisqrt = Isqrt( accC ); /* Q31 - 3 + tmpQLP*/ - Ryytmp = mult_32_32_q( accA, accCisqrt, 16 + 3 - tmpQLP ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ - Ryytmp = mult_32_32_q( Ryytmp, accBisqrt, 15 - 3 + tmpQLP ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ - Ryy = extract_h( Ryytmp ); /* Q15 */ + Ryytmp = mult_32_32_q( accA, accCisqrt, sub( 16 + 3, tmpQLP ) ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ + Ryytmp = mult_32_32_q( Ryytmp, accBisqrt, add( 15 - 3, tmpQLP ) ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ + Ryy = extract_h( Ryytmp ); /* Q15 */ - IF( Ryy > *min_corr_fx ) + IF( GT_16( Ryy, *min_corr_fx ) ) { *min_corr_fx = Ryy; + move16(); delay_ind = i; + move16(); } test(); - IF( HqVoicing == 0 && *min_corr_fx > 31130 ) + IF( HqVoicing == 0 && GT_16( *min_corr_fx, 31130 ) ) { BREAK; } } *N = sub( Lon20mul34, delay_ind ); - + move16(); Scale_sig( prevsynth_LP_fx, 320, negate( sub( tmpQLP, 3 ) ) ); return; @@ -3710,7 +3783,9 @@ static void sin_cos_est_fx( Word32 phi, Word16 *cosfreq, Word16 *sinfreq ) #endif #ifdef BASOP_NOGLOB *sinfreq = round_fx_sat( sinv ); + move16(); *cosfreq = round_fx_sat( cosv ); + move16(); #else *sinfreq = round_fx( sinv ); *cosfreq = round_fx( cosv ); @@ -3802,7 +3877,7 @@ static void ivas_fec_ecu_dft_fx( Lon20 = 8; move16(); - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { alignment_point = sub( shl( 160, 1 ), i_mult( 3, Lon20 ) ); } @@ -3821,6 +3896,7 @@ static void ivas_fec_ecu_dft_fx( L_tmp = L_shl( L_tmp, 1 ); } *Nfft = shl( 1, sub( 15, tmp ) ); + move16(); set32_fx( Tfr32, 0, *Nfft ); set32_fx( Tfi32, 0, *Nfft ); @@ -3831,7 +3907,7 @@ static void ivas_fec_ecu_dft_fx( IF( EQ_16( *Nfft, N ) ) { - Copy( &target[1], &Tfr16[1], *Nfft - 2 ); + Copy( &target[1], &Tfr16[1], sub( *Nfft, 2 ) ); } ELSE { @@ -3860,6 +3936,7 @@ static void ivas_fec_ecu_dft_fx( /*to avoid overflow in DoRTFTn_fx() */ tmp = Exp16Array( *Nfft, Tfr16 ); *exp = add( tmp, add( 2, norm_s( *Nfft ) ) ); + move16(); Copy_Scale_sig_16_32( Tfr16, Tfr32, *Nfft, *exp ); /*Qin+exp; */ DoRTFTn_fx( Tfr32, Tfi32, *Nfft ); @@ -3876,7 +3953,9 @@ static void ivas_fec_ecu_dft_fx( FOR( i = 0; i < N_LP; i++ ) { *pt1 = extract_h( *Pt1 ); /*Qin+exp-16 */ + move16(); *pt2 = extract_h( *Pt2 ); /*Qin+exp-16 */ + move16(); *pt3 = abs_iter_fx( Tfr[i], Tfi[i], 5 ); move16(); /*Qin+exp-16 */ L_tmp = L_mac0( L_tmp, *pt3, 1 ); /*Qin+exp-16 */ @@ -3889,6 +3968,7 @@ static void ivas_fec_ecu_dft_fx( *sum_Tf_abs = L_tmp; move32(); *exp = sub( *exp, 16 ); + move16(); return; } #endif @@ -3936,6 +4016,7 @@ static void fec_ecu_dft_fx( L_tmp = L_shl( L_tmp, 1 ); } *Nfft = shl( 1, sub( 15, tmp ) ); + move16(); set32_fx( Tfr32, 0, *Nfft ); @@ -3947,7 +4028,7 @@ static void fec_ecu_dft_fx( IF( EQ_16( *Nfft, N ) ) { - Copy( &target[1], &Tfr16[1], *Nfft - 2 ); + Copy( &target[1], &Tfr16[1], sub( *Nfft, 2 ) ); } ELSE { @@ -3976,6 +4057,7 @@ static void fec_ecu_dft_fx( /*to avoid overflow in DoRTFTn_fx() */ tmp = Exp16Array( *Nfft, Tfr16 ); *exp = add( tmp, add( 2, norm_s( *Nfft ) ) ); + move16(); Copy_Scale_sig_16_32( Tfr16, Tfr32, *Nfft, *exp ); /*Qin+exp; */ DoRTFTn_fx( Tfr32, Tfi32, *Nfft ); @@ -3992,7 +4074,9 @@ static void fec_ecu_dft_fx( FOR( i = 0; i < N_LP; i++ ) { *pt1 = extract_h( *Pt1 ); /*Qin+exp-16 */ + move16(); *pt2 = extract_h( *Pt2 ); /*Qin+exp-16 */ + move16(); *pt3 = abs_iter_fx( Tfr[i], Tfi[i], 5 ); move16(); /*Qin+exp-16 */ L_tmp = L_mac0( L_tmp, *pt3, 1 ); /*Qin+exp-16 */ @@ -4005,6 +4089,7 @@ static void fec_ecu_dft_fx( *sum_Tf_abs = L_tmp; move32(); *exp = sub( *exp, 16 ); + move16(); return; } @@ -4108,6 +4193,8 @@ static void sinusoidal_synthesis_fx( Word32 synthesis_fx[2 * L_FRAME48k]; Word16 *pt1, *pt2, *pt3, *pt4; + move16(); // indmax + move16(); // Lon20_10 flag = HqVoicing; move16(); if ( GT_16( N, Lon20_10 ) ) @@ -4331,7 +4418,7 @@ static void ivas_fec_noise_filling_fx( Word16 alignment_point; // PMTE() L20 = extract_h( L_mult( 1639, L ) ); /*L/20 */ - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { alignment_point = sub( shl( L, 1 ), i_mult2( 3, L20 ) ); } @@ -4353,7 +4440,7 @@ static void ivas_fec_noise_filling_fx( sinq_tab = sinq_16k; } - Copy( prevsynth_fx + alignment_point - N, noisevect_fx, N ); + Copy( prevsynth_fx + sub( alignment_point, N ), noisevect_fx, N ); /* Noise addition on full band */ /* residual */ @@ -4392,7 +4479,7 @@ static void ivas_fec_noise_filling_fx( flag = ind; move16(); pt5 = synthesis_fx; - WHILE( GT_16( flag, 0 ) ) + WHILE( flag > 0 ) { tmp_fx = Random( ni_seed_forfec ); @@ -4433,7 +4520,7 @@ static void ivas_fec_noise_filling_fx( flag = sub( flag, tmp_fx ); } - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { kk = i_mult2( 7, L20 ); tmp_fx = i_mult2( 37, L20 ); @@ -4458,11 +4545,12 @@ static void ivas_fec_noise_filling_fx( L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ L_tmp = L_mac( L_tmp, ( *pt6++ ), q2 ); /*Qsynth+16 */ ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */ + move16(); } - Copy( synthesis_fx, synthesis_fx + kk, 2 * L - kk ); + Copy( synthesis_fx, synthesis_fx + kk, sub( 2 * L, kk ) ); Copy( synthesis_fx + L, gapsynth_fx, L ); - Copy( prevsynth_fx + alignment_point - kk, synthesis_fx, kk ); + Copy( prevsynth_fx + sub( alignment_point, kk ), synthesis_fx, kk ); } #endif @@ -4644,6 +4732,7 @@ static void fec_noise_filling_fx( L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ L_tmp = L_mac( L_tmp, ( *pt6++ ), q2 ); /*Qsynth+16 */ ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */ + move16(); } } @@ -4685,7 +4774,7 @@ static void ivas_fec_alg_fx( n = R1_16 - R2_16; move16(); - IF( EQ_16( output_frame, L_FRAME32k ) ) + if ( EQ_16( output_frame, L_FRAME32k ) ) { n = 2 * N16_CORE_SW; move16(); @@ -4809,9 +4898,10 @@ static void ivas_hq_phase_ecu_fx( noise_fac = 32767; /* 1.0f in Q15 */ move16(); - IF( EQ_16( element_mode, EVS_MONO ) ) + IF( element_mode == EVS_MONO ) { ph_ecu_lookahead = NS2SA( output_frame * FRAMES_PER_SEC, PH_ECU_LOOKAHEAD_NS ); + move16(); } ELSE { @@ -4828,7 +4918,7 @@ static void ivas_hq_phase_ecu_fx( lprot = L_PROT32k; /* 1024 */ move16(); } - ELSE IF( output_frame == L_FRAME16k ) + ELSE IF( EQ_16( output_frame, L_FRAME16k ) ) { lprot = 512; move16(); @@ -4842,11 +4932,12 @@ static void ivas_hq_phase_ecu_fx( test(); test(); test(); - IF( EQ_16( prev_bfi, 0 ) || ( NE_16( prev_bfi, 0 ) && NE_16( *last_fec, 0 ) && ( EQ_16( *time_offs, output_frame ) ) ) ) + IF( prev_bfi == 0 || ( prev_bfi != 0 && *last_fec != 0 && ( EQ_16( *time_offs, output_frame ) ) ) ) { + test(); test(); // PMT("verify condition compared to float") - IF( !( NE_16( prev_bfi, 0 ) && NE_16( *last_fec, 0 ) && EQ_16( element_mode, EVS_MONO ) ) ) + if ( !( prev_bfi != 0 && *last_fec != 0 && element_mode == EVS_MONO ) ) { *time_offs = 0; move16(); @@ -4859,15 +4950,16 @@ static void ivas_hq_phase_ecu_fx( ivas_spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec, element_mode, &noise_fac, pcorr ); test(); - IF( NE_16( prev_bfi, 0 ) && NE_16( *last_fec, 0 ) ) + IF( prev_bfi != 0 && *last_fec != 0 ) { *time_offs = add( *time_offs, output_frame ); + move16(); } } ELSE { *time_offs = add( *time_offs, output_frame ); - + move16(); offset = sub( shl( output_frame, 1 ), lprot ); trans_ana_fx( prevsynth + offset, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, 0, alpha, beta, beta_mute, Xavg ); @@ -4878,16 +4970,16 @@ static void ivas_hq_phase_ecu_fx( /* seed for own_rand2 */ seed = *time_offs; move16(); - IF( GT_16( *num_p, 0 ) ) + IF( *num_p > 0 ) { - seed = add( seed, plocs[*num_p - 1] ); + seed = add( seed, plocs[sub( *num_p, 1 )] ); } ivas_subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, alpha, beta, *beta_mute, Xavg, element_mode, ph_ecu_lookahead, noise_fac ); /* reconstructed frame in tda domain */ - old_dec = prevsynth + 2 * output_frame - NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); + old_dec = prevsynth + sub( shl( output_frame, 1 ), NS2SA( output_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ) ); ivas_rec_frame_fx( X, ecu_rec, output_frame, *Q_spec, old_dec, element_mode, num_p, plocs ); *last_fec = 0; @@ -4975,7 +5067,7 @@ static void hq_phase_ecu_fx( #ifdef IVAS_FEC_ECU_TO_COMPLETE IF( !( prev_bfi != 0 && *last_fec != 0 ) && EQ_16( element_mode == EVS_MONO ) ) #else - IF( !( prev_bfi != 0 && *last_fec != 0 ) ) + if ( !( prev_bfi != 0 && *last_fec != 0 ) ) #endif { *time_offs = 0; @@ -5001,11 +5093,13 @@ static void hq_phase_ecu_fx( IF( prev_bfi != 0 && *last_fec != 0 ) { *time_offs = add( *time_offs, output_frame ); + move16(); } } ELSE { *time_offs = add( *time_offs, output_frame ); + move16(); offset = sub( shl( output_frame, 1 ), lprot ); trans_ana_fx( prevsynth + offset, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, @@ -5017,9 +5111,9 @@ static void hq_phase_ecu_fx( /* seed for own_rand2 */ seed = *time_offs; move16(); - if ( *num_p > 0 ) + IF( *num_p > 0 ) { - seed = add( seed, plocs[*num_p - 1] ); + seed = add( seed, plocs[sub( *num_p, 1 )] ); } subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, @@ -5042,6 +5136,7 @@ static void hq_phase_ecu_fx( ); *last_fec = 0; + move16(); *ph_ecu_active = 1; move16(); } @@ -5139,8 +5234,8 @@ void ivas_hq_ecu_fx( test(); test(); test(); - IF( ( ( EQ_16( st_fx->element_mode, EVS_MONO ) ) && evs_mode_selection ) || - ( ( NE_16( st_fx->element_mode, EVS_MONO ) ) && evs_mode_selection && ivas_mode_selection ) ) + IF( ( ( st_fx->element_mode == EVS_MONO ) && evs_mode_selection ) || + ( ( st_fx->element_mode != EVS_MONO ) && evs_mode_selection && ivas_mode_selection ) ) { ivas_fec_alg_fx( fec_alg_input, prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, st_fx->element_mode, st_fx->hHQ_core->old_out_fx ); *last_fec = 1; @@ -5210,6 +5305,7 @@ void hq_ecu_fx( #endif /* init (values ar changed after) */ decimatefactor = 4; + move16(); N = shr( output_frame, 2 ); @@ -5277,6 +5373,7 @@ void hq_ecu_fx( fec_alg_fx( prevsynth + NS2SA( output_frame * 50, ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth ); *last_fec = 1; + move16(); *ph_ecu_active = 0; move16(); *time_offs = output_frame; diff --git a/lib_dec/FEC_pitch_estim_fx.c b/lib_dec/FEC_pitch_estim_fx.c index 4fa36e5b84cea42c8be5badc2c0f222b2d89afe3..1305f1373009e57add9801f6b852ac504bf96b79 100644 --- a/lib_dec/FEC_pitch_estim_fx.c +++ b/lib_dec/FEC_pitch_estim_fx.c @@ -69,9 +69,12 @@ void FEC_pitch_estim_fx( test(); test(); - IF( ( EQ_16( element_mode, EVS_MONO ) && EQ_16( last_core, HQ_CORE ) ) || ( NE_16( element_mode, EVS_MONO ) && ( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) || EQ_16( last_core, TCX_10_CORE ) ) ) ) + test(); + test(); + test(); + IF( ( ( element_mode == EVS_MONO ) && EQ_16( last_core, HQ_CORE ) ) || ( element_mode != EVS_MONO && ( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) || EQ_16( last_core, TCX_10_CORE ) ) ) ) { - *bfi_pitch = pitch_buf[shr( L_frame, 6 ) - 1]; + *bfi_pitch = pitch_buf[sub( shr( L_frame, 6 ), 1 )]; move16(); *bfi_pitch_frame = L_frame; move16(); @@ -102,7 +105,7 @@ void FEC_pitch_estim_fx( ( EQ_16( L_frame, L_FRAME16k ) ) ) || ( EQ_16( coder_type, TRANSITION ) ) ) { - *bfi_pitch = pitch_buf[shr( L_frame, 6 ) - 1]; + *bfi_pitch = pitch_buf[sub( shr( L_frame, 6 ), 1 )]; move16(); *bfi_pitch_frame = L_frame; move16(); diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 24fca62db75ea9d0976dbb92e246b3f471a9e114..9a8da8454af1eedae4e9333ef1368cb17bd50c69 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -163,6 +163,7 @@ void FEC_scale_syn_fx( ELSE IF( *scaling_flag > 0 ) { ( *scaling_flag ) = sub( *scaling_flag, 1 ); /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ + move16(); } scaling = 32767; /*2.0 Q14*/ move16(); @@ -175,7 +176,9 @@ void FEC_scale_syn_fx( /*fer_energy( L_frame, clas, synth, pitch[(L_frame>>6)-1], &enr2, L_frame );*/ frame_ener_fx( L_frame, clas, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); - if ( bfi || ( EQ_32( total_brate, ACELP_7k20 ) ) || ( EQ_32( total_brate, ACELP_8k00 ) ) ) + test(); + test(); + IF( bfi || ( EQ_32( total_brate, ACELP_7k20 ) ) || ( EQ_32( total_brate, ACELP_8k00 ) ) ) { /* previous frame erased and no TC frame */ IF( *scaling_flag > 0 ) @@ -236,7 +239,6 @@ void FEC_scale_syn_fx( pitch_dist = 0; move16(); L_mean_pitch = L_mult( pitch[0], 8192 ); - move32(); FOR( k = 0; k < ( NB_SUBFR - 1 ); k++ ) { pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); @@ -301,8 +303,8 @@ void FEC_scale_syn_fx( test(); test(); test(); - IF( ( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, INACTIVE_CLAS ) ) ) || - EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || EQ_32( last_core_brate, FRAME_NO_DATA ) ) && + IF( ( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || + EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) && prev_bfi ) { /* voiced -> unvoiced signal transition */ @@ -405,8 +407,8 @@ void FEC_scale_syn_fx( test(); IF( ( ( ( EQ_32( total_brate, ACELP_13k20 ) ) || ( EQ_32( total_brate, ACELP_12k85 ) ) || ( EQ_32( total_brate, ACELP_12k15 ) ) || ( EQ_32( total_brate, ACELP_11k60 ) ) || ( EQ_32( total_brate, ACELP_9k60 ) ) ) && - ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ - ( ( EQ_16( clas, UNVOICED_CLAS ) ) || ( EQ_16( clas, INACTIVE_CLAS ) ) ) ) ) /* unvoiced classification */ + ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ + ( ( ( clas == UNVOICED_CLAS ) ) || ( EQ_16( clas, INACTIVE_CLAS ) ) ) ) ) /* unvoiced classification */ { /*if( enr_q > scaling * enr_old )enr_q = scaling * enr_old;*/ #ifdef BASOP_NOGLOB @@ -457,6 +459,7 @@ void FEC_scale_syn_fx( exp2 = 7; move16(); tmp2 = 160 << 7; /* 160 = 20.0f in Q3 */ + move16(); exp = sub( exp2, exp ); IF( GT_16( tmp, tmp2 ) ) @@ -474,6 +477,7 @@ void FEC_scale_syn_fx( test(); test(); test(); + test(); IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) || force_scaling ) { @@ -538,8 +542,8 @@ void FEC_scale_syn_fx( /*------------------------------------------------------------* * voiced->unvoiced transition recovery *------------------------------------------------------------*/ - ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ - EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || EQ_32( last_core_brate, FRAME_NO_DATA ) ) /* CNG -> active signal transition */ + ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ + EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) /* CNG -> active signal transition */ { gain1 = gain2; move16(); diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index dd8b57681624f4aa2fff3799b68a6d3222b91a87..ff97e81cd27b30ccc264436802328cd240f7d5f6 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -63,6 +63,7 @@ void Es_pred_dec_fx( ELSE { *Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx]; + move16(); } } /*======================================================================================*/ @@ -117,6 +118,7 @@ void gain_dec_tc_fx( * find number of bits for gain dequantization *----------------------------------------------------------------*/ nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ @@ -256,6 +258,7 @@ void gain_dec_tc_ivas_fx( * find number of bits for gain dequantization *----------------------------------------------------------------*/ nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ @@ -301,7 +304,6 @@ void gain_dec_tc_ivas_fx( /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ index = (Word16) get_next_indice( st_fx, nBits ); - move16(); IF( GT_16( nBits, 3 ) ) @@ -388,6 +390,8 @@ void gain_dec_mless_fx( * decode pitch gain *-----------------------------------------------------------------*/ nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + move16(); + test(); test(); test(); @@ -398,7 +402,6 @@ void gain_dec_mless_fx( { /* decode pitch gain */ index = (Word16) get_next_indice( st_fx, shr( nBits, 1 ) ); - move16(); /*Ei = (G_PITCH_MAX_TC192 - G_PITCH_MIN_TC192) / ((1 << (nBits>>1)) - 1);*/ /* set quantization step */ tmp_fx = div_s( 1, sub( shl( 1, shr( nBits, 1 ) ), 1 ) ); /*Q15*/ @@ -420,6 +423,7 @@ void gain_dec_mless_fx( L_tmp = Isqrt_lc( L_tmp, &expg ); *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ + move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); @@ -452,11 +456,9 @@ void gain_dec_mless_fx( /* decode normalized codebook gain */ /*index = (short)get_indice( st_fx, "gain_code", i_subfr_fx, ACELP_CORE );move16();*/ index = (Word16) get_next_indice( st_fx, shr( add( nBits, 1 ), 1 ) ); - move16(); /**gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 );*/ gain_code16 = gain_dequant_fx( index, G_CODE_MIN_TC192_Q15, G_CODE_MAX_TC192_Q0, shr( add( nBits, 1 ), 1 ), &expg ); - move16(); /**gain_code *= gcode0;*/ L_tmp = L_mult( gain_code16, gcode0_fx ); /*Q0*Q0 -> Q1*/ @@ -474,14 +476,12 @@ void gain_dec_mless_fx( case 7: { qua_table_fx = gain_qua_mless_7b_fx; - move16(); BREAK; } case 6: { qua_table_fx = gain_qua_mless_6b_fx; - move16(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { // PMT("gain_qua_mless_6b_stereo to fixed point") qua_table_fx = gain_qua_mless_6b_stereo_fx; @@ -491,25 +491,22 @@ void gain_dec_mless_fx( case 5: { qua_table_fx = gain_qua_mless_5b_fx; - move16(); BREAK; } default: { qua_table_fx = gain_qua_mless_6b_fx; - move16(); BREAK; } } test(); - if ( EQ_16( coder_type, INACTIVE ) && EQ_16( nBits, 6 ) ) + if ( coder_type == INACTIVE && EQ_16( nBits, 6 ) ) { nBits = sub( nBits, 1 ); } index = (Word16) get_next_indice( st_fx, nBits ); - move16(); *gain_pit_fx = qua_table_fx[index * 2]; move16(); @@ -526,6 +523,7 @@ void gain_dec_mless_fx( L_tmp = Isqrt_lc( L_tmp, &expg ); *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ + move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); @@ -629,8 +627,9 @@ void gain_dec_lbr_fx( *gain_inov = 1.0f / (float)sqrt(Ecode); */ Word16 shift_L_subfr; shift_L_subfr = 6; + move16(); // for *cdbk_fx move16(); - IF( GT_16( L_subfr, L_SUBFR ) ) + if ( GT_16( L_subfr, L_SUBFR ) ) { shift_L_subfr = add( shift_L_subfr, 1 ); } @@ -644,7 +643,7 @@ void gain_dec_lbr_fx( L_tmp = Isqrt_lc( L_tmp, &expg ); *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ - + move16(); /*-----------------------------------------------------------------* * select the codebook, size and number of bits @@ -671,19 +670,16 @@ void gain_dec_lbr_fx( case 8: { cdbk_fx = gp_gamma_1sfr_8b_fx; /* Q14/Q9*/ - move16(); BREAK; } case 7: { cdbk_fx = gp_gamma_1sfr_7b_fx; /* Q14/Q9*/ - move16(); BREAK; } case 6: { cdbk_fx = gp_gamma_1sfr_6b_fx; /* Q14/Q9*/ - move16(); BREAK; } } @@ -692,6 +688,7 @@ void gain_dec_lbr_fx( aux_fx[0] = 4096; move16(); aux_fx[1] = shl( ctype, 12 ); + move16(); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); @@ -727,7 +724,6 @@ void gain_dec_lbr_fx( /* retrieve the codebook index and calculate both gains */ /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ index = (Word16) get_next_indice( st_fx, nBits ); - move16(); *gain_pit_fx = cdbk_fx[index * 2]; move16(); @@ -758,13 +754,11 @@ void gain_dec_lbr_fx( case 7: { cdbk_fx = gp_gamma_2sfr_7b_fx; /* Q14/Q9*/ - move16(); BREAK; } case 6: { cdbk_fx = gp_gamma_2sfr_6b_fx; /* Q14/Q9*/ - move16(); BREAK; } } @@ -773,6 +767,7 @@ void gain_dec_lbr_fx( aux_fx[0] = 4096; move16(); aux_fx[1] = shl( ctype, 12 ); + move16(); /*aux_fx[2] = (float)log10(gc_mem[0]); = log2(gc_mem[0])*log10(2);*/ @@ -781,8 +776,10 @@ void gain_dec_lbr_fx( e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + move16(); aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ + move16(); /*-----------------------------------------------------------------* * gcode0 = pow(10.0, dotp(b, aux, n_pred) @@ -800,7 +797,6 @@ void gain_dec_lbr_fx( /* retrieve the codebook index and calculate both gains */ index = (Word16) get_next_indice( st_fx, nBits ); - move16(); *gain_pit_fx = cdbk_fx[index * 2]; move16(); @@ -827,12 +823,11 @@ void gain_dec_lbr_fx( cdbk_fx = gp_gamma_3sfr_6b_fx; - IF( EQ_16( nBits, 7 ) ) + if ( EQ_16( nBits, 7 ) ) { cdbk_fx = gp_gamma_3sfr_7b_fx; // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } - move16(); /* Q14/Q9*/ /* calculate predicted gain */ aux_fx[0] = 4096; @@ -847,6 +842,7 @@ void gain_dec_lbr_fx( e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + move16(); /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ @@ -855,6 +851,7 @@ void gain_dec_lbr_fx( e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + move16(); aux_fx[4] = shr( gp_mem[0], 2 ); move16(); @@ -877,9 +874,8 @@ void gain_dec_lbr_fx( /* retrieve the codebook index and calculate both gains */ index = (Word16) get_next_indice( st_fx, nBits ); - move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[shl( index, 1 )]; move16(); L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ @@ -896,7 +892,6 @@ void gain_dec_lbr_fx( ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { b_fx = b_4sfr_fx; - move16(); n_pred = 8; move16(); @@ -909,7 +904,6 @@ void gain_dec_lbr_fx( PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) } #endif - move16(); /* Q14/Q9*/ /* calculate predicted gain */ aux_fx[0] = 4096; @@ -924,6 +918,7 @@ void gain_dec_lbr_fx( e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + move16(); /*aux[3] = (float)log10(gc_mem[1]); = log2(gc_mem[1])*log10(2);*/ @@ -932,6 +927,7 @@ void gain_dec_lbr_fx( e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + move16(); /*aux[4] = (float)log10(gc_mem[2]); = log2(gc_mem[2])*log10(2);*/ @@ -940,6 +936,7 @@ void gain_dec_lbr_fx( e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ + move16(); aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ move16(); @@ -965,7 +962,7 @@ void gain_dec_lbr_fx( /* retrieve the codebook index and calculate both gains */ index = (Word16) get_next_indice( st_fx, nBits ); move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[shl( index, 1 )]; move16(); L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ @@ -1034,7 +1031,7 @@ void lp_gain_updt_fx( #endif IF( EQ_16( L_frame, L_FRAME ) ) { - IF( i_subfr == 0 ) + IF( EQ_16( i_subfr, 0 ) ) { *lp_gainp = mult( 3277, gain_pit ); move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ @@ -1239,6 +1236,7 @@ void gain_dec_SQ_fx( L_tmp = Isqrt_lc( L_tmp, &expg ); *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ + move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); @@ -1313,6 +1311,7 @@ void gain_dec_amr_wb_fx( Word16 expg, exp_gcode0, fracg; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -1323,6 +1322,7 @@ void gain_dec_amr_wb_fx( L_tmp = Isqrt_lc( L_tmp, &expg ); *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ + move16(); /*-----------------------------------------------------------------* * Select the gain quantization table @@ -1331,7 +1331,7 @@ void gain_dec_amr_wb_fx( move16(); t_qua_gain = t_qua_gain7b_fx; - IF( LT_32( core_brate, ACELP_12k65 ) ) + if ( LT_32( core_brate, ACELP_12k65 ) ) { nbits = 6; move16(); diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index 0dec8dbf632830dba87690961414f2c9e7eef50d..dc999e3f0276eb4b9d30ac77fd3f9e68beb9a4bf 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -67,14 +67,15 @@ void gaus_dec_fx( exp = sub( exp, 18 /*24*/ + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ L_tmp = Isqrt_lc( L_tmp, &exp ); *inv_gain_inov = extract_h( L_shl( L_tmp, sub( exp, 3 ) ) ); /* inv_gain_inov in Q12 */ + move16(); nb_bits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; move16(); idx = (Word16) get_next_indice( st_fx, nb_bits ); - move16(); /* safety check in case of bit errors */ - IF( GT_16( idx, 78 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) + test(); + IF( GT_16( idx, 78 ) && st_fx->element_mode == EVS_MONO ) { idx = 78; move16(); @@ -83,6 +84,7 @@ void gaus_dec_fx( } *L_gain_code = gain_dec_gaus_fx( idx, nb_bits, -30, 190, *inv_gain_inov, L_norm_gain_code ); + move32(); /* update LP filtered gains for the case of frame erasures */ lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ @@ -122,7 +124,8 @@ void gaus_dec_fx( FOR( i = 0; i < L_SUBFR; i++ ) { L_tmp = L_shl( L_mult( gain_code, code[i] ), 6 /*3*/ ); - exc[i + i_subfr] = round_fx( L_tmp ); + exc[add( i, i_subfr )] = round_fx( L_tmp ); + move16(); } return; @@ -174,6 +177,7 @@ void gaus_dec2v_fx( /* gaus_dico2[i] = (gaus_dico_fx[i] - delta*gaus_dico_fx[i-1])/(1+delta*delta) */ tmp16 = msu_r( L_deposit_h( gaus_dico_fx[i] ), delta, gaus_dico_fx[i - 1] ); gaus_dico2_fx[i] = mult_r( tmp16, inv_delta ); + move16(); } } ELSE @@ -186,15 +190,14 @@ void gaus_dec2v_fx( } pt1 = &gaus_dico2_fx[i_mult2( ind1, step )]; - move16(); pt2 = &gaus_dico2_fx[i_mult2( ind2, step )]; - move16(); FOR( i = 0; i < lg; i++ ) { /* code is Q9, Gaussian codebook is Q12 */ /* code[i] = pt1[i] * sign1 + pt2[i] * sign2 */ code[i] = add( mult( pt1[i], sign1 ), mult( pt2[i], sign2 ) ); + move16(); } return; @@ -236,7 +239,7 @@ static void dec_2pos_fx( move16(); *sign2 = *sign1; move16(); - if ( GT_16( *ind1, *ind2 ) ) + IF( GT_16( *ind1, *ind2 ) ) { *sign2 = negate( *sign1 ); move16(); diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index f55b5e87766a95d4d9bbdd6b2debaf102013bb4f..4ad733294b40f95c2d6449e7e7fcf1c068c0420c 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -71,6 +71,7 @@ static void NoiseFill_fx( L_temp = L_mult( Random( seed_tcx ), fact ); L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); exc_diffQ_fx[CurBin] = round_fx( L_temp ); + move16(); } } @@ -175,6 +176,7 @@ static void Apply_gain_fx( L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); L_temp = L_shr( L_temp, y_gain_exp ); exc_diffQ_fx[CurBin] = round_fx( L_temp ); + move16(); } } } @@ -212,6 +214,7 @@ static void normalize_spec_fx( FOR( j = 0; j < L_frame; j++ ) { fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); + move16(); } return; @@ -300,7 +303,7 @@ static void gs_dec_amr_wb_fx( test(); IF( L_temp <= CONTR_LIMIT && ( VeryLowRateSTflag || GE_32( core_brate, ACELP_12k65 ) ) ) #else - IF( GE_32( core_brate, ACELP_12k65 ) ) + if ( GE_32( core_brate, ACELP_12k65 ) ) #endif { L_temp = L_shl( L_temp, 1 ); @@ -361,6 +364,7 @@ static void gs_dec_amr_wb_fx( temp2 = mult_r( temp2, temp ); /* Q15*Q9+1-16 -> Q9 */ L_temp = L_mult( exc_diffQ_fx[i], s_max( temp2, 512 ) ); /*Q(Qexc_diffQ+10) */ exc_diffQ_fx[i] = round_fx( L_shl( L_temp, 16 - 10 ) ); /*Qexc_diffQ */ + move16(); } /*--------------------------------------------------------------------------------------* @@ -412,6 +416,7 @@ void improv_amr_wb_gs_fx( Word16 Aq_orig[NB_SUBFR * ( M + 1 )], enr_LP_old, enr_LP_new; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*------------------------------------------------------------* @@ -435,8 +440,8 @@ void improv_amr_wb_gs_fx( #else IF( ( locattack == 0 && LE_32( core_brate, ACELP_12k65 ) ) && ( ( LT_32( core_brate, ACELP_8k85 ) && NE_16( clas, AUDIO_CLAS ) && - ( EQ_16( clas, UNVOICED_CLAS ) || EQ_16( clas, VOICED_TRANSITION ) ) ) || - EQ_16( coder_type, INACTIVE ) ) ) + ( clas == UNVOICED_CLAS || EQ_16( clas, VOICED_TRANSITION ) ) ) || + ( coder_type == INACTIVE ) ) ) #endif { /*------------------------------------------------------------* @@ -446,32 +451,34 @@ void improv_amr_wb_gs_fx( * LP filter smoothing for inactive parts *------------------------------------------------------------*/ *seed_tcx = extract_l( L_mult0( pitch_buf_fx[0], pitch_buf_fx[3] ) ); + move16(); /* last_coder_type == UNVOICED should be understand as INACTIVE, but it is forced to UNVOICED in update_dec */ test(); test(); test(); - IF( EQ_16( coder_type, INACTIVE ) && GT_16( Last_ener_fx, -3 * 256 ) && EQ_16( last_coder_type, UNVOICED ) && rate_switching_reset == 0 ) /* 3.0 x 256 to Go to Q8 */ + IF( coder_type == INACTIVE && GT_16( Last_ener_fx, -3 * 256 ) && EQ_16( last_coder_type, UNVOICED ) && rate_switching_reset == 0 ) /* 3.0 x 256 to Go to Q8 */ { FOR( i = 0; i < NB_SUBFR; i++ ) { Copy( Aq_fx, Aq_orig, NB_SUBFR * ( M + 1 ) ); - exp_a = norm_s( Aq_fx[i * ( M + 1 )] ); - exp_b = norm_s( old_Aq_fx[i * ( M + 1 )] ); + exp_a = norm_s( Aq_fx[imult1616( i, ( M + 1 ) )] ); + exp_b = norm_s( old_Aq_fx[imult1616( i, ( M + 1 ) )] ); exp_diff = sub( exp_a, exp_b ); IF( exp_diff > 0 ) { - Scale_sig( &old_Aq_fx[i * ( M + 1 )], ( M + 1 ), negate( exp_diff ) ); + Scale_sig( &old_Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), negate( exp_diff ) ); } ELSE { - Scale_sig( &Aq_fx[i * ( M + 1 )], ( M + 1 ), exp_diff ); + Scale_sig( &Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), exp_diff ); } - FOR( j = i * ( M + 1 ); j < ( i + 1 ) * ( M + 1 ); j++ ) + FOR( j = imult1616( i, ( M + 1 ) ); j < imult1616( add( i, 1 ), ( M + 1 ) ); j++ ) { Aq_fx[j] = round_fx( L_mac( L_mult( ALP_FX, old_Aq_fx[j] ), MALP_FX, Aq_fx[j] ) ); + move16(); } } @@ -483,11 +490,12 @@ void improv_amr_wb_gs_fx( FOR( i = 0; i < NB_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - enr_LP_new = Enr_1_Az_fx_o( Aq_fx + i * ( M + 1 ), L_SUBFR, &Overflow ); + enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); #else enr_LP_new = Enr_1_Az_fx( Aq_fx + i * ( M + 1 ), L_SUBFR ); #endif - IF( ( shr( enr_LP_new, 7 ) > enr_LP_old ) || Overflow ) + test(); + IF( GT_16( shr( enr_LP_new, 7 ), enr_LP_old ) || Overflow ) { /* filter is unstable, do not modify the excitation */ Copy( Aq_orig, Aq_fx, NB_SUBFR * ( M + 1 ) ); diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 4c292536984760d224b67407bb15d953482f25c4..bd5f9b7f84fb74e7f634bd8e02e3643cb036b081 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -67,6 +67,7 @@ void decod_audio_fx( /*---------------------------------------------------------------* * Initialization *---------------------------------------------------------------*/ + move16(); // corresponding to initialization of Es_pred Diff_len = 0; move16(); @@ -76,17 +77,19 @@ void decod_audio_fx( /* decode GSC SWB speech flag */ test(); #if !defined ADD_LRTD - IF( NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->total_brate, ACELP_13k20 ) ) + IF( st_fx->coder_type != INACTIVE && GE_32( st_fx->total_brate, ACELP_13k20 ) ) #else if ( st_fx->GSC_IVAS_mode >= 1 || ( st_fx->coder_type != INACTIVE && ( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20 ) || ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) #endif { st_fx->GSC_noisy_speech = (Word16) get_next_indice( st_fx, 1 ); + move16(); } /* safety check in case of bit errors */ test(); + test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { st_fx->BER_detect = 1; @@ -142,10 +145,12 @@ void decod_audio_fx( IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2 ); + move16(); } ELSE { hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0 ); + move16(); } /*---------------------------------------------------------------* @@ -177,7 +182,7 @@ void decod_audio_fx( #endif nb_frame_flg = (Word16) get_next_indice( st_fx, nbits ); - IF( s_and( nb_frame_flg, 0x1 ) == 0 ) + if ( s_and( nb_frame_flg, 0x1 ) == 0 ) { nb_subfr = 2 * SWNB_SUBFR; move16(); @@ -213,7 +218,7 @@ void decod_audio_fx( nbits = 3; move16(); test(); - if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( EQ_16( st_fx->coder_type, INACTIVE ) ) ) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type == INACTIVE ) { nbits = 1; move16(); @@ -225,7 +230,7 @@ void decod_audio_fx( move16(); } test(); - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { pit_band_idx = 1; move16(); @@ -235,7 +240,7 @@ void decod_audio_fx( pit_band_idx = (Word16) get_next_indice( st_fx, nbits ); } - IF( pit_band_idx != 0 ) + if ( pit_band_idx != 0 ) { IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { @@ -248,7 +253,7 @@ void decod_audio_fx( } /* detect bit errors in the bitstream */ - IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ + if ( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ { pit_band_idx = 13; move16(); @@ -283,7 +288,7 @@ void decod_audio_fx( Word16 indice; nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; move16(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { nbits = 5; move16(); @@ -307,7 +312,7 @@ void decod_audio_fx( { pit_band_idx = 9 + BAND1k2; move16(); - if ( EQ_16( st_fx->bwidth, NB ) ) + if ( st_fx->bwidth == NB ) { pit_band_idx = 7 + BAND1k2; move16(); @@ -341,14 +346,14 @@ void decod_audio_fx( max_len = sub( st_fx->L_frame, Diff_len ); - if ( EQ_16( st_fx->bwidth, NB ) ) + if ( st_fx->bwidth == NB ) { max_len = sub( 160, Diff_len ); } Len = 80; move16(); - if ( max_len < 80 ) + if ( LT_16( max_len, 80 ) ) { Len = max_len; move16(); @@ -359,7 +364,7 @@ void decod_audio_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[i + Diff_len] = 0; + dct_epit[add( i, Diff_len )] = 0; move16(); } } @@ -367,13 +372,13 @@ void decod_audio_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); + dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[i + Diff_len] = 0; + dct_epit[add( i, Diff_len )] = 0; move16(); } } @@ -406,6 +411,7 @@ void decod_audio_fx( set16_fx( gain_buf, 0, NB_SUBFR16k ); st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); st_fx->lp_gainp_fx = 0; @@ -444,7 +450,8 @@ void decod_audio_fx( test(); if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) #else - if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) + test(); + if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif { tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); @@ -477,7 +484,7 @@ void decod_audio_fx( * Update BWE excitation *--------------------------------------------------------------------------------------*/ - if ( st_fx->hBWE_TD != NULL ) + IF( st_fx->hBWE_TD != NULL ) { set16_fx( voice_factors, 0, NB_SUBFR16k ); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) @@ -561,6 +568,7 @@ void decod_audio_ivas_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; + move16(); // Es_pred /*---------------------------------------------------------------* * Initialization @@ -576,15 +584,23 @@ void decod_audio_ivas_fx( #if 0 // !defined ADD_LRTD IF(NE_16(st_fx->coder_type, INACTIVE) && GE_32(st_fx->total_brate, ACELP_13k20)) #else - if ( st_fx->GSC_IVAS_mode >= 1 || ( st_fx->coder_type != INACTIVE && ( ( st_fx->element_mode == EVS_MONO && st_fx->total_brate >= ACELP_13k20 ) || - ( st_fx->element_mode > EVS_MONO && st_fx->total_brate > MIN_BRATE_GSC_NOISY_FLAG && st_fx->bwidth >= SWB && !st_fx->flag_ACELP16k ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( st_fx->coder_type != INACTIVE && ( ( st_fx->element_mode == EVS_MONO && GE_32( st_fx->total_brate, ACELP_13k20 ) ) || + ( st_fx->element_mode > EVS_MONO && GT_32( st_fx->total_brate, MIN_BRATE_GSC_NOISY_FLAG ) && GE_16( st_fx->bwidth, SWB ) && !st_fx->flag_ACELP16k ) ) ) ) #endif { st_fx->GSC_noisy_speech = (Word16) get_next_indice( st_fx, 1 ); + move16(); } /* safety check in case of bit errors */ test(); + test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { st_fx->BER_detect = 1; @@ -604,7 +620,7 @@ void decod_audio_ivas_fx( #if 1 // defined ADD_LRTD test(); test(); - IF( st_fx->GSC_IVAS_mode >= 1 || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && st_fx->GSC_IVAS_mode == 0 ) ) + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && st_fx->GSC_IVAS_mode == 0 ) ) #else IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif @@ -616,21 +632,26 @@ void decod_audio_ivas_fx( hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); #if 1 // def ADD_LRTD - if ( st_fx->GSC_IVAS_mode >= 1 ) + IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) { - if ( st_fx->core_brate < GSC_L_RATE_STG && st_fx->GSC_IVAS_mode < 3 ) + test(); + if ( LT_32( st_fx->core_brate, GSC_L_RATE_STG ) && LT_32( st_fx->GSC_IVAS_mode, 3 ) ) { nb_subfr = 2; + move16(); } hGSCDec->noise_lev = NOISE_LEVEL_SP2; + move16(); - if ( st_fx->GSC_IVAS_mode == 3 ) /* Music like */ + IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { hGSCDec->noise_lev = NOISE_LEVEL_SP0; + move16(); } - else if ( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ + ELSE IF( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ { hGSCDec->noise_lev = NOISE_LEVEL_SP3; + move16(); } } #endif @@ -640,22 +661,28 @@ void decod_audio_ivas_fx( IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2 ); + move16(); } ELSE { hGSCDec->noise_lev = add( (Word16) get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0 ); + move16(); } /*---------------------------------------------------------------* * Decode number of subframes *---------------------------------------------------------------*/ #if 1 // def ADD_LRTD - if ( st_fx->L_frame == L_FRAME16k && ( st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE ) ) + test(); + test(); + IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && ( LE_32( st_fx->core_brate, ACELP_13k20 ) || st_fx->coder_type == INACTIVE ) ) { hGSCDec->cor_strong_limit = 0; + move16(); nb_subfr = 1; + move16(); } - else + ELSE #endif { hGSCDec->cor_strong_limit = 1; @@ -668,13 +695,16 @@ void decod_audio_ivas_fx( nbits = 1; move16(); #if 1 // def ADD_LRTD - if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR ) + test(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { nbits = 2; + move16(); } #endif nb_frame_flg = (Word16) get_next_indice( st_fx, nbits ); + test(); IF( s_and( nb_frame_flg, 0x1 ) == 0 ) { nb_subfr = 2 * SWNB_SUBFR; @@ -683,23 +713,26 @@ void decod_audio_ivas_fx( move16(); } #if 1 // def ADD_LRTD - else if ( st_fx->L_frame == L_FRAME16k && st_fx->core_brate >= MIN_RATE_4SBFR ) + ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { nb_subfr = 2 * SWNB_SUBFR; /* cor_strong already set to 1 */ + move16(); } - if ( ( nb_frame_flg >> 1 ) == 1 ) + if ( EQ_16( shr( nb_frame_flg, 1 ), 1 ) ) { - nb_subfr *= 2; + nb_subfr = shl( nb_subfr, 1 ); } #endif } } } #if 1 - if ( st_fx->L_frame == L_FRAME16k && nb_subfr == NB_SUBFR ) + test(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) { nb_subfr = NB_SUBFR16k; + move16(); } #endif /*---------------------------------------------------------------* @@ -711,7 +744,7 @@ void decod_audio_ivas_fx( nbits = 3; move16(); test(); - if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( EQ_16( st_fx->coder_type, INACTIVE ) ) ) + if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( st_fx->coder_type == INACTIVE ) ) { nbits = 1; move16(); @@ -723,7 +756,7 @@ void decod_audio_ivas_fx( move16(); } test(); - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { pit_band_idx = 1; move16(); @@ -771,9 +804,16 @@ void decod_audio_ivas_fx( *---------------------------------------------------------------*/ test(); #if 1 // def ADD_LRTD - if ( !( st_fx->GSC_IVAS_mode > 0 && st_fx->L_frame / nb_subfr == 2 * L_SUBFR && st_fx->GSC_IVAS_mode < 3 ) && - ( ( st_fx->core_brate >= MIN_RATE_FCB || st_fx->GSC_noisy_speech ) && - ( ( nb_subfr == NB_SUBFR && st_fx->L_frame == L_FRAME ) || ( nb_subfr == NB_SUBFR16k && st_fx->L_frame == L_FRAME16k ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( !( ( st_fx->GSC_IVAS_mode > 0 ) && EQ_16( idiv1616( st_fx->L_frame, nb_subfr ), 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) && + ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || st_fx->GSC_noisy_speech ) && + ( ( EQ_16( nb_subfr, NB_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) || ( EQ_16( nb_subfr, NB_SUBFR16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) ) ) ) #else IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) ) #endif @@ -781,7 +821,7 @@ void decod_audio_ivas_fx( Word16 indice; nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; move16(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { nbits = 5; move16(); @@ -805,7 +845,7 @@ void decod_audio_ivas_fx( { pit_band_idx = 9 + BAND1k2; move16(); - if ( EQ_16( st_fx->bwidth, NB ) ) + if ( st_fx->bwidth == NB ) { pit_band_idx = 7 + BAND1k2; move16(); @@ -839,25 +879,25 @@ void decod_audio_ivas_fx( max_len = sub( st_fx->L_frame, Diff_len ); - if ( EQ_16( st_fx->bwidth, NB ) ) + if ( st_fx->bwidth == NB ) { max_len = sub( 160, Diff_len ); } Len = 80; move16(); - if ( max_len < 80 ) + if ( LT_16( max_len, 80 ) ) { Len = max_len; move16(); } test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) { FOR( i = 0; i < max_len; i++ ) { - dct_epit[i + Diff_len] = 0; + dct_epit[add( i, Diff_len )] = 0; move16(); } } @@ -865,13 +905,13 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); + dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[i + Diff_len] = 0; + dct_epit[add( i, Diff_len )] = 0; move16(); } } @@ -904,6 +944,7 @@ void decod_audio_ivas_fx( set16_fx( gain_buf, 0, NB_SUBFR16k ); st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); st_fx->lp_gainp_fx = 0; @@ -940,7 +981,7 @@ void decod_audio_ivas_fx( test(); #if 1 // defined ADD_LRTD test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) + if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->idchan == 0 ) #else if ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) #endif @@ -952,7 +993,7 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->idchan, 1 ) ) { tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - IF( EQ_16( st_fx->tdm_LRTD_flag, 1 ) ) + if ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) ) { tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); } @@ -976,7 +1017,7 @@ void decod_audio_ivas_fx( * Update BWE excitation *--------------------------------------------------------------------------------------*/ - if ( st_fx->hBWE_TD != NULL ) + IF( st_fx->hBWE_TD != NULL ) { set16_fx( voice_factors, 0, NB_SUBFR16k ); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) @@ -1069,6 +1110,8 @@ void gsc_dec_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; + move16(); // for Mbands_gn + move16(); // for Qexc_diffQ set16_fx( inpulses_fx, 0, NB_SFM ); set16_fx( imaxpulse_fx, 0, NB_SFM ); @@ -1112,6 +1155,7 @@ void gsc_dec_fx( } st_fx->lp_gainc_fx = mult_r( st_fx->lp_gainc_fx, 32112 ); /*Q3*/ + move16(); } ELSE { @@ -1143,12 +1187,13 @@ void gsc_dec_fx( mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); #endif st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ + move16(); } *last_bin = 0; move16(); test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) { bitallocation_exc[0] = 0; move16(); @@ -1178,6 +1223,7 @@ void gsc_dec_fx( L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ + move16(); } } @@ -1246,7 +1292,7 @@ void gsc_dec_fx( { seed_init = extract_l( L_shl( seed_init, 3 ) ); } - IF( concat_out[j] < 0 ) + if ( concat_out[j] < 0 ) { seed_init = add( seed_init, 3 ); move16(); @@ -1257,7 +1303,7 @@ void gsc_dec_fx( move16(); } test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { @@ -1390,6 +1436,8 @@ void gsc_dec_ivas_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; + move16(); // for Mbands_gn + move16(); // for Qexc_diffQ set16_fx( inpulses_fx, 0, NB_SFM ); set16_fx( imaxpulse_fx, 0, NB_SFM ); @@ -1402,13 +1450,12 @@ void gsc_dec_ivas_fx( test(); test(); test(); - test(); - IF( EQ_16( coder_type, INACTIVE ) && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) + if ( coder_type == INACTIVE && ( EQ_16( st_fx->tdm_LRTD_flag, 1 ) || EQ_16( st_fx->element_mode, IVAS_SCE ) ) && LE_32( st_fx->core_brate, GSC_LRES_GAINQ_LIMIT ) ) { bit = add( bit, GSC_LRES_NB_NITS ); } - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; move16(); @@ -1433,6 +1480,7 @@ void gsc_dec_ivas_fx( } st_fx->lp_gainc_fx = mult_r( st_fx->lp_gainc_fx, 32112 ); /*Q3*/ + move16(); } ELSE { @@ -1452,11 +1500,10 @@ void gsc_dec_ivas_fx( test(); test(); test(); - test(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) && EQ_16( coder_type, AUDIO ) && + IF( st_fx->element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) && LE_32( st_fx->core_brate, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation is mapped to 8 kb/s instead of 9.6 kb/s in this case */ { - i--; + i = sub( i, 1 ); } mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); @@ -1464,12 +1511,13 @@ void gsc_dec_ivas_fx( mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); #endif st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ + move16(); } *last_bin = 0; move16(); test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) { bitallocation_exc[0] = 0; move16(); @@ -1499,6 +1547,7 @@ void gsc_dec_ivas_fx( L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ + move16(); } } @@ -1536,20 +1585,27 @@ void gsc_dec_ivas_fx( #if 1 // def ADD_LRTD max_eq = 0; + move16(); max_eq_val = 32767; + move16(); - IF( ( ( st_fx->core_brate < ACELP_7k20 && st_fx->GSC_noisy_speech == 1 ) || st_fx->core_brate < 6000 ) && coder_type <= UNVOICED ) + test(); + test(); + test(); + IF( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( coder_type, UNVOICED ) ) { - j = maximum_fx( concat_out, nb_subbands * 16, &max_eq ); + j = maximum_fx( concat_out, imult1616( nb_subbands, 16 ), &max_eq ); // max_eq = max_eq_val / (abs_s(concat_out[j]) + 328 /*0.01f*/ ); - Word16 temp_max_eq = abs_s( concat_out[j] ) + 10 /*0.01f in Q10*/; + Word16 temp_max_eq = add( abs_s( concat_out[j] ), 10 ) /*0.01f in Q10*/; IF( LE_16( temp_max_eq, ONE_IN_Q10 ) ) { max_eq = max_eq_val; + move16(); } ELSE { Word16 exp = 5; + move16(); max_eq = Inv16( temp_max_eq, &exp ); max_eq = shl( max_eq, exp ); } @@ -1578,14 +1634,13 @@ void gsc_dec_ivas_fx( { seed_init = extract_l( L_shl( seed_init, 3 ) ); } - IF( concat_out[j] < 0 ) + if ( concat_out[j] < 0 ) { #ifdef BASOP_NOGLOB_TMP_715 seed_init = add_sat( seed_init, 3 ); #else seed_init = add( seed_init, 3 ); #endif - move16(); } } @@ -1593,15 +1648,15 @@ void gsc_dec_ivas_fx( move16(); } test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) + IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) { - IF( exc_diffQ[L_FRAME8k - 2] != 0 ) + if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { bitallocation_exc[0] = 1; move16(); } - IF( exc_diffQ[L_FRAME8k - 1] != 0 ) + if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { bitallocation_exc[1] = 1; move16(); @@ -1620,8 +1675,6 @@ void gsc_dec_ivas_fx( test(); test(); test(); - test(); - test(); IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) { FOR( i = 64; i < st_fx->L_frame; i++ ) @@ -1629,6 +1682,7 @@ void gsc_dec_ivas_fx( // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + move16(); } } ELSE IF( ( ( LT_32( st_fx->core_brate, ACELP_7k20 ) && EQ_16( st_fx->GSC_noisy_speech, 1 ) ) || LT_32( st_fx->core_brate, 6000 ) ) && LE_16( st_fx->coder_type, UNVOICED ) ) @@ -1638,6 +1692,7 @@ void gsc_dec_ivas_fx( // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + move16(); } } ELSE diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 40946cb204c511a084ff92ef87278d511a35eb3e..4894ee0e86d7fd53aba25d7cd2260a97f3749a10 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -55,7 +55,7 @@ void hdecnrm_fx( move16(); if ( get_next_indice_1( st_fx ) != 0 ) { - j = (Word16) 1; + j = 1; move16(); } temp = add( 8, n ); @@ -110,6 +110,7 @@ Word16 decode_huff_context_fx( tmp_h = shr( hufftab[hufftab_idx], 4 ); tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); *rbits = add( *rbits, tmp_l ); + move16(); hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice( st_fx, tmp_l ) ) ); } return negate( hufftab[hufftab_idx] ); @@ -218,7 +219,6 @@ void hdecnrm_resize_fx( ELSE{ IF( get_next_indice_1( st_fx ) != 0 ){ temp = add( 16, k ); - move16(); } ELSE { @@ -282,6 +282,7 @@ void huff_dec_fx( /* Put back unused bits */ st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); + move16(); return; } @@ -304,7 +305,6 @@ void hdecnrm_tran_fx( Word16 l; pidx = index; - move16(); m = sub( N, 1 ); FOR( i = 0; i < m; i++ ) diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index c63636e23e503ea23e4e742bec22182941f7dca4..a40ae1a3045c7f5deb2223dffdb2676875a9a639 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -48,6 +48,7 @@ void hf_synth_init_fx( ) { hBWE_zero->seed2 = RANDOM_INITSEED; + move16(); set16_fx( hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) ); set16_fx( hBWE_zero->mem_syn_hf_fx, 0, M ); set16_fx( hBWE_zero->mem_hp400_fx, 0, 4 ); @@ -113,14 +114,12 @@ void hf_synth_fx( move16(); p_Aq = Aq; - move16(); FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { - hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[i_subfr * output_subfr / L_SUBFR], + hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode ); p_Aq += ( M + 1 ); - move16(); } return; @@ -241,7 +240,6 @@ static void hf_synthesis_fx( scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ exp2 = sub( *memExp1, exp1 ); - move16(); *memExp1 = exp1; move16(); @@ -303,7 +301,7 @@ static void hf_synthesis_fx( tmp = add( 1, sub( 32767, tmp ) ); #endif test(); - if ( EQ_32( core_brate, FRAME_NO_DATA ) || EQ_32( core_brate, SID_2k40 ) ) + if ( core_brate == FRAME_NO_DATA || EQ_32( core_brate, SID_2k40 ) ) { /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ @@ -349,8 +347,8 @@ static void hf_synthesis_fx( /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ delay = NS2SA( 16000, DELAY_CLDFB_NS ) - 15; - Copy( HF_syn + L_SUBFR16k - delay, temp_buffer, delay ); - Copy( HF_syn, HF_syn + delay, L_SUBFR16k - delay ); + Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); + Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); Copy( delay_syn_hf, HF_syn, delay ); Copy( temp_buffer, delay_syn_hf, delay ); @@ -643,6 +641,7 @@ static void filt_6k_7k_scale_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Copy_Scale_sig( mem, x, L_FIR - 1, exp ); @@ -657,7 +656,7 @@ static void filt_6k_7k_scale_fx( Word16 j; L_tmp = 0; move32(); - for ( j = 0; j < 31; j++ ) + FOR( j = 0; j < 31; j++ ) { #ifdef BASOP_NOGLOB L_tmp = L_mac_o( L_tmp, x[i + j], fir_6k_7k_fx[j], &Overflow ); @@ -668,6 +667,7 @@ static void filt_6k_7k_scale_fx( #ifdef BASOP_NOGLOB signal[i] = round_fx_o( L_tmp, &Overflow ); + move16(); #else signal[i] = round_fx( L_tmp ); #endif @@ -844,6 +844,7 @@ void hf_synth_amr_wb_fx( tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ L_tmp = L_mult( tmp2, tmp1 ); /*30-exp-2*(Q_syn-3)-1+2*(Q_syn-3)+1 - >30-exp */ *pt3 = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /*13 */ + move16(); *pt4++ = *pt3++; move16(); @@ -879,10 +880,12 @@ void hf_synth_amr_wb_fx( } ELSE { - move16(); hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + move16(); hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + move16(); hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); + move16(); } pt6 = voice_factors; @@ -912,6 +915,7 @@ void hf_synth_amr_wb_fx( fmerit_w = extract_l( L_shr( L_tmp, 15 ) ); /*Q14 */ /**fmerit_w_sm = add(mult_r(*fmerit_w_sm, 29491), mult_r(fmerit_w, 3277)); //Q14 */ hAmrwb_IO->fmerit_w_sm_fx = round_fx( L_mac( L_mult( hAmrwb_IO->fmerit_w_sm_fx, 29491 ), fmerit_w, 3277 ) ); /*Q14 */ + move16(); fmerit_w = hAmrwb_IO->fmerit_w_sm_fx; move16(); @@ -925,6 +929,7 @@ void hf_synth_amr_wb_fx( } fmerit_m = negate( add( -32768, tmp1 ) ); hAmrwb_IO->fmerit_m_sm_fx = add( shr( hAmrwb_IO->fmerit_m_sm_fx, 1 ), shr( fmerit_m, 1 ) ); /*Q14 */ + move16(); fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; move16(); @@ -949,6 +954,7 @@ void hf_synth_amr_wb_fx( L_tmp = L_mult0( *pt1, fmerit_m ); /*Q13+14 */ *pt1++ = extract_l( L_shr( L_tmp, 14 ) ); /*Q13 */ + move16(); } /* predict LPC coefficents and calculate sub-frame gains */ p_Aq = Aq; @@ -1032,6 +1038,7 @@ void hf_synth_amr_wb_fx( IF( LT_16( beta, 16384 ) ) { L_tmp = 1; /*variable for tonal energy*/ + move32(); pt1 = hb_amb; pt2 = hb_tonal; @@ -1052,6 +1059,7 @@ void hf_synth_amr_wb_fx( #endif } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ + move16(); *pt2 = sub( *pt3, *pt1 ); move16(); IF( *pt2 > 0 ) @@ -1067,6 +1075,7 @@ void hf_synth_amr_wb_fx( fb = sub( i, 7 ); fn = add( fb, 15 ); tmp = 0; + move16(); pt4 = &dct_hb[fb + 240]; FOR( j = fb; j < fn; j++ ) { @@ -1109,6 +1118,7 @@ void hf_synth_amr_wb_fx( #endif } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ + move16(); *pt2 = sub( *pt3, *pt1 ); move16(); IF( *pt2 > 0 ) @@ -1140,20 +1150,22 @@ void hf_synth_amr_wb_fx( pt4 = signum; FOR( i = 0; i < L_SUBFR16k; i++ ) { - if ( *pt1 > 0 ) + IF( *pt1 > 0 ) { *pt1 = mult_r( *pt1, g ); /*qdct */ move16(); } #ifdef BASOP_NOGLOB *pt2 = round_fx_sat( L_shl_sat( L_mult( *pt2, inv_g ), 3 ) ); /*qdct */ + move16(); *pt3 = add_sat( *pt1, *pt2 ); + move16(); #else *pt2 = round_fx( L_shl( L_mult( *pt2, inv_g ), 3 ) ); /*qdct */ *pt3 = add( *pt1, *pt2 ); #endif - move16(); *pt3 = extract_l( L_mult0( *pt3, *pt4 ) ); /*qdct */ + move16(); pt1++; pt2++; pt3++; @@ -1221,6 +1233,7 @@ void hf_synth_amr_wb_fx( IF( GE_16( i, sub( L_FRAME16k, filt_weight_coeff ) ) ) { *pt1 = round_fx( L_shl( L_mult( *pt3, *pt1 ), 1 ) ); /*qdct */ + move16(); } pt1++; pt3++; @@ -1260,6 +1273,7 @@ void hf_synth_amr_wb_fx( IF( GE_16( i, sub( L_FRAME16k, filt_weight_coeff ) ) ) { *pt1 = round_fx( L_shl( L_mult( *pt3, *pt1 ), 1 ) ); /*qdct */ + move16(); } pt1++; pt3++; @@ -1334,6 +1348,7 @@ void hf_synth_amr_wb_fx( { #ifdef BASOP_NOGLOB *pt2 = round_fx_sat( L_shl_sat( L_mult( *pt2, scale ), 2 ) ); /*qhf-1 */ + move16(); #else *pt2 = round_fx( L_shl( L_mult( *pt2, scale ), 2 ) ); /*qhf-1 */ #endif @@ -1418,6 +1433,7 @@ static void hf_synthesis_amr_wb_fx( L_tmp = L_mult( *pt1++, HF_corr_gain ); /*qhf+15*/ L_tmp = Mult_32_16( L_tmp, scale ); /*qhf-1+12+1*/ *pt2++ = round_fx( L_shl( L_tmp, 1 ) ); /*qhf-3*/ + move16(); } pt1 = exc16k; @@ -1468,6 +1484,7 @@ static void hf_synthesis_amr_wb_fx( tmp = s_min( tmp, 4096 ); tmp = s_max( tmp, scale ); *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; + move16(); } } } @@ -1555,6 +1572,7 @@ static Word16 EnhanceClass_fx( /* Decide (*unvoicing_flag) to allow BWE enhancement when qq>pp */ /**voice_fac_fx = add(mult_r(*voice_fac_fx, 24576), mult_r(voice_factor_fx, 8192)); //Q15 */ *voice_fac_fx = round_fx( L_mac( L_mult( *voice_fac_fx, 24576 ), voice_factor_fx, 8192 ) ); /*Q15 */ + move16(); tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ @@ -1571,16 +1589,19 @@ static Word16 EnhanceClass_fx( /**unvoicing_fx = add(mult_r(16384, *unvoicing_fx), mult_r(16384, unvoicing_tmp_fx)); //Q15 */ *unvoicing_fx = round_fx( L_mac( L_mult( 16384, *unvoicing_fx ), 16384, unvoicing_tmp_fx ) ); /*Q15 */ + move16(); IF( GT_16( *unvoicing_sm_fx, *unvoicing_fx ) ) { /**unvoicing_sm_fx = add(mult_r(29491, *unvoicing_sm_fx), mult_r(3277, *unvoicing_fx)); //Q15 */ *unvoicing_sm_fx = round_fx( L_mac( L_mult( 29491, *unvoicing_sm_fx ), 3277, *unvoicing_fx ) ); /*Q15 */ + move16(); } ELSE { /**unvoicing_sm_fx = add(mult_r(32440, *unvoicing_sm_fx), mult_r(328, *unvoicing_fx)); //Q15 */ *unvoicing_sm_fx = round_fx( L_mac( L_mult( 32440, *unvoicing_sm_fx ), 328, *unvoicing_fx ) ); /*Q15 */ + move16(); } #ifdef BASOP_NOGLOB @@ -1590,6 +1611,7 @@ static Word16 EnhanceClass_fx( #endif { *unvoicing_flag = 1; + move16(); } #ifdef BASOP_NOGLOB @@ -1599,6 +1621,7 @@ static Word16 EnhanceClass_fx( #endif { *unvoicing_flag = 0; + move16(); } test(); return ( *unvoicing_flag && GT_16( qq_fx, pp_fx ) ); @@ -1651,7 +1674,8 @@ static void envelope_fx( } /* LPC envelope level estimate */ - L_tmp = L_deposit_l( 0 ); + L_tmp = 0; + move32(); pt1 = Ap; pt2 = exp_tab_p_fx; FOR( i = 0; i <= M; i++ ) @@ -1766,7 +1790,6 @@ static void envelope_fx( if ( k1 < 0 ) { tmp = negate( tmp ); - move16(); } L_tmp = L_mult( As[1], tmp ); /*Q(42-q1) */ @@ -1803,6 +1826,7 @@ static void envelope_fx( move16(); L_tmp = L_mult( As[1], k1 ); /*Q25 */ As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ + move16(); As[2] = k2; move16(); /*Q12 */ @@ -1926,6 +1950,7 @@ static void envelope_fx( #ifdef BASOP_NOGLOB *sub_gain = s_min( 20480, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ + move16(); #else *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ #endif @@ -1958,8 +1983,10 @@ void AdaptiveStartBand_fx( Word16 *pt1, flag; const Word16 *pt2, *pt3; + move32(); // corresponding to initialization of OptCrit_fx /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ voicing_flag_old = *voicing_flag; + move16(); test(); test(); test(); @@ -2045,6 +2072,7 @@ void AdaptiveStartBand_fx( tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); + move16(); L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 ); /* Q11+2.56+2.56 */ test(); @@ -2052,7 +2080,7 @@ void AdaptiveStartBand_fx( test(); test(); IF( NE_16( voicing_flag_old, *voicing_flag ) || ( *voicing_flag == 0 && LT_32( OptCrit_fx, *OptCrit_old_fx ) ) || - ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) > 0 ) ) + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 ) ) ) { *OptCrit_old_fx = OptCrit_fx; move16(); diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index d8ce93970598817f53da5f5742cbaf7203cb1c8e..3a2d3f511590da1ab414f1e8d745c735cb96a8fb 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -29,7 +29,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits max_brate = HQ_32k; move32(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { max_brate = HQ_48k; move32(); @@ -39,7 +39,8 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = get_next_indice( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice( st_fx, 2 ); + move16(); bits = 2; move16(); } @@ -53,22 +54,22 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits ELSE { *hqswb_clas = get_next_indice( st_fx, 1 ); + move16(); bits = 1; move16(); } *is_transient = 0; move16(); - IF( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) + if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { *is_transient = 1; move16(); } test(); - IF( LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) + IF( LE_32( st_fx->core_brate, HQ_32k ) && *hqswb_clas == HQ_NORMAL ) { - move16(); IF( EQ_16( length, L_SPEC32k ) ) { *hqswb_clas = HQ_GEN_SWB; @@ -99,12 +100,16 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits max_brate = HQ_32k; move32(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { max_brate = HQ_48k; move32(); } #ifndef SOLVED_COMP_ENC_DEC + test(); + test(); + test(); + test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_FRAME48k ) ) && LE_32( core_brate, max_brate ) ) #else /*_DIFF_FLOAT_FIX_ -> could this modification break the interoperability with EVS ?? */ @@ -113,6 +118,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits #endif { *hqswb_clas = get_next_indice( st_fx, 2 ); + move16(); bits = 2; move16(); } @@ -126,6 +132,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits ELSE { *hqswb_clas = get_next_indice( st_fx, 1 ); + move16(); bits = 1; move16(); } @@ -139,9 +146,8 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits } test(); - IF( LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) + IF( LE_32( st_fx->core_brate, HQ_32k ) && *hqswb_clas == HQ_NORMAL ) { - move16(); IF( EQ_16( length, L_SPEC32k ) ) { *hqswb_clas = HQ_GEN_SWB; diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 1dc75f4344f11efe15d42ee24a6df8b24a374199..fb0f5f02471dbb37fe336e69a09bdd48115ffd5c 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -131,7 +131,7 @@ void hq_core_dec_fx( { hHQ_core->HqVoicing = 0; move16(); - IF( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) + if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = 1; move16(); @@ -146,6 +146,7 @@ void hq_core_dec_fx( /* set inner frame (== coded bandwidth) length */ inner_frame = inner_frame_tbl[st_fx->bwidth]; + move16(); #ifndef ADD_IVAS_HQ_CODE_L_SPEC L_spec = inner_frame; #endif @@ -252,6 +253,7 @@ void hq_core_dec_fx( { tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ ener_match = hq_nominal_scaling_inv[tmp]; + move16(); FOR( i = 0; i < inner_frame; i++ ) { /*t_audio_q[i] *= ener_match;*/ @@ -500,6 +502,7 @@ void hq_core_dec_fx( st_fx->plcInfo.recovery_gain = shl_sat( st_fx->plcInfo.recovery_gain, *Q_synth ); #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); + move16(); #endif waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth, @@ -555,6 +558,7 @@ void hq_core_dec_fx( Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ nbsubfr = 4; + move16(); if ( EQ_16( st_fx->L_frame, 320 ) ) { nbsubfr = 5; @@ -660,6 +664,8 @@ void ivas_hq_core_dec_fx( } st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); + test(); + test(); hq_recovery_flag = ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && st_fx->prev_bfi && ( GT_16( st_fx->element_mode, EVS_MONO ) ); /* ACELP -> HQtrans -> HQ; with HQtrans lost */ /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 14037b5f6fd20fe6917f2deedccc6835abf928c1..0226c32f3d65f6538e2d87b2954c4e2b9a804e45 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -67,7 +67,7 @@ Word16 decode_envelope_indices_fx( /* o : Number of b { hcode_l = 0; move16(); - IF( EQ_16( LCmode, 0 ) ) + IF( LCmode == 0 ) { hdecnrm_context_fx( st_fx, num_sfm, &difidx[start_norm], &hcode_l ); } @@ -93,17 +93,19 @@ Word16 decode_envelope_indices_fx( /* o : Number of b { pDifidx = pDifidx1++; move16(); - IF( *pDifidx > 17 ) + IF( GT_16( *pDifidx, 17 ) ) { offset = sub( *pDifidx, 17 ); offset = s_min( offset, 3 ); *pDifidx1 = sub( *pDifidx1, offset ); + move16(); } - ELSE IF( *pDifidx < 13 ) + ELSE IF( LT_16( *pDifidx, 13 ) ) { offset = sub( *pDifidx, 13 ); offset = s_max( offset, -3 ); *pDifidx1 = sub( *pDifidx1, offset ); + move16(); } } } diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 8a014d817dd03a9f3349223628b743bddbf1ae3e..a454af97a75ac6ebe558732edffe0c895853dbaa 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -240,7 +240,7 @@ void hq_lr_dec_fx( { num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); } - IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { flag_spt_fx = 1; move16(); @@ -333,6 +333,7 @@ void hq_lr_dec_fx( } Q_band_energy = SWB_BWE_LR_Qbe; + move16(); FOR( i = 0; i < bands_fx; i++ ) { L_tmp = L_shl( L_band_energy[i], sub( 16, Q_band_energy ) ); /*Q16 */ @@ -342,6 +343,7 @@ void hq_lr_dec_fx( exp = sub( exp, 30 ); #ifdef BASOP_NOGLOB Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ + move32(); #else Ep_fx[i] = L_shl( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ #endif @@ -389,6 +391,7 @@ void hq_lr_dec_fx( FOR( i = 0; i < 2; i++ ) { last_bitalloc_max_band[i] = get_next_indice( st_fx, 1 ); + move16(); } lowband = 6; move16(); @@ -435,7 +438,7 @@ void hq_lr_dec_fx( #else Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } @@ -564,7 +567,7 @@ void hq_lr_dec_fx( ELSE { Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ - IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q13 */ } @@ -798,7 +801,7 @@ void hq_lr_dec_fx( #else Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } @@ -1043,10 +1046,11 @@ static Word16 decode_huff_8s_fx( { Word16 bit; - WHILE( GT_16( *hufftab, 0 ) ) + WHILE( *hufftab > 0 ) { *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); bit = get_next_indice( st_fx, s_and( *hufftab, 0xf ) ); + move16(); hufftab += add( shr( *hufftab, 4 ), bit ); } @@ -1069,13 +1073,13 @@ static Word16 large_symbol_dec_fx( /* o : bits move16(); ns2mode = get_next_indice( st_fx, BITS_DE_8SMODE ); - IF( EQ_16( ns2mode, 0 ) ) + IF( ns2mode == 0 ) { ns2mode0 = get_next_indice( st_fx, BITS_DE_8SMODE_N0 ); ns2mode1 = get_next_indice( st_fx, BITS_DE_8SMODE_N1 ); cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); - IF( EQ_16( ns2mode0, 0 ) ) + IF( ns2mode0 == 0 ) { IF( EQ_16( ns2mode1, 1 ) ) { @@ -1160,6 +1164,7 @@ static Word16 large_symbol_dec_fx( /* o : bits bits = 0; move16(); qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + move16(); qbidx[i] = shl( qbidx[i], basic_shift ); move16(); cntbits = add( cntbits, bits ); @@ -1210,7 +1215,7 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ deng_cmode = get_next_indice( st_fx, BITS_DE_CMODE ); - IF( EQ_16( deng_cmode, 0 ) ) + IF( deng_cmode == 0 ) { deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); @@ -1369,6 +1374,7 @@ static void mdct_spectrum_fine_gain_dec_fx( IF( L_y2[i] >= 0x0 ) { L_y2[i] = L_shl( Mpy_32_16_1( L_y2[i], gamma_fx ), 1 ); + move32(); } ELSE { diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index d2c4670b37a20b2c9577d6208f3b41b115982f73..8d846a794d53c2d369f3111da2bce9388a355cf3 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -48,17 +48,17 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou { tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ - IF( EQ_16( cond[i], 0 ) ) + if ( cond[i] == 0 ) { tmp32 = L_deposit_h( 0 ); } - IF( GE_32( tmp32, 0 ) ) + if ( tmp32 >= 0 ) { x_max = L_max( x_max, tmp32 ); } - IF( LT_32( tmp32, 0 ) ) + if ( tmp32 < 0 ) { x_min = L_min( x_min, tmp32 ); } @@ -69,11 +69,11 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou i_min = 0x20; move16(); - IF( NE_32( x_max, 0 ) ) + if ( x_max != 0 ) { i_max = norm_l( x_max ); } - IF( NE_32( x_min, 0 ) ) + if ( x_min != 0 ) { i_min = norm_l( x_min ); } @@ -109,24 +109,26 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou nE = 0; move32(); - FOR( sb = start; sb < stop; sb++ ){ - IF( TCXNoise[sb] ){ + FOR( sb = start; sb < stop; sb++ ) + { + if ( TCXNoise[sb] ) + { tmp16 = extract_h( L_shl( in[sb], s_l ) ); -} -IF( TCXNoise[sb] ) -{ - nE = L_mac( nE, tmp16, tmp16 ); -} -IF( TCXNoise[sb] ) -{ - noise = add( noise, 1 ); -} -} + } + if ( TCXNoise[sb] ) + { + nE = L_mac( nE, tmp16, tmp16 ); + } + if ( TCXNoise[sb] ) + { + noise = add( noise, 1 ); + } + } -*totalNoiseNrg = nE; -move32(); + *totalNoiseNrg = nE; + move32(); -return noise; + return noise; } /**********************************************************************/ /* @@ -177,20 +179,20 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in /* make sure that rE is never 0 */ - IF( EQ_32( rE, 0 ) ) + IF( rE == 0 ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - IF( EQ_32( totalNoiseNrg, 0 ) ) + if ( totalNoiseNrg == 0 ) { rE = L_max( rE, 0x00010000 ); } /* make sure that rE is never smaller than totalNoiseNrg */ L_tmp = L_sub( rE, totalNoiseNrg ); - IF( LT_32( L_tmp, 0 ) ) + if ( L_tmp < 0 ) { rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ move32(); @@ -254,18 +256,18 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in } - IF( NE_16( n_noise_bands_tile, 0 ) ) + IF( n_noise_bands_tile != 0 ) { noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 /* make sure that rE is never 0 */ - IF( EQ_32( rE, 0 ) ) + if ( rE == 0 ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - IF( EQ_32( totalNoiseNrg, 0 ) ) + if ( totalNoiseNrg == 0 ) { rE = L_max( rE, 0x00010000 ); } @@ -281,9 +283,9 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in IF( TCXNoise[sb] ) { Word16 nrm = norm_l( in[sb] ); - in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp - in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e - in[sb] = L_shr( in[sb], sub( in_e, 31 - nrm + tmp_e ) ); // Making the exponent same as original + in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp + in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e + in[sb] = L_shr( in[sb], sub( in_e, sub( add( 31, tmp_e ), nrm ) ) ); // Making the exponent same as original move32(); } } @@ -336,18 +338,18 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, } - IF( NE_16( n_noise_bands_tile, 0 ) ) + IF( n_noise_bands_tile != 0 ) { noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 /* make sure that rE is never 0 */ - IF( EQ_32( rE, 0 ) ) + IF( rE == 0 ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - IF( EQ_32( totalNoiseNrg, 0 ) ) + IF( totalNoiseNrg == 0 ) { rE = L_max( rE, 0x00010000 ); } @@ -389,7 +391,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, tmp = get_next_indice( st, 1 ); - IF( EQ_16( tmp, 0 ) ) + IF( tmp == 0 ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; move16(); @@ -401,7 +403,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; move16(); - IF( EQ_16( tmp, 0 ) ) + if ( tmp == 0 ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); @@ -434,9 +436,10 @@ static void IGF_setLinesToZero( const Word16 startLine, /**< in if there is content in the original MDCT spectrum */ FOR( i = startLine; i < stopLine; i++ ) { - IF( NE_32( pSpectralData[i], 0 ) ) + if ( pSpectralData[i] != 0 ) { pPowerSpecIGF[i] = L_deposit_l( 0 ); + move32(); } } } @@ -545,7 +548,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF( NE_32( abs_sum, 0 ) ) + IF( abs_sum != 0 ) { FOR( i = strt_cpy; i < startLine; i++ ) { @@ -570,7 +573,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* medium whitening detected */ IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF( NE_16( n_noise_bands, 0 ) ) + IF( n_noise_bands != 0 ) { IGF_replaceTCXNoise_2( igf_spec, TCXNoise, @@ -593,7 +596,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* off whitening detectded */ ELSE { - IF( NE_16( n_noise_bands_off, 0 ) ) + IF( n_noise_bands_off != 0 ) { IGF_replaceTCXNoise_2( hPrivateData->pSpecFlat, TCXNoise, @@ -715,11 +718,12 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF( NE_32( abs_sum, 0 ) ) + IF( abs_sum != 0 ) { FOR( i = strt_cpy; i < stop; i++ ) { igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + move32(); } } ELSE @@ -742,7 +746,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { IF( GT_16( element_mode, EVS_MONO ) ) { - IF( NE_16( n_noise_bands, 0 ) ) + IF( n_noise_bands != 0 ) { IGF_replaceTCXNoise_2_new_ivas( igf_spec, specMed_e, @@ -757,7 +761,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - IF( NE_16( n_noise_bands, 0 ) ) + IF( n_noise_bands != 0 ) { IGF_replaceTCXNoise_2( igf_spec, TCXNoise, @@ -783,7 +787,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in IF( GT_16( element_mode, EVS_MONO ) ) { - IF( NE_16( n_noise_bands_off, 0 ) ) + IF( n_noise_bands_off != 0 ) { IGF_replaceTCXNoise_2_new_ivas( src_spec, src_spec_e, @@ -798,7 +802,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - IF( NE_16( n_noise_bands_off, 0 ) ) + IF( n_noise_bands_off != 0 ) { IGF_replaceTCXNoise_2( src_spec, TCXNoise, @@ -1040,6 +1044,7 @@ static void IGF_prepStereo( IF( EQ_16( IGF_WHITENING_STRONG, hPrivateDataR->currWhiteningLevel[tile_idx] ) ) { tb = swb_offset[hGrid->sfbWrap[tile_idx]]; + move16(); FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { @@ -1156,7 +1161,7 @@ static void IGF_prepStereo( move16(); } - IF( EQ_16( coreMsMask[tb], 0 ) ) + IF( ( coreMsMask[tb] == 0 ) ) { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->LR */ { @@ -1510,6 +1515,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < 24; tb++ ) { Carry = 0; + move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); Overflow = 0; @@ -1531,12 +1537,12 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) + if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) + if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); @@ -1563,13 +1569,15 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in &pN_e[sfb] ); move32(); sN[tb] = L_deposit_l( 0 ); + move32(); pN[tb] = L_deposit_l( 0 ); + move32(); } } } /* IGF_rescale_SCF */ - IF( NE_16( hGrid->infoIsRefined, 0 ) ) + IF( hGrid->infoIsRefined != 0 ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { @@ -1626,7 +1634,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( LT_32( L_tmp2, 0 ) ) + IF( L_tmp2 < 0 ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -1637,8 +1645,10 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_tmp = Sqrt32( L_tmp, &L_tmp_e ); #ifdef BASOP_NOGLOB dN[sfb] = round_fx_sat( L_tmp ); + move16(); #else dN[sfb] = round_fx( L_tmp ); + move16(); #endif dN_e[sfb] = L_tmp_e; move16(); @@ -1704,7 +1714,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( LT_32( L_tmp2, 0 ) ) + IF( L_tmp2 < 0 ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -1713,6 +1723,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32( L_tmp, &L_tmp_e ); dN[sfb] = round_fx( L_tmp ); + move16(); dN_e[sfb] = L_tmp_e; move16(); } @@ -1729,7 +1740,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in negate( dN[start_sfb] ), dN_e[start_sfb], &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ L_tmp = L_mult( fFactor, tmp ); @@ -1750,7 +1761,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in sfb_p1 = add( start_sfb, 1 ); sfb_m1 = sub( stop_sfb, 1 ); test(); - IF( NE_16( hGrid->infoIsRefined, 0 ) && EQ_16( hopsize, 1 ) ) + IF( hGrid->infoIsRefined != 0 && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) @@ -1880,7 +1891,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* gain calculation */ gain[sfb] = 0; move16(); - IF( NE_32( pN[sfb], 0 ) ) + IF( pN[sfb] != 0 ) { tmp = BASOP_Util_Divide3232_Scale( dNlocal, pN[sfb], &s ); s = sub( add( s, dNlocal_e ), pN_e[sfb] ); @@ -1905,7 +1916,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - IF( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + if ( LE_16( hGrid->sfbWrap[add( tileIdx, 1 )], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -1915,7 +1926,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*check whether overflow would occur and calculate Headroom, needed*/ shift = sub( L_tmp_e, *spectrum_e ); tmp = sub( shift, sub( norm_l( L_tmp ), TCX_IMDCT_HEADROOM ) ); - IF( GT_16( tmp, 0 ) ) + if ( tmp > 0 ) { Hr = s_max( Hr, tmp ); } @@ -1923,7 +1934,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* disable rescaling if gain is smaler than 1 */ /* gain < 1, if norm_s(gain[sfb]) >= gain_e[sfb] */ tmp = sub( norm_s( gain[sfb] ), gain_e[sfb] ); - IF( GE_16( tmp, 0 ) ) + if ( tmp >= 0 ) { Hr = 0; move16(); @@ -1933,7 +1944,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* Rescale spectrum if overflow may occur */ tileIdx = -1; move16(); - IF( GT_16( Hr, 0 ) ) + IF( Hr > 0 ) { /* rescale virtual Spec, cheap and easy: reset scalingfactor */ *virtualSpec_e = add( *virtualSpec_e, Hr ); @@ -1955,7 +1966,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -1965,7 +1976,9 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* normalize gain */ tmp = norm_s( gain[sfb] ); gain[sfb] = shl( gain[sfb], tmp ); + move16(); gain_e[sfb] = sub( gain_e[sfb], tmp ); + move16(); /* gain[sfb] = min(gain[sfb], 12.f); */ BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ @@ -2032,8 +2045,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in IF( spectrum[tb] == 0 ) { shift = sub( L_tmp_e, *spectrum_e ); - tmp = norm_l( L_tmp ) - shift - 32; - IF( LT_16( tmp, 0 ) ) + tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); + if ( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2045,8 +2058,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in ELSE { shift = sub( L_tmp_e, *virtualSpec_e ); - tmp = norm_l( L_tmp ) - shift - 32; - IF( LT_16( tmp, 0 ) ) + tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); + if ( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2129,7 +2142,9 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in Word16 vspec_e_arr[N_MAX_TCX - IGF_START_MN]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); Flag Carry = 0; + move16(); #endif @@ -2213,6 +2228,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < 24; tb++ ) { Carry = 0; + move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); Overflow = 0; @@ -2234,12 +2250,12 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) + if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) + if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); @@ -2270,13 +2286,15 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in &pN_e[sfb] ); move32(); sN[tb] = L_deposit_l( 0 ); + move32(); pN[tb] = L_deposit_l( 0 ); + move32(); } } } /* IGF_rescale_SCF */ - IF( NE_16( hGrid->infoIsRefined, 0 ) ) + IF( hGrid->infoIsRefined != 0 ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { @@ -2333,7 +2351,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( LT_32( L_tmp2, 0 ) ) + IF( L_tmp2 < 0 ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -2343,6 +2361,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32( L_tmp, &L_tmp_e ); dN[sfb] = extract_h( L_tmp ); + move16(); dN_e[sfb] = L_tmp_e; move16(); dN[sfb + 1] = dN[sfb]; @@ -2400,15 +2419,17 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); - IF( LT_32( L_tmp2, 0 ) ) + IF( L_tmp2 < 0 ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; + move16(); } /* calc square root of L_tmp and store result in dN */ L_tmp = Sqrt32( L_tmp, &L_tmp_e ); dN[sfb] = round_fx( L_tmp ); + move16(); dN_e[sfb] = L_tmp_e; move16(); } @@ -2425,7 +2446,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in negate( dN[start_sfb] ), dN_e[start_sfb], &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ L_tmp = L_mult( fFactor, tmp ); @@ -2446,7 +2467,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in sfb_p1 = add( start_sfb, 1 ); sfb_m1 = sub( stop_sfb, 1 ); test(); - IF( NE_16( hGrid->infoIsRefined, 0 ) && EQ_16( hopsize, 1 ) ) + IF( hGrid->infoIsRefined != 0 && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) @@ -2456,6 +2477,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in dS[sfb] = round_fx( L_tmp ); move16(); dS_e[sfb] = dN_e[sfb - 1]; /* w0 is Q15, so no need to add an exponent */ + move16(); L_tmp = L_mult( w1, dN[sfb] ); dS_e[sfb] = BASOP_Util_Add_MantExp( dS[sfb], dS_e[sfb], @@ -2543,6 +2565,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* take the square root and store the result in dS */ L_tmp = Sqrt32( L_tmp, &L_tmp_e ); dS[sfb] = round_fx( L_tmp ); + move16(); dS_e[sfb] = L_tmp_e; move16(); @@ -2604,7 +2627,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2615,7 +2638,9 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* normalize gain */ tmp = norm_s( gain[sfb] ); gain[sfb] = shl( gain[sfb], tmp ); + move16(); gain_e[sfb] = sub( gain_e[sfb], tmp ); + move16(); /* gain[sfb] = min(gain[sfb], 12.f); */ BASOP_SATURATE_WARNING_OFF_EVS /* threshold, may overflow */ @@ -2768,7 +2793,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in ak_norm = Mpy_32_16_r( ak, 2185 ); tmp_16 = sub( 31, norm_l( ak_norm ) ); - IF( EQ_32( ak, 0 ) ) + if ( ak == 0 ) { tmp_16 = 0; move16(); @@ -2791,7 +2816,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); tmp_16 = sub( 31, norm_l( ak_norm ) ); - IF( EQ_32( ak, 0 ) ) + if ( ak == 0 ) { tmp_16 = 0; move16(); @@ -2800,7 +2825,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); div = shl( 1, tmp_16 ); - IF( LT_32( ak, 16 ) ) + if ( LT_32( ak, 16 ) ) { div = 1; move16(); @@ -2857,7 +2882,9 @@ static void IGF_getWhiteSpectralData_ivas( FOR( i = start; i < stop - level; i++ ) { ak = 0; + move32(); ak_e = 0; + move32(); FOR( j = i - level; j < i + level + 1; j++ ) { tmp_16 = extract_h( L_shl( in[j], s_l ) ); @@ -2919,6 +2946,7 @@ static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in Word16 delta; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif set16_fx( a, 0, IGF_MAX_SFB + 1 ); @@ -2969,6 +2997,7 @@ static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid han Word16 delta; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif set16_fx( a, 0, IGF_MAX_SFB + 1 ); @@ -2994,6 +3023,7 @@ static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid han IF( GE_16( sub( delta, shl( shr( delta, 6 ), 6 ) ), MID ) ) { a[tmp] = add( a[tmp], 1 ); + move16(); } move16(); IF( s_and( a[tmp], 1 ) != 0 ) @@ -3048,12 +3078,12 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in move16(); } - IF( EQ_16( isIndepFrame, 0 ) ) + IF( isIndepFrame == 0 ) { tmp = get_next_indice( st, 1 ); } - IF( EQ_16( tmp, 1 ) ) + IF( tmp == 1 ) { FOR( p = 0; p < nT; p++ ) { @@ -3065,7 +3095,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in { IGF_decode_whitening_level( st, hPrivateData, 0 ); test(); - IF( hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_SWB_48000_CPE || hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_FB_48000_CPE ) + IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) { tmp = 0; move16(); @@ -3133,7 +3163,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins move16(); } - IF( EQ_16( isIndepFrame, 0 ) ) + IF( isIndepFrame == 0 ) { tmp = get_next_indice( st, 1 ); } @@ -3205,7 +3235,7 @@ void IGFDecReadLevel( /**< ou move16(); IGFAllZero = get_next_indice( st, 1 ); - IF( EQ_16( IGFAllZero, 0 ) ) + IF( IGFAllZero == 0 ) { Copy( hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb ); IGFSCFDecoderDecode( &hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart], /* 0Q15, hPrivateData->igf_curr = [0, 91] */ igfGridIdx, isIndepFrame ); @@ -3266,7 +3296,7 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF( NE_16( bfi, 0 ) ) + IF( bfi != 0 ) { hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } @@ -3277,7 +3307,7 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } /* skip IGF processing if all IGF levels are zero */ - IF( EQ_16( hInstance->infoIGFAllZero, 0 ) ) + IF( hInstance->infoIGFAllZero == 0 ) { @@ -3434,7 +3464,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF( NE_16( bfi, 0 ) ) + IF( bfi != 0 ) { hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } @@ -3445,7 +3475,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } /* skip IGF processing if all IGF levels are zero */ - IF( EQ_16( hInstance->infoIGFAllZero, 0 ) ) + IF( hInstance->infoIGFAllZero == 0 ) { FOR( i = 0; i < hGrid->nTiles; i++ ) { @@ -4262,9 +4292,9 @@ Word16 get_igf_startline( { Word16 igf_startline; - IF( EQ_16( st->igf, 0 ) ) + IF( st->igf == 0 ) { - IF( EQ_16( st->narrowBand, 0 ) ) + IF( st->narrowBand == 0 ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index cda1bb3b8aa08ff4350ac0c51682d196d7ef4e14..b9af11db158cb9d6c6b54ac4ac8f25b90962933e 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -54,7 +54,7 @@ static Word16 quant_ctx_fx( result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ - IF( LT_16( ctx, 0 ) ) /* add the sign back, if needed */ + if ( ctx < 0 ) /* add the sign back, if needed */ { result = negate( result ); } @@ -80,7 +80,7 @@ static Word16 arith_decode_bits_fx( x = lshl( x, 1 ); /* decode one bit using the new raw AC function */ bit = ari_decode_14bits_bit_ext_fx( st, &hPrivateData->acState ); - IF( NE_16( bit, 0 ) ) + if ( bit != 0 ) { x = s_or( x, 1 ); } @@ -107,7 +107,7 @@ static Word16 arith_decode_residual_fx( /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ test(); - IF( ( NE_16( val, 0 ) ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) + IF( ( val != 0 ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) { x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ @@ -133,12 +133,12 @@ static Word16 arith_decode_residual_fx( extra = add( 15, extra ); } - IF( EQ_16( val, 0 ) ) + if ( val == 0 ) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); } - IF( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) + if ( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); @@ -186,9 +186,9 @@ static void decode_sfe_vector_fx( FOR( f = 0; f < length; ++f ) { - IF( EQ_16( t, 0 ) ) + IF( t == 0 ) { - IF( EQ_16( f, 0 ) ) + IF( f == 0 ) { /* (t == 0) && (f == 0) */ /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ @@ -228,7 +228,7 @@ static void decode_sfe_vector_fx( ELSE { /* t == 1 */ - IF( EQ_16( f, 0 ) ) + IF( f == 0 ) { /* (t == 1) && (f == 0) */ res = arith_decode_residual_fx( hPrivateData, @@ -264,7 +264,7 @@ static void decode_sfe_vector_fx( } } - IF( LT_16( x[f], 0 ) ) + IF( x[f] < 0 ) { x[f] = 0; move16(); @@ -315,7 +315,7 @@ void IGFSCFDecoderDecode( ari_start_decoding_14bits_fx( st, &hPublicData->acState ); /* start AC decoding */ /* check if coder needs a reset and do it if necessary */ - IF( NE_16( indepFlag, 0 ) ) + IF( indepFlag != 0 ) { /* reset of coder */ IGFSCFDecoderReset( hPublicData ); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index ad5c524c136379f1a5cf7528f600ce7107c514f1..ba95b6933bb73c2db66eaaaee5f4ae21f4104ac6 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -130,7 +130,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) count_malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -149,7 +149,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) count_malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { @@ -209,7 +209,7 @@ ivas_error init_decoder_fx( test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) count_malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { @@ -227,7 +227,7 @@ ivas_error init_decoder_fx( * parameters for fast recovery (WI) *-----------------------------------------------------------------*/ test(); - IF( EQ_32( st_fx->output_Fs, 16000 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) { @@ -354,7 +354,7 @@ ivas_error init_decoder_fx( test(); test(); test(); - IF( EQ_16( idchan, 0 ) && ( EQ_16( st_fx->element_mode, EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) + IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) { IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) count_malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { @@ -368,6 +368,7 @@ ivas_error init_decoder_fx( st_fx->hTdCngDec = NULL; } st_fx->cng_type = -1; + move16(); st_fx->CNG_fx = 0; move16(); /* RTXDTX handler CNG=1 nonCNG= 0,*/ st_fx->prev_ft_speech_fx = 1; @@ -397,7 +398,9 @@ ivas_error init_decoder_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; + move16(); st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; + move16(); } st_fx->shb_dtx_count_fx = 0; @@ -428,7 +431,7 @@ ivas_error init_decoder_fx( test(); test(); test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || ( st_fx->element_mode == EVS_MONO ) ) ) { IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) count_malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { @@ -438,7 +441,7 @@ ivas_error init_decoder_fx( /* HQ core initialization */ HQ_core_dec_init_fx( st_fx->hHQ_core ); - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { /* HQ NB FEC initialization */ IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) count_malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) @@ -468,7 +471,7 @@ ivas_error init_decoder_fx( move16(); set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); } @@ -477,7 +480,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ /* TCX-LTP */ - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) count_malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { @@ -491,7 +494,7 @@ ivas_error init_decoder_fx( /* TCX core */ // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 - IF( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) count_malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { @@ -508,7 +511,7 @@ ivas_error init_decoder_fx( st_fx->hTcxDec = NULL; } /* TCX config. data structure */ - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { @@ -536,7 +539,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) count_malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -623,7 +626,7 @@ ivas_error init_decoder_fx( * AMR-WB IO mode parameters *----------------------------------------------------------------------------------*/ test(); - IF( st_fx->Opt_AMR_WB || EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->Opt_AMR_WB || st_fx->element_mode == EVS_MONO ) { IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) count_malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) { @@ -645,7 +648,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) count_malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) { @@ -672,7 +675,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) count_malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) { @@ -689,18 +692,18 @@ ivas_error init_decoder_fx( * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ /* open analysis for max. SR 48kHz */ - IF( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ), IVAS_ERR_OK ) ) { return error; } /* open analysis BPF for max. SR 16kHz */ - IF( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ), IVAS_ERR_OK ) ) { return error; } /* open synthesis for output SR */ - IF( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -731,7 +734,7 @@ ivas_error init_decoder_fx( * SC-VBR parameters *-----------------------------------------------------------------*/ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) count_malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) { @@ -788,12 +791,12 @@ ivas_error init_decoder_fx( #ifdef IVAS_CODE IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) // TBV Fixed point missing #else - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( idchan, 0 ) ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) #endif { /* Create FD_CNG instance */ - IF( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } @@ -942,6 +945,7 @@ ivas_error init_decoder_ivas_fx( move16(); st_fx->flag_ACELP16k = set_ACELP_flag( st_fx->element_mode, st_fx->total_brate, st_fx->total_brate, idchan, 0, -1, -1 ); + move16(); /*-----------------------------------------------------------------* * ACELP core parameters @@ -1109,7 +1113,7 @@ ivas_error init_decoder_ivas_fx( test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) count_malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { @@ -1128,7 +1132,7 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_32( st_fx->output_Fs, 16000 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) { @@ -1148,7 +1152,7 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) count_malloc( sizeof( PFSTAT ) ) ) == NULL ) { @@ -1170,7 +1174,7 @@ ivas_error init_decoder_ivas_fx( test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) { @@ -1192,7 +1196,7 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) count_malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) { @@ -1226,7 +1230,7 @@ ivas_error init_decoder_ivas_fx( test(); test(); test(); - IF( EQ_16( idchan, 0 ) && ( EQ_16( st_fx->element_mode, EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) + IF( idchan == 0 && ( EQ_16( st_fx->element_mode, EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) { IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) count_malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { @@ -1266,7 +1270,7 @@ ivas_error init_decoder_ivas_fx( test(); test(); test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) { IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { @@ -1302,7 +1306,7 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -1328,7 +1332,7 @@ ivas_error init_decoder_ivas_fx( * SWB BWE parameters *-----------------------------------------------------------------*/ test(); - IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -1373,7 +1377,7 @@ ivas_error init_decoder_ivas_fx( * HR SWB BWE parameters *-----------------------------------------------------------------*/ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) count_malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) { @@ -1448,7 +1452,7 @@ ivas_error init_decoder_ivas_fx( test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) { @@ -1467,16 +1471,16 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { /* open analysis for max. SR 48kHz */ - IF( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } /* open analysis BPF for max. SR 16kHz */ - IF( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -1488,7 +1492,7 @@ ivas_error init_decoder_ivas_fx( } /* open synthesis for output SR */ - IF( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -1566,7 +1570,7 @@ ivas_error init_decoder_ivas_fx( /* TCX-LTP */ test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) count_malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { @@ -1580,7 +1584,7 @@ ivas_error init_decoder_ivas_fx( /* TCX core */ test(); - IF( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { @@ -1589,8 +1593,8 @@ ivas_error init_decoder_ivas_fx( set32_fx( st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA( st_fx->output_Fs, PH_ECU_MEM_NS ); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_fx2( st_fx->output_Fs, PH_ECU_MEM_NS ); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); } ELSE { @@ -1599,7 +1603,7 @@ ivas_error init_decoder_ivas_fx( /* TCX config. data structure */ test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { @@ -1613,7 +1617,7 @@ ivas_error init_decoder_ivas_fx( /* Tonal MDCT concealment data structure */ test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) { @@ -1630,7 +1634,7 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ test(); - IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { @@ -1649,7 +1653,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * Mode 2 initialization *-----------------------------------------------------------------*/ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) { @@ -1697,7 +1701,7 @@ ivas_error init_decoder_ivas_fx( move16(); test(); - IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); @@ -1710,11 +1714,11 @@ ivas_error init_decoder_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( idchan, 0 ) ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { /* Create FD_CNG instance */ - IF( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 9531a05be38cfca22d145739e9d20900af856953..24c82e20ae7ad543f189a81c92c62b648bae2ca5 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -82,7 +82,7 @@ void inov_decode_fx( test(); test(); test(); - IF( GE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr], 0 ) ) + IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0 ) { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { @@ -100,9 +100,9 @@ void inov_decode_fx( dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); } } - ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( ( st_fx->idchan == 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) { - IF( EQ_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0 ) ) + IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { // dec_acelp_1t64(st_fx, code, L_SUBFR); dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); @@ -115,18 +115,20 @@ void inov_decode_fx( } ELSE { - wordcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) >> 4; + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); move16(); - bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { indexing_indices[i] = get_next_indice( st_fx, 16 ); + move16(); } IF( bitcnt ) { indexing_indices[i] = get_next_indice( st_fx, bitcnt ); + move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); @@ -271,7 +273,7 @@ void inov_decode_ivas_fx( test(); test(); test(); - IF( GE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr], 0 ) ) + IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0 ) { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { @@ -290,7 +292,7 @@ void inov_decode_ivas_fx( } ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) { - IF( EQ_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0 ) ) + IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { // dec_acelp_1t64(st_fx, code, L_SUBFR); dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); diff --git a/lib_dec/ivas_agc_dec_fx.c b/lib_dec/ivas_agc_dec_fx.c index 6043e082c5fc0684741d634b6428ffbbc53aa08d..2bf3ad9ca4c121a92fcf8237d012f7bdd187bc24 100644 --- a/lib_dec/ivas_agc_dec_fx.c +++ b/lib_dec/ivas_agc_dec_fx.c @@ -210,7 +210,7 @@ void ivas_agc_dec_process_fx( // gainLast = 1.f / pState->gain_state[i].lastGain; tmp = negate( sub( pState->gain_data[i].absGainExp, pState->agc_com.absEmin ) ); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { tmp_2 = MAX_16; move16(); @@ -233,7 +233,7 @@ void ivas_agc_dec_process_fx( move16(); gainLast = div_l( ONE_IN_Q29, pState->gain_state[i].lastGain_fx ); // Q13 - IF( NE_16( pState->gain_state[i].gainExpVal, 0 ) ) + IF( pState->gain_state[i].gainExpVal != 0 ) { FOR( idx = 0; idx < output_frame; idx++ ) { @@ -242,8 +242,7 @@ void ivas_agc_dec_process_fx( // gain = powf( pState->agc_com.winFunc[idx - pState->agc_com.in_delay], (float) ( -1 * pState->gain_state[i].gainExpVal ) ) * gainLast; tmp = negate( pState->gain_state[i].gainExpVal ); - move16(); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { tmp_2 = MAX_16; move16(); @@ -251,7 +250,7 @@ void ivas_agc_dec_process_fx( { tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); } - IF( LT_16( tmp_2, 0 ) ) + IF( tmp_2 < 0 ) { tmp_2 = div_l( ONE_IN_Q30, negate( tmp_2 ) ); // Q14 tmp_2 = negate( tmp_2 ); @@ -267,7 +266,7 @@ void ivas_agc_dec_process_fx( move16(); FOR( j = 0; j < ( tmp ); j++ ) { - tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); + tmp_2 = mult( pState->agc_com.winFunc_fx[sub( idx, pState->agc_com.in_delay )], tmp_2 ); } tmp_2 = shr( tmp_2, 1 ); // Q14 } @@ -284,7 +283,7 @@ void ivas_agc_dec_process_fx( // pState->gain_state[i].lastGain *= powf( pState->agc_com.winFunc[offset - 1], (float) pState->gain_state[i].gainExpVal ); tmp = pState->gain_state[i].gainExpVal; move16(); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { tmp_2 = MAX_16; move16(); @@ -357,6 +356,7 @@ void ivas_agc_read_bits_fx( ELSE { pState->gain_data[i].absGainExpCurr = (Word32) pState->agc_com.absEmin; + move32(); } } } @@ -365,6 +365,7 @@ void ivas_agc_read_bits_fx( FOR( i = 0; i < n_channels; i++ ) { pState->gain_data[i].absGainExpCurr = (Word32) pState->agc_com.absEmin; + move32(); } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 3d9020f7c2252883364ec255062b401c2222af79..8933057bdcd71312466b8a650d63c8d3fee24693 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -328,11 +328,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_spar_dec_open( st_ivas, 1 ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -357,20 +353,13 @@ ivas_error ivas_sba_dec_reconfigure( } ivas_pca_dec_init( hSpar->hPCA ); -#ifdef IVAS_FLOAT_FIXED - ivas_pca_dec_init_fx( hSpar->hPCA ); -#endif } ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); } else { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -432,19 +421,11 @@ ivas_error ivas_sba_dec_reconfigure( ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); } -#ifdef IVAS_FLOAT_FIXED - 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_fx( 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 ) - { - return error; - } -#else 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 ) { return error; } -#endif if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( 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 ) ) ) { @@ -456,11 +437,7 @@ ivas_error ivas_sba_dec_reconfigure( flag_config = DIRAC_RECONFIGURE_MODE; } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_dirac_dec_config( st_ivas, flag_config ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -470,7 +447,7 @@ ivas_error ivas_sba_dec_reconfigure( int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - if ( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ) + if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; @@ -478,8 +455,8 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; } - ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), - st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); if ( st_ivas->hDirAC ) { @@ -489,17 +466,10 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->renderer_type == RENDERER_DISABLE ) { -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); - vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); -#else ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); -#endif } if ( st_ivas->hDirAC != NULL ) @@ -518,11 +488,7 @@ ivas_error ivas_sba_dec_reconfigure( int32_t temp_brate[MAX_SCE]; st_ivas->ism_mode = ISM_SBA_MODE_DISC; -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -537,17 +503,10 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#endif } if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) @@ -613,32 +572,20 @@ ivas_error ivas_sba_dec_reconfigure( } } -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, 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; - } -#else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, 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; } -#endif /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#else + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) { return error; } -#endif + /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ @@ -748,12 +695,6 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED return error; } diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index b6a4240933602b470d42b1fab3a2dad1fad4b683..d88e311983b3e558895942f6a8f93f3fedce3bb1 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -360,10 +360,29 @@ void parse_stereo_from_bitstream( IF( !isSBAStereoMode ) { - nSubframes = ( EQ_16( sts[0]->core, TCX_10_CORE ) || ( NE_16( sts[0]->core, sts[1]->core ) ) ) ? NB_DIV : 1; + // nSubframes = ( EQ_16( sts[0]->core, TCX_10_CORE ) || ( NE_16( sts[0]->core, sts[1]->core ) ) ) ? NB_DIV : 1; + test(); + IF( ( EQ_16( sts[0]->core, TCX_10_CORE ) || ( NE_16( sts[0]->core, sts[1]->core ) ) ) ) + { + nSubframes = NB_DIV; + move16(); + } + ELSE + { + nSubframes = 1; + move16(); + } move16(); - sfbConf = ( EQ_16( sts[0]->core, TCX_20_CORE ) ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; - IF( EQ_16( sts[0]->last_core_from_bs, ACELP_CORE ) ) + // sfbConf = ( EQ_16( sts[0]->core, TCX_20_CORE ) ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + IF( ( EQ_16( sts[0]->core, TCX_20_CORE ) ) ) + { + sfbConf = &hStereoMdct->stbParamsTCX20; + } + ELSE + { + sfbConf = &hStereoMdct->stbParamsTCX10; + } + if ( sts[0]->last_core_from_bs == ACELP_CORE ) { sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; } @@ -412,7 +431,7 @@ void parse_stereo_from_bitstream( IF( !mct_on ) { test(); - IF( EQ_16( sts[0]->core, sts[1]->core ) || EQ_16( k, 0 ) ) + IF( EQ_16( sts[0]->core, sts[1]->core ) || k == 0 ) { hStereoMdct->global_ild[k] = extract_l( get_next_indice_fx( st0, SMDCT_GLOBAL_ILD_BITS ) ); move16(); @@ -425,7 +444,15 @@ void parse_stereo_from_bitstream( } } - set16_fx( ms_mask[k], ( EQ_16( hStereoMdct->mdct_stereo_mode[k], SMDCT_MS_FULL ) ) ? 1 : 0, sfbConf->nBandsStereoCore ); + // set16_fx( ms_mask[k], ( EQ_16( hStereoMdct->mdct_stereo_mode[k], SMDCT_MS_FULL ) ) ? 1 : 0, sfbConf->nBandsStereoCore ); + IF( ( EQ_16( hStereoMdct->mdct_stereo_mode[k], SMDCT_MS_FULL ) ) ) + { + set16_fx( ms_mask[k], 1, sfbConf->nBandsStereoCore ); + } + ELSE + { + set16_fx( ms_mask[k], 0, sfbConf->nBandsStereoCore ); + } IF( EQ_16( hStereoMdct->mdct_stereo_mode[k], SMDCT_BW_MS ) ) { @@ -462,7 +489,15 @@ void parse_stereo_from_bitstream( assert( !"Not supported stereo mode\n" ); } - set16_fx( &ms_mask[k][sfbConf->nBandsStereoCore], ( EQ_16( hStereoMdct->IGFStereoMode[k], SMDCT_MS_FULL ) ) ? 1 : 0, sub( sfbConf->sfbCnt, sfbConf->nBandsStereoCore ) ); + // set16_fx( &ms_mask[k][sfbConf->nBandsStereoCore], ( EQ_16( hStereoMdct->IGFStereoMode[k], SMDCT_MS_FULL ) ) ? 1 : 0, sub( sfbConf->sfbCnt, sfbConf->nBandsStereoCore ) ); + IF( ( EQ_16( hStereoMdct->IGFStereoMode[k], SMDCT_MS_FULL ) ) ) + { + set16_fx( &ms_mask[k][sfbConf->nBandsStereoCore], 1, sub( sfbConf->sfbCnt, sfbConf->nBandsStereoCore ) ); + } + ELSE + { + set16_fx( &ms_mask[k][sfbConf->nBandsStereoCore], 0, sub( sfbConf->sfbCnt, sfbConf->nBandsStereoCore ) ); + } IF( EQ_16( hStereoMdct->IGFStereoMode[k], SMDCT_BW_MS ) ) { @@ -576,7 +611,7 @@ void stereo_decoder_tcx_fx( move16(); test(); test(); - IF( ( LE_16( core_l, TCX_20_CORE ) && LE_16( core_r, TCX_20_CORE ) ) || tmp_plc_upmix ) + if ( ( LE_16( core_l, TCX_20_CORE ) && LE_16( core_r, TCX_20_CORE ) ) || tmp_plc_upmix ) { nSubframes = 1; move16(); @@ -584,10 +619,18 @@ void stereo_decoder_tcx_fx( FOR( k = 0; k < nSubframes; k++ ) { - sfbConf = ( EQ_16( core_l, TCX_20_CORE ) ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + // sfbConf = ( EQ_16( core_l, TCX_20_CORE ) ) ? &hStereoMdct->stbParamsTCX20 : &hStereoMdct->stbParamsTCX10; + IF( ( EQ_16( core_l, TCX_20_CORE ) ) ) + { + sfbConf = &hStereoMdct->stbParamsTCX20; + } + ELSE + { + sfbConf = &hStereoMdct->stbParamsTCX10; + } test(); - IF( EQ_16( last_core_l, ACELP_CORE ) || EQ_16( last_core_r, ACELP_CORE ) ) + if ( last_core_l == ACELP_CORE || last_core_r == ACELP_CORE ) { sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; } @@ -643,7 +686,7 @@ void stereo_decoder_tcx_fx( move32(); } } - inverseMS_fx( sfbConf->sfbOffset[sfbConf->sfbCnt] - sfbConf->sfbOffset[sfbConf->nBandsStereoCore], &spec_l[k][sfbConf->sfbOffset[sfbConf->nBandsStereoCore]], &spec_r[k][sfbConf->sfbOffset[sfbConf->nBandsStereoCore]], SQRT2_OVER_2_FIXED ); + inverseMS_fx( sub( sfbConf->sfbOffset[sfbConf->sfbCnt], sfbConf->sfbOffset[sfbConf->nBandsStereoCore] ), &spec_l[k][sfbConf->sfbOffset[sfbConf->nBandsStereoCore]], &spec_r[k][sfbConf->sfbOffset[sfbConf->nBandsStereoCore]], SQRT2_OVER_2_FIXED ); *q_x_ch2 = *q_x_ch2; move16(); *q_x_ch1 = *q_x_ch1; @@ -692,9 +735,33 @@ void stereo_decoder_tcx_fx( move16(); } + Word16 tmp1, tmp2 = 0; + + IF( EQ_16( core_r, TCX_10_CORE ) ) + { + tmp1 = NB_DIV; + move16(); + } + ELSE + { + tmp1 = 1; + move16(); + } + + IF( EQ_16( core_l, TCX_10_CORE ) ) + { + tmp2 = NB_DIV; + move16(); + } + ELSE + { + tmp2 = 1; + move16(); + } + test(); test(); - IF( ( GT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, ( ( EQ_16( core_r, TCX_10_CORE ) ) ? NB_DIV : 1 ) ) ) ) + IF( ( GT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, tmp1 ) ) ) { shift = norm_l( nrgRatio ); nrgRatio = L_shl( nrgRatio, shift ); @@ -703,11 +770,11 @@ void stereo_decoder_tcx_fx( *q_x_ch2 = *q_x_ch2; move16(); } - ELSE IF( ( LT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, ( ( EQ_16( core_l, TCX_10_CORE ) ) ? NB_DIV : 1 ) ) ) ) + ELSE IF( ( LT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, tmp2 ) ) ) { tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q26, nrgRatio, &tmp_e ); inv_nrgRatio = L_deposit_h( tmp ); - shift = 5 - tmp_e; + shift = sub( 5, tmp_e ); v_multc_fixed( spec_l[k], inv_nrgRatio, spec_l[k], L_frameTCX_l ); Scale_sig32( spec_l[k], L_frameTCX_l, sub( 5, shift ) ); *q_x_ch1 = *q_x_ch1; @@ -891,7 +958,7 @@ ivas_error initMdctStereoDtxData_fx( IF( st->hFdCngDec == NULL ) { /* Create FD_CNG instance */ - IF( ( error = createFdCngDec_fx( &st->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = createFdCngDec_fx( &st->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } @@ -903,18 +970,20 @@ ivas_error initMdctStereoDtxData_fx( initFdCngDec_ivas_fx( st, st->cldfbSyn->scale ); } - IF( EQ_16( st->first_CNG, 0 ) ) + IF( st->first_CNG == 0 ) { + test(); IF( EQ_16( ch, 1 ) && st->cng_sba_flag ) { st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); + move16(); } } IF( st->cldfbAna == NULL ) { /* open analysis for max. sampling rate 48kHz */ - IF( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -923,7 +992,7 @@ ivas_error initMdctStereoDtxData_fx( IF( st->cldfbBPF == NULL ) { /* open analysis BPF for max. internal sampling rate 16kHz */ - IF( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -1036,7 +1105,7 @@ void synchonize_channels_mdct_sid_fx( } } - IF( EQ_16( sts[0]->first_CNG, 0 ) ) + IF( sts[0]->first_CNG == 0 ) { /* configure CNG after reading first side info from SID to get correct values for L_frame and bwidth if first SID is also first valid frame */ configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->element_brate, st->L_frame, st->last_L_frame, st->element_mode ); @@ -1100,35 +1169,41 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ) { Word16 diff = 0; - if ( *a_exp > *b_exp ) + move16(); + IF( GT_16( *a_exp, *b_exp ) ) { - diff = *a_exp - *b_exp; - for ( int j = 0; j < legth; j++ ) + diff = sub( *a_exp, *b_exp ); + FOR( Word16 j = 0; j < legth; j++ ) { buff_b[j] = shr( buff_b[j], diff ); + move16(); } *b_exp = *a_exp; + move16(); } - else if ( *a_exp < *b_exp ) + ELSE IF( LT_16( *a_exp, *b_exp ) ) { - diff = *b_exp - *a_exp; + diff = sub( *b_exp, *a_exp ); - for ( int j = 0; j < legth; j++ ) + FOR( Word16 j = 0; j < legth; j++ ) { buff_a[j] = shr( buff_a[j], diff ); + move16(); } *a_exp = *b_exp; + move16(); } return; } -static Word16 norm_arr( Word16 *arr, int size ) +static Word16 norm_arr( Word16 *arr, Word32 size ) { Word16 q = 15; - for ( int i = 0; i < size; i++ ) - if ( arr[i] != 0 ) - { - q = min( q, norm_s( arr[i] ) ); - } + move16(); + FOR( Word32 i = 0; i < size; i++ ) + IF( arr[i] != 0 ) + { + q = s_min( q, norm_s( arr[i] ) ); + } return q; } void updateBuffersForDmxMdctStereo_fx( @@ -1153,36 +1228,49 @@ void updateBuffersForDmxMdctStereo_fx( } Word32 Var1 = 0; + move16(); Word16 diff_sidNoiseEst = 0; + move16(); Word16 exp_sidNoiseEst0 = sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp; + move16(); Word16 exp_sidNoiseEst1 = sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp; - if ( exp_sidNoiseEst0 > exp_sidNoiseEst1 ) + move16(); + IF( GT_16( exp_sidNoiseEst0, exp_sidNoiseEst1 ) ) { - diff_sidNoiseEst = exp_sidNoiseEst0 - exp_sidNoiseEst1; - for ( int j = 0; j < NPART; j++ ) + diff_sidNoiseEst = sub( exp_sidNoiseEst0, exp_sidNoiseEst1 ); + FOR( Word32 j = 0; j < NPART; j++ ) { sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); + move16(); } exp_sidNoiseEst1 = exp_sidNoiseEst0; + move16(); } - else if ( exp_sidNoiseEst0 < exp_sidNoiseEst1 ) + ELSE IF( LT_16( exp_sidNoiseEst0, exp_sidNoiseEst1 ) ) { - diff_sidNoiseEst = exp_sidNoiseEst1 - exp_sidNoiseEst0; - for ( int j = 0; j < NPART; j++ ) + diff_sidNoiseEst = sub( exp_sidNoiseEst1, exp_sidNoiseEst0 ); + FOR( Word32 j = 0; j < NPART; j++ ) { sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); + move16(); } exp_sidNoiseEst0 = exp_sidNoiseEst1; + move16(); } sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = exp_sidNoiseEst0; + move16(); sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp = exp_sidNoiseEst1; + move16(); + test(); + test(); IF( EQ_32( hCPE->element_brate, IVAS_SID_5k2 ) && GT_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { /* in the first SID frame after an active frame, create mid noise shape here, in SID frames that follow inactive frames, it is done directly in the SID decoding since the mid shape is being used in CNG then */ FOR( int16_t p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ ) { - Var1 = L_add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] >> 1, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] >> 1 ); // exp_sidNoiseEst0 - 1 - sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = Mpy_32_32( float_to_fix( 0.5f, 31 ), Var1 ); // 31 - exp_sidNoiseEst0 - 1 + 31 - 31 + Var1 = L_add( L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ), L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p], 1 ) ); // exp_sidNoiseEst0 - 1 + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = Mpy_32_32( ONE_IN_Q30, Var1 ); // 31 - exp_sidNoiseEst0 - 1 + 31 - 31 + move32(); } } @@ -1190,25 +1278,34 @@ void updateBuffersForDmxMdctStereo_fx( IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { delta = 1; + move16(); IF( EQ_16( output_frame, L_FRAME16k ) ) { delta = 2; + move16(); } ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { delta = 4; + move16(); } ELSE IF( EQ_16( output_frame, L_FRAME48k ) ) { delta = 6; + move16(); } delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); tcxltp_mem_in_len = NS2SA_fx2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); + move16(); assert( delay_buf_out_len > tcxltp_mem_in_len ); Word16 sum_tcx_ltp = 0, sum_delay_buf = 0, sum_tcx_ltp_out = 0, sum_old_out = 0; + move16(); + move16(); + move16(); + move16(); Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); @@ -1216,11 +1313,15 @@ void updateBuffersForDmxMdctStereo_fx( Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = 15 - norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ); - sts[1]->hTcxLtpDec->exp_tcxltp_mem_in = 15 - norm_arr( sts[1]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ); + sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = sub( 15, norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ) ); + move16(); + sts[1]->hTcxLtpDec->exp_tcxltp_mem_in = sub( 15, norm_arr( sts[1]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ) ); + move16(); - sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = 15 - norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k ); - sts[1]->hTcxLtpDec->exp_tcxltp_mem_out = 15 - norm_arr( sts[1]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k ); + sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = sub( 15, norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k ) ); + move16(); + sts[1]->hTcxLtpDec->exp_tcxltp_mem_out = sub( 15, norm_arr( sts[1]->hTcxLtpDec->tcxltp_mem_out, L_FRAME48k ) ); + move16(); Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ); @@ -1243,15 +1344,19 @@ void updateBuffersForDmxMdctStereo_fx( { sum_tcx_ltp = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_in[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_in[i], 1 ) ); // exp_tcxltp_mem_in + 1 sts[0]->hTcxLtpDec->tcxltp_mem_in[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp ); // 14 - exp_tcxltp_mem_in - 1 + move16(); sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // exp_delay_buf_sum + move16(); sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out_sum + move16(); sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm + move16(); } @@ -1259,25 +1364,33 @@ void updateBuffersForDmxMdctStereo_fx( { sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // exp_delay_buf_sum + move16(); sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); + move16(); sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcs_ltp_out_sm + move16(); } FOR( ; i < output_frame; i++ ) { sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out_sum + move16(); sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // 15 + exp_tcs_ltp_out_sm - 15 + move16(); } sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, 1 ); + move16(); sts[0]->hHQ_core->exp_old_out = add( sts[0]->hHQ_core->exp_old_out, 1 ); + move16(); sts[0]->hTcxLtpDec->exp_tcxltp_mem_out = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, 1 ); + move16(); Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ) ); Copy_Scale_sig_16_32( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], TCXLTP_MAX_DELAY, sub( 11, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ) ); @@ -1445,6 +1558,7 @@ void applyDmxMdctStereo_fx( IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + move16(); SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: @@ -1491,6 +1605,7 @@ void applyDmxMdctStereo_fx( ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->last_element_brate, IVAS_32k ) ) { crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); + move16(); SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 514d5c520c8f8bb98b2d22e507a7343309bd3d6b..232675e4b135df9fd26c1a6c402f53e1f4cb7f4a 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -384,7 +384,7 @@ static ivas_error allocate_CoreCoder_fx( IF( st->cldfbAna == NULL ) { /* open analysis for max. sampling rate 48kHz */ - IF( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -393,7 +393,7 @@ static ivas_error allocate_CoreCoder_fx( IF( st->cldfbBPF == NULL ) { /* open analysis BPF for max. internal sampling rate 16kHz */ - IF( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -590,12 +590,12 @@ static void cpy_tcx_ltp_data_fx( move16(); /* (int16_t) ( ( TCXLTP_MAX_DELAY * output_Fs ) / 48000 ) */ sz = extract_l( Mpy_32_32_r( TCXLTP_MAX_DELAY * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - mvs2s( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later - mvl2l( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); + Copy( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later + Copy32( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); /* (int16_t) ( ( L_FRAME48k * output_Fs ) / 48000 ) */ sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - mvs2s( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later - mvl2l( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); + Copy( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later + Copy32( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); return; } @@ -1296,6 +1296,8 @@ ivas_error stereo_memory_dec_fx( *---------------------------------------------------------------*/ /* handling of DFT->TD switching */ + test(); + test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) { delay_comp_DFT = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); @@ -1308,20 +1310,22 @@ ivas_error stereo_memory_dec_fx( { div_m = BASOP_Util_Divide3216_Scale( hCPE->output_mem_fx[n][sub( i, delay_comp_DFT )], hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( add( sub( hCPE->hStereoDft->dft32ms_ovl, 1 ), delay_comp_DFT ), i ) ) )], &div_e ); hCPE->output_mem_fx[n][sub( i, delay_comp_DFT )] = L_shl( div_m, add( div_e, 16 ) ); + move32(); // hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)] = hCPE->hStereoDft->win32ms_fx[i_mult(STEREO_DFT32MS_STEP, ( sub(add(sub(hCPE->hStereoDft->dft32ms_ovl, 1), delay_comp_DFT), i) ))]; } } - IF( NE_16( hCPE->hCoreCoder[0]->last_core, ACELP_CORE ) ) + IF( hCPE->hCoreCoder[0]->last_core != ACELP_CORE ) { - mvl2l( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); } } + test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); - v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); @@ -1356,7 +1360,7 @@ ivas_error stereo_memory_dec_fx( deallocate_CoreCoder_fx( hCPE->hCoreCoder[1] ); /* allocate DFT stereo data structure */ - IF( NE_16( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, 0, nchan_transport ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, 0, nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } @@ -1368,7 +1372,7 @@ ivas_error stereo_memory_dec_fx( } /* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */ - mvl2l( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, 16000 ), STEREO_DFT32MS_OVL_NS ) ); + Copy32( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( i_mult( hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC ), 16000 ), STEREO_DFT32MS_OVL_NS ) ); /* allocate ICBWE structure */ IF( hCPE->hStereoICBWE == NULL ) @@ -1449,7 +1453,7 @@ ivas_error stereo_memory_dec_fx( stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); /* allocate CoreCoder secondary channel */ - IF( NE_16( ( error = allocate_CoreCoder_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = allocate_CoreCoder_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -1459,6 +1463,8 @@ ivas_error stereo_memory_dec_fx( * allocate DFT/TD stereo structures after MDCT stereo frame *---------------------------------------------------------------*/ + test(); + test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) ) { /* deallocated TCX-LTP for second channel */ @@ -1473,11 +1479,11 @@ ivas_error stereo_memory_dec_fx( { /* re-use an existing buffer for MDCT->TD stereo switching */ Word16 nZeros, len; - nZeros = (Word16) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + nZeros = extract_l( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); move16(); len = NS2SA( st->output_Fs, 3000000 ); move16(); - mvl2l( st->hHQ_core->oldOut_fx + nZeros, hCPE->output_mem_fx[1], len ); + Copy32( st->hHQ_core->oldOut_fx + nZeros, hCPE->output_mem_fx[1], len ); } /* deallocated HQ-core for second channel */ @@ -1488,6 +1494,7 @@ ivas_error stereo_memory_dec_fx( } /* allocate DFT stereo mono DMX data structure */ + test(); IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDftDmx == NULL ) { IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) @@ -1499,6 +1506,7 @@ ivas_error stereo_memory_dec_fx( } /* allocate TCA data structure */ + test(); IF( NE_16( hCPE->nchan_out, 1 ) && hCPE->hStereoTCA == NULL ) { IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) @@ -1512,7 +1520,7 @@ ivas_error stereo_memory_dec_fx( st = hCPE->hCoreCoder[0]; /* allocate primary channel substructures */ - IF( NE_16( ( error = allocate_CoreCoder_fx( st ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = allocate_CoreCoder_fx( st ) ), IVAS_ERR_OK ) ) { return error; } @@ -1528,9 +1536,13 @@ ivas_error stereo_memory_dec_fx( td_bwe_dec_init_ivas_fx( st, st->hBWE_TD, st->output_Fs ); st->prev_Q_bwe_exc = 31; + move16(); st->prev_Qx = 0; + move16(); st->prev_ener_fx_Q = 31; + move16(); st->prev_frame_pow_exp = 0; + move16(); IF( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -1549,15 +1561,18 @@ ivas_error stereo_memory_dec_fx( #endif fd_bwe_dec_init( st, st->hBWE_FD ); st->hBWE_FD->old_wtda_swb_fx_exp = 0; + move16(); st->hBWE_FD->mem_imdct_exp_fx = 0; + move16(); st->prev_Q_synth = 0; + move16(); } /* Allocated FD_CNG instance for primary channel*/ IF( st->hFdCngDec == NULL ) { /* Create FD_CNG instance */ - IF( ( error = createFdCngDec_fx( &st->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = createFdCngDec_fx( &st->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } @@ -1589,7 +1604,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - mvl2l( hCPE->hStereoTD->TCX_old_syn_Overl_fx, tmpF_buff, L_FRAME16k / 2 ); + Copy32( hCPE->hStereoTD->TCX_old_syn_Overl_fx, tmpF_buff, L_FRAME16k / 2 ); } IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) @@ -1647,7 +1662,7 @@ ivas_error stereo_memory_dec_fx( IF( st->cldfbAna == NULL ) { - IF( NE_16( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -1656,14 +1671,14 @@ ivas_error stereo_memory_dec_fx( IF( st->cldfbBPF == NULL ) { /* open analysis BPF for max. internal sampling rate 16kHz */ - IF( NE_16( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } } /* allocate Fd-Cng structure for second channel */ - IF( NE_16( ( error = createFdCngDec_fx( &st->hFdCngDec ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = createFdCngDec_fx( &st->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } @@ -1674,13 +1689,14 @@ ivas_error stereo_memory_dec_fx( initFdCngDec( st ); #endif - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) + if ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() */ + move16(); } /*Allocate CoreCoder TCX modules for second channel */ - IF( NE_16( ( error = allocate_CoreCoder_TCX_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = allocate_CoreCoder_TCX_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK ) ) { return error; } @@ -1699,7 +1715,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - mvl2l( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); + Copy32( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); Copy_Scale_sig32_16( st->hTcxDec->old_syn_Overl_32, st->hTcxDec->old_syn_Overl, L_FRAME16k / 2, add( st->Q_syn, 5 ) ); //(st->Qsyn - (11 - 16)) } @@ -1742,12 +1758,13 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - IF( EQ_16( hCPE->hCoreCoder[0]->bfi, 0 ) ) + IF( hCPE->hCoreCoder[0]->bfi == 0 ) { st = hCPE->hCoreCoder[1]; - hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate + hCPE->brate_surplus, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + ( hCPE->brate_surplus / FRAMES_PER_SEC ) - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); + hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], L_add( hCPE->element_brate, hCPE->brate_surplus ), ( sub( add( sub( extract_l( Mpy_32_16_1( hCPE->element_brate, INV_FRAME_PER_SEC_Q15 ) ), nb_bits_metadata ), extract_l( Mpy_32_16_1( hCPE->brate_surplus, INV_FRAME_PER_SEC_Q15 ) ) ), ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS ) ) ), TDM_LR_CONTENT_BITS ); + move16(); - IF( NE_16( hCPE->hStereoTD->tdm_LRTD_flag, 0 ) ) + IF( hCPE->hStereoTD->tdm_LRTD_flag != 0 ) { /* deallocate ICBWE structure */ IF( hCPE->hStereoICBWE != NULL ) @@ -1767,9 +1784,13 @@ ivas_error stereo_memory_dec_fx( td_bwe_dec_init_ivas_fx( st, st->hBWE_TD, st->output_Fs ); st->prev_Q_bwe_exc = 31; + move16(); st->prev_Qx = 0; + move16(); st->prev_ener_fx_Q = 31; + move16(); st->prev_frame_pow_exp = 0; + move16(); IF( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { @@ -1788,8 +1809,11 @@ ivas_error stereo_memory_dec_fx( #endif fd_bwe_dec_init( st, st->hBWE_FD ); st->hBWE_FD->old_wtda_swb_fx_exp = 0; + move16(); st->hBWE_FD->mem_imdct_exp_fx = 0; + move16(); st->prev_Q_synth = 0; + move16(); } } ELSE /* tdm_LRTD_flag == 0 */ @@ -1828,11 +1852,13 @@ ivas_error stereo_memory_dec_fx( * MDCT stereo bitrate switching *---------------------------------------------------------------*/ + test(); IF( EQ_16( ivas_format, STEREO_FORMAT ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { + test(); IF( LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - IF( EQ_16( hCPE->hStereoMdct->use_itd, 0 ) ) + IF( hCPE->hStereoMdct->use_itd == 0 ) { IF( hCPE->hStereoTCA == NULL ) { @@ -1852,14 +1878,17 @@ ivas_error stereo_memory_dec_fx( ELSE { /* de-allocate TCA data structure */ - IF( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_5k2 && hCPE->hStereoTCA != NULL ) + test(); + test(); + test(); + IF( EQ_16( hCPE->hStereoMdct->use_itd, 1 ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) && hCPE->hStereoTCA != NULL ) { free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; hCPE->hStereoMdct->use_itd = 0; move16(); } - ELSE IF( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_5k2 ) + ELSE IF( EQ_16( hCPE->hStereoMdct->use_itd, 1 ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { hCPE->hStereoMdct->itd_fx = 0; move32(); @@ -1876,6 +1905,8 @@ ivas_error stereo_memory_dec_fx( * Bitrate switching in MASA format *---------------------------------------------------------------*/ + test(); + test(); IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( nchan_transport, 2 ) ) { IF( EQ_16( hCPE->nchan_out, 1 ) ) @@ -1962,8 +1993,10 @@ ivas_error stereo_memory_dec_fx( * Bitrate switching in MASA format *---------------------------------------------------------------*/ + test(); IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { + test(); IF( EQ_16( mc_mode, MC_MODE_MCT ) || EQ_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { /* deallocate the FdCNG handle */ @@ -1979,7 +2012,7 @@ ivas_error stereo_memory_dec_fx( { IF( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ { - IF( NE_16( ( error = openCldfb_ivas_fx( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = openCldfb_ivas_fx( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -1987,7 +2020,7 @@ ivas_error stereo_memory_dec_fx( IF( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) { - IF( NE_16( ( error = createFdCngDec_fx( &hCPE->hCoreCoder[i]->hFdCngDec ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = createFdCngDec_fx( &hCPE->hCoreCoder[i]->hFdCngDec ) ), IVAS_ERR_OK ) ) { return error; } @@ -2388,34 +2421,55 @@ void synchro_synthesis_fx( Word16 dft_mono_brate_switch; Word16 delay_diff; Word32 tmpF_fx = 0; + move32(); Word16 nChannels; sts = hCPE->hCoreCoder; output_Fs = sts[0]->output_Fs; use_cldfb_for_last_dft = 0; - IF( ( hCPE->element_mode != IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) /* note: this is to mimic the DFT stereo condition "hCPE->hStereoDft->hConfig->res_cod_mode == 0" in last frame */ - || ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) + move16(); + + test(); + test(); + test(); + test(); + test(); + if ( ( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && LE_32( hCPE->last_element_brate, IVAS_24k4 ) ) /* note: this is to mimic the DFT stereo condition "hCPE->hStereoDft->hConfig->res_cod_mode == 0" in last frame */ + || ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { use_cldfb_for_last_dft = 1; + move16(); } dft_mono_brate_switch = 0; - IF( hCPE->element_mode == IVAS_CPE_DFT && ( hCPE->last_element_mode == IVAS_CPE_DFT || hCPE->last_element_mode == IVAS_CPE_MDCT ) && hCPE->nchan_out == 1 && hCPE->element_brate != hCPE->last_element_brate ) + move16(); + test(); + test(); + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) && EQ_16( hCPE->nchan_out, 1 ) && NE_32( hCPE->element_brate, hCPE->last_element_brate ) ) { - IF( hCPE->last_element_brate >= IVAS_32k && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + test(); + test(); + IF( GE_32( hCPE->last_element_brate, IVAS_32k ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo */ + move16(); } - ELSE IF( hCPE->last_element_brate <= IVAS_24k4 && hCPE->hStereoDft->hConfig->res_cod_mode > STEREO_DFT_RES_COD_OFF ) + ELSE IF( LE_32( hCPE->last_element_brate, IVAS_24k4 ) && GT_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { dft_mono_brate_switch = 1; /* switch to residual coding mode*/ + move16(); } } IF( use_cldfb_for_last_dft ) { - IF( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_5k2 || hCPE->nchan_out == 2 ) ) + test(); + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_16( hCPE->nchan_out, 2 ) ) ) { stereo_tca_scale_R_channel_fx( hCPE, output_fx[0], output_frame ); } @@ -2423,14 +2477,18 @@ void synchro_synthesis_fx( /* set delays */ delay_comp_DFT = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); + move16(); delay_comp_TD = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); - delay_diff = delay_comp_TD - delay_comp_DFT; + move16(); + delay_diff = sub( delay_comp_TD, delay_comp_DFT ); - dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * output_Fs ) / 48000 ); + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); delay_cldfb = NS2SA( output_Fs, DELAY_CLDFB_NS ); + move16(); /* initialize pointers */ - IF( hCPE->element_mode >= IVAS_CPE_DFT && hCPE->output_mem_fx[0] != NULL ) + test(); + IF( GE_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->output_mem_fx[0] != NULL ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { @@ -2442,28 +2500,33 @@ void synchro_synthesis_fx( * DFT stereo synchro *----------------------------------------------------------------*/ - IF( hCPE->element_mode == IVAS_CPE_DFT || sba_dirac_stereo_flag ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || sba_dirac_stereo_flag ) { /* handling of bitrate switching from residual (using DFT) to non-residual mode (using CLDFB) FOR mono output - as in DFT->TD switching */ - IF( dft_mono_brate_switch == -1 ) + IF( EQ_16( dft_mono_brate_switch, -1 ) ) { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][i - delay_comp_DFT]; + sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][sub( i, delay_comp_DFT )]; + move32(); } - FOR( i = delay_comp_TD; i < delay_comp_TD + delay_cldfb; i++ ) + FOR( i = delay_comp_TD; i < add( delay_comp_TD, delay_cldfb ); i++ ) { - tmp_out_fx[0][i - delay_comp_TD] = p_output_mem_fx[0][i - delay_comp_DFT]; + tmp_out_fx[0][sub( i, delay_comp_TD )] = p_output_mem_fx[0][sub( i, delay_comp_DFT )]; + move32(); } } - IF( hCPE->nchan_out == 1 && hCPE->last_element_mode == IVAS_CPE_MDCT ) + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { FOR( Word32 ind = 0; ind < delay_comp_DFT; ind++ ) { - Word32 temp = sts[0]->prev_synth_buffer32_fx[ind] + sts[1]->prev_synth_buffer32_fx[ind]; + Word32 temp = L_add( sts[0]->prev_synth_buffer32_fx[ind], sts[1]->prev_synth_buffer32_fx[ind] ); sts[0]->prev_synth_buffer32_fx[ind] = Mpy_32_32( temp, INV_SQRT2_FX ); + move32(); } } @@ -2474,7 +2537,7 @@ void synchro_synthesis_fx( delay_signal_fx( output_fx[0], output_frame, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); } - IF( hCPE->element_mode != IVAS_CPE_MDCT ) + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { ivas_post_proc_fx( NULL, hCPE, 0, output_fx[0], output_fx, output_frame, sba_dirac_stereo_flag ); } @@ -2491,9 +2554,10 @@ void synchro_synthesis_fx( delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_DFT ); } } - IF( sba_dirac_stereo_flag ) + if ( sba_dirac_stereo_flag ) { hCPE->q_prev_synth_fx = hCPE->hStereoDft->q_dft; + move16(); } IF( use_cldfb_for_last_dft ) { @@ -2503,20 +2567,27 @@ void synchro_synthesis_fx( /* handling of TD->DFT switching */ FOR( n = 0; n < hCPE->nchan_out; n++ ) { - IF( ( hCPE->last_element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag && dft_mono_brate_switch != -1 ) || dft_mono_brate_switch == 1 ) + test(); + test(); + test(); + IF( ( NE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag && NE_16( dft_mono_brate_switch, -1 ) ) || EQ_16( dft_mono_brate_switch, 1 ) ) { Word32 *pPrev_synth_fx; Word32 inv_fade_len_fx = 0; + move32(); SWITCH( output_Fs ) { case 16000: inv_fade_len_fx = 71582792; + move32(); BREAK; case 32000: inv_fade_len_fx = 35791396; + move32(); BREAK; case 48000: inv_fade_len_fx = 23860930; + move32(); BREAK; default: assert( 0 ); @@ -2526,63 +2597,79 @@ void synchro_synthesis_fx( IF( sba_dirac_stereo_flag ) { pPrev_synth_fx = hCPE->prev_synth_fx[n]; + move32(); } ELSE { pPrev_synth_fx = sts[n]->prev_synth_buffer32_fx; + move32(); } - IF( hCPE->last_element_mode != IVAS_CPE_MDCT ) + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - Word64 res1 = (Word64) pPrev_synth_fx[i] * ( delay_comp_TD - i ); - Word64 res2 = (Word64) output_fx[n][i] * ( i - delay_comp_DFT ); - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); + Word64 res1 = W_mult0_32_32( pPrev_synth_fx[i], ( sub( delay_comp_TD, i ) ) ); + Word64 res2 = W_mult0_32_32( output_fx[n][i], ( sub( i, delay_comp_DFT ) ) ); + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); res = res * inv_fade_len_fx; - output_fx[n][i] = (Word32) W_shr( res, 31 - 6 ); + move64(); + output_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); + move32(); // change 6 to less number to get better precision } } } - ELSE IF( dft_mono_brate_switch == -1 ) + ELSE IF( EQ_16( dft_mono_brate_switch, -1 ) ) { Word32 inv_fade_len_1_fx = 0; + move32(); Word32 inv_fade_len_2_fx = 0; + move32(); SWITCH( output_Fs ) { case 16000: inv_fade_len_1_fx = 71582792; + move32(); inv_fade_len_2_fx = 107374184; + move32(); BREAK; case 32000: inv_fade_len_1_fx = 35791396; + move32(); inv_fade_len_2_fx = 53687092; + move32(); BREAK; case 48000: inv_fade_len_1_fx = 23860930; + move32(); inv_fade_len_2_fx = 35791396; + move32(); BREAK; default: assert( 0 ); } FOR( i = 0; i < delay_diff; i++ ) { - Word64 res1 = (Word64) output_fx[0][i + delay_comp_DFT] * ( delay_diff - i ); - Word64 res2 = (Word64) p_output_mem_fx[0][i] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); + Word64 res1 = W_mult0_32_32( output_fx[0][add( i, delay_comp_DFT )], ( sub( delay_diff, i ) ) ); + Word64 res2 = W_mult0_32_32( p_output_mem_fx[0][i], i ); + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); res = res * inv_fade_len_1_fx; - output_fx[0][i + delay_comp_DFT] = (Word32) W_shr( res, 31 - 6 ); + move64(); + output_fx[0][add( i, delay_comp_DFT )] = W_extract_l( W_shr( res, 31 - 6 ) ); + move32(); } FOR( i = 0; i < delay_cldfb; i++ ) { - Word64 res1 = (Word64) tmp_out_fx[0][i] * ( delay_cldfb - i ); - Word64 res2 = (Word64) output_fx[0][i + delay_comp_TD] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); + Word64 res1 = W_mult0_32_32( tmp_out_fx[0][i], ( sub( delay_cldfb, i ) ) ); + Word64 res2 = W_mult0_32_32( output_fx[0][add( i, delay_comp_TD )], i ); + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); res = res * inv_fade_len_2_fx; - output_fx[0][i + delay_comp_TD] = (Word32) W_shr( res, 31 - 6 ); + move64(); + output_fx[0][add( i, delay_comp_TD )] = W_extract_l( W_shr( res, 31 - 6 ) ); + move32(); } } } @@ -2597,28 +2684,35 @@ void synchro_synthesis_fx( return; } - IF( hCPE->element_mode == IVAS_CPE_TD || hCPE->element_mode == IVAS_CPE_MDCT ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { /* handling of DFT->TD switching */ - IF( hCPE->last_element_mode == IVAS_CPE_DFT && !use_cldfb_for_last_dft && hCPE->output_mem_fx[0] != NULL ) + test(); + test(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_last_dft && hCPE->output_mem_fx[0] != NULL ) { /* use redressed DFT stereo OLA part to reconstruct the TD stereo synchro memory */ FOR( n = 0; n < hCPE->nchan_out; n++ ) { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][i - delay_comp_DFT]; + sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][sub( i, delay_comp_DFT )]; + move32(); } - FOR( i = delay_comp_TD; i < delay_comp_TD + delay_cldfb; i++ ) + FOR( i = delay_comp_TD; i < add( delay_comp_TD, delay_cldfb ); i++ ) { - tmp_out_fx[n][i - delay_comp_TD] = p_output_mem_fx[n][i - delay_comp_DFT]; + tmp_out_fx[n][sub( i, delay_comp_TD )] = p_output_mem_fx[n][sub( i, delay_comp_DFT )]; + move32(); } } } /* IF previous frame had only one channel copy buffers to other channel */ - IF( hCPE->nchan_out == 1 && hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_DFT ) + test(); + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); Copy32( tmp_out_fx[0], tmp_out_fx[1], delay_cldfb ); @@ -2630,11 +2724,12 @@ void synchro_synthesis_fx( *----------------------------------------------------------------*/ /* resample LB synthesis to output_Fs */ - IF( hCPE->element_mode != IVAS_CPE_MDCT && !use_cldfb_for_last_dft ) + test(); + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !use_cldfb_for_last_dft ) { FOR( n = 0; n < hCPE->nchan_out; n++ ) { - IF( sts[n]->core == ACELP_CORE ) + IF( EQ_16( sts[n]->core, ACELP_CORE ) ) { L_lerp_fx_q11( hCPE->input_mem_LB_fx[n], tmp_out_TD_fx[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); } @@ -2645,12 +2740,13 @@ void synchro_synthesis_fx( /* use TCX synchro memory (perfect signal is available) */ FOR( i = delay_diff; i < dft32ms_ovl; i++ ) { - tmp_out_TD_fx[n][i] = sts[n]->delay_buf_out32_fx[i - delay_diff]; + tmp_out_TD_fx[n][i] = sts[n]->delay_buf_out32_fx[sub( i, delay_diff )]; + move32(); } } } - IF( hCPE->nchan_out == CPE_CHANNELS ) + IF( EQ_16( hCPE->nchan_out, CPE_CHANNELS ) ) { /* upmix the resampled LB / the TCX synchro memory */ tdm_upmix_plain_fx( tmp_out_TD2_fx[0], tmp_out_TD2_fx[1], tmp_out_TD_fx[0], tmp_out_TD_fx[1], tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx], tdm_den_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx], 0, dft32ms_ovl, 1 ); @@ -2668,12 +2764,15 @@ void synchro_synthesis_fx( { case 16000: tmpF_fx = 71582792; + move32(); BREAK; case 32000: tmpF_fx = 35791396; + move32(); BREAK; case 48000: tmpF_fx = 23860930; + move32(); BREAK; default: assert( 0 ); @@ -2682,11 +2781,12 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { - Word64 res1 = (Word64) output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i] * ( delay_diff - i ); - Word64 res2 = (Word64) tmp_out_TD2_fx[n][i] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); + Word64 res1 = W_mult0_32_32( output_fx[n][add( add( sub( output_frame, dft32ms_ovl ), delay_cldfb ), i )], ( sub( delay_diff, i ) ) ); + Word64 res2 = W_mult0_32_32( tmp_out_TD2_fx[n][i], i ); + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); res = res * tmpF_fx; - p_output_mem_fx[n][i] = (Word32) W_shr( res, 31 - 6 ); + move64(); + p_output_mem_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); } } ELSE /* TCX core */ @@ -2695,6 +2795,7 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { p_output_mem_fx[n][i] = output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i]; + move32(); } } @@ -2702,6 +2803,7 @@ void synchro_synthesis_fx( FOR( i = delay_diff; i < dft32ms_ovl; i++ ) { p_output_mem_fx[n][i] = tmp_out_TD2_fx[n][i]; + move32(); } } } @@ -2711,20 +2813,28 @@ void synchro_synthesis_fx( * the upmixed TD/MDCT stereo synthesis with the DFT stereo synthesis *----------------------------------------------------------------*/ - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->stereo_switching_counter == 0 && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) + test(); + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->stereo_switching_counter == 0 && EQ_16( hCPE->nchan_out, 1 ) && LE_32( hCPE->last_element_brate, IVAS_24k4 ) ) { Word32 step_fx = 0; + move32(); tmpF_fx = ONE_IN_Q31; + move32(); SWITCH( output_Fs ) { case 16000: step_fx = 33554432; + move32(); BREAK; case 32000: step_fx = 16777216; + move32(); BREAK; case 48000: step_fx = 11184811; + move32(); BREAK; default: assert( 0 ); @@ -2733,19 +2843,33 @@ void synchro_synthesis_fx( FOR( n = 0; n < delay_comp_TD; n++ ) { sts[0]->prev_synth_buffer32_fx[n] = Mpy_32_32( sts[0]->prev_synth_buffer32_fx[n], tmpF_fx ); + move32(); tmpF_fx = L_sub_sat( tmpF_fx, step_fx ); } } - IF( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->nchan_out == 1 && !is_DTXrate( hCPE->element_brate ) && is_DTXrate( hCPE->last_element_brate ) ) + test(); + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && !is_DTXrate( hCPE->element_brate ) && is_DTXrate( hCPE->last_element_brate ) ) { Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); } - nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out; + // nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out; + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) + { + nChannels = 2; + move16(); + } + ELSE + { + nChannels = hCPE->nchan_out; + move16(); + } FOR( n = 0; n < nChannels; n++ ) { - IF( hCPE->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { Copy32( sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); delay_signal_fx( output_fx[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); @@ -2761,9 +2885,11 @@ void synchro_synthesis_fx( } /* handling of DFT->TD switching */ - IF( hCPE->last_element_mode == IVAS_CPE_DFT && !use_cldfb_for_last_dft ) + test(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && !use_cldfb_for_last_dft ) { - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->hStereoCng->prev_sid_nodata ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng->prev_sid_nodata ) { FOR( n = 0; n < hCPE->nchan_out; n++ ) { @@ -2771,19 +2897,23 @@ void synchro_synthesis_fx( { case 16000: tmpF_fx = 107374184; + move32(); BREAK; case 32000: tmpF_fx = 53687092; + move32(); BREAK; case 48000: tmpF_fx = 35791396; + move32(); BREAK; default: assert( 0 ); } FOR( i = 0; i < delay_cldfb; i++ ) { - tmp_out_fx[n][i] = Mpy_32_32( tmp_out_fx[n][i], tmpF_fx ) * ( delay_cldfb - i ); + tmp_out_fx[n][i] = W_extract_l( W_mult0_32_32( Mpy_32_32( tmp_out_fx[n][i], tmpF_fx ), ( sub( delay_cldfb, i ) ) ) ); + move32(); } } } @@ -2791,18 +2921,21 @@ void synchro_synthesis_fx( /* cross-fading between DFT OLA memory and TD output */ FOR( n = 0; n < nChannels; n++ ) { - IF( hCPE->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { SWITCH( output_Fs ) { case 16000: tmpF_fx = 71582792; + move32(); BREAK; case 32000: tmpF_fx = 35791396; + move32(); BREAK; case 48000: tmpF_fx = 23860930; + move32(); BREAK; default: assert( 0 ); @@ -2810,34 +2943,41 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { - Word64 res1 = (Word64) output_fx[n][i + delay_comp_DFT] * ( delay_diff - i ); - Word64 res2 = (Word64) p_output_mem_fx[n][i] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); + Word64 res1 = W_mult0_32_32( output_fx[n][i + delay_comp_DFT], ( sub( delay_diff, i ) ) ); + Word64 res2 = W_mult0_32_32( p_output_mem_fx[n][i], i ); + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); res = res * tmpF_fx; - output_fx[n][i + delay_comp_DFT] = (Word32) W_shr( res, 31 - 6 ); + move64(); + output_fx[n][add( i, delay_comp_DFT )] = W_extract_l( W_shr( res, 31 - 6 ) ); + move32(); } } SWITCH( output_Fs ) { case 16000: tmpF_fx = 107374184; + move32(); BREAK; case 32000: tmpF_fx = 53687092; + move32(); BREAK; case 48000: tmpF_fx = 35791396; + move32(); BREAK; default: assert( 0 ); } FOR( i = 0; i < delay_cldfb; i++ ) { - Word64 res1 = (Word64) tmp_out_fx[n][i] * ( delay_cldfb - i ); - Word64 res2 = (Word64) output_fx[n][i + delay_comp_TD] * i; - Word64 res = W_shr( res1, 6 ) + W_shr( res2, 6 ); + Word64 res1 = W_mult0_32_32( tmp_out_fx[n][i], ( sub( delay_cldfb, i ) ) ); + Word64 res2 = W_mult0_32_32( output_fx[n][add( i, delay_comp_TD )], i ); + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); res = res * tmpF_fx; - output_fx[n][i + delay_comp_TD] = (Word32) W_shr( res, 31 - 6 ); + move64(); + output_fx[n][add( i, delay_comp_TD )] = W_extract_l( W_shr( res, 31 - 6 ) ); + move32(); } } } @@ -2902,66 +3042,83 @@ void stereo_switching_dec( sts = hCPE->hCoreCoder; delay_comp_TD = NS2SA( sts[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + move16(); /* prevent CPE mode switching in the first received frame */ IF( sts[0]->ini_frame == 0 ) { hCPE->last_element_mode = hCPE->element_mode; + move16(); hCPE->stereo_switching_counter = 10; + move16(); hCPE->NbFrameMod = 7; + move16(); hCPE->lt_es_em_fx = 0; + move16(); } - IF( hCPE->element_mode == hCPE->last_element_mode ) + IF( EQ_16( hCPE->element_mode, hCPE->last_element_mode ) ) { - hCPE->stereo_switching_counter++; - hCPE->stereo_switching_counter = min( 10, hCPE->stereo_switching_counter ); + hCPE->stereo_switching_counter = add( hCPE->stereo_switching_counter, 1 ); + hCPE->stereo_switching_counter = s_min( 10, hCPE->stereo_switching_counter ); } ELSE { hCPE->stereo_switching_counter = 0; + move16(); } - IF( hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->element_brate >= IVAS_32k && hCPE->last_element_brate <= IVAS_24k4 ) + test(); + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && GE_32( hCPE->element_brate, IVAS_32k ) && LE_32( hCPE->last_element_brate, IVAS_24k4 ) ) { - dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs ) / 48000 ); + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) set32_fx( hCPE->output_mem_fx[0], 0, dft32ms_ovl ); } - IF( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode != IVAS_CPE_DFT && hCPE->hCoreCoder[0]->ini_frame > 0 ) + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && hCPE->hCoreCoder[0]->ini_frame > 0 ) { /* windowing the OLA memory */ - dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs ) / 48000 ); + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF( hCPE->last_element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { /* copy memories from previous MDCT Stereo frame to output_mem */ Copy32( hCPE->input_mem_fx[n], hCPE->output_mem_fx[n], dft32ms_ovl ); } - IF( ivas_total_brate > IVAS_SID_5k2 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1 ) + test(); + test(); + test(); + IF( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || n == 0 || EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->nchan_out, 1 ) ) { FOR( i = 0; i < dft32ms_ovl; i++ ) { - hCPE->output_mem_fx[n][i] = Mpy_32_16_1( hCPE->output_mem_fx[n][i], hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); + hCPE->output_mem_fx[n][i] = Mpy_32_16_1( hCPE->output_mem_fx[n][i], hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, ( sub( sub( dft32ms_ovl, 1 ), i ) ) )] ); + move32(); } } ELSE { - IF( hCPE->hStereoTCA->prevTargetGain_fx == ONE_IN_Q29 ) + IF( EQ_32( hCPE->hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ) ) { tmpF_fx = ONE_IN_Q27; + move32(); } ELSE { - Word16 temp_b = (Word16) L_shr( hCPE->hStereoTCA->prevTargetGain_fx, 16 ); + Word16 temp_b = extract_l( L_shr( hCPE->hStereoTCA->prevTargetGain_fx, 16 ) ); Word16 temp_b_q = 2; + move16(); tmpF_fx = Inv16( temp_b, &temp_b_q ); - tmpF_fx = L_shl( tmpF_fx, ( 31 - 4 ) - ( 15 - temp_b_q ) ); + tmpF_fx = L_shl( tmpF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); } FOR( i = 0; i < dft32ms_ovl; i++ ) { - Word32 temp_result = Mpy_32_16_1( tmpF_fx, hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); + Word32 temp_result = Mpy_32_16_1( tmpF_fx, hCPE->hStereoDft->win32ms_fx[i_mult( STEREO_DFT32MS_STEP, sub( dft32ms_ovl, 1 + i ) )] ); hCPE->output_mem_fx[n][i] = L_shl_sat( Mpy_32_32( hCPE->output_mem_fx[n][i], temp_result ), 4 ); } FOR( i = 0; i < delay_comp_TD; i++ ) @@ -2971,48 +3128,55 @@ void stereo_switching_dec( // temp_result = (Word64) hCPE->hCoreCoder[1]->prev_synth_buffer_fx[i] * tmpF_fx; // hCPE->hCoreCoder[1]->prev_synth_buffer_fx[i] = saturate( W_extract_l(W_shr( temp_result, 27 )) ); // 32bit buffer - temp_result = (Word64) hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] * tmpF_fx; + temp_result = W_mult0_32_32( hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i], tmpF_fx ); hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] = W_sat_l( W_shr( temp_result, 27 ) ); + move32(); } FOR( i = 0; i < L_DEC_MEM_LEN_ICA; i++ ) { hCPE->hStereoTCA->memChanR_fx[i] = L_shl_sat( Mpy_32_32( hCPE->hStereoTCA->memChanR_fx[i], tmpF_fx ), 4 ); + move32(); } } } - IF( hCPE->last_element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { /* create passive downmix of MDCT Stereo memories FOR DFT input memory */ - FOR( int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { Word32 result_int = L_add_sat( hCPE->input_mem_LB_fx[0][ind], hCPE->input_mem_LB_fx[1][ind] ); hCPE->input_mem_LB_fx[0][ind] = L_shr( result_int, 1 ); + move32(); } - FOR( int ind = 0; ind < dft32ms_ovl; ind++ ) + FOR( Word32 ind = 0; ind < dft32ms_ovl; ind++ ) { Word32 result_int = L_add_sat( hCPE->input_mem_fx[0][ind], hCPE->input_mem_fx[1][ind] ); hCPE->input_mem_fx[0][ind] = L_shr( result_int, 1 ); + move32(); } - IF( hCPE->nchan_out == 1 ) + IF( EQ_16( hCPE->nchan_out, 1 ) ) { - FOR( int ind = 0; ind < dft32ms_ovl; ind++ ) + FOR( Word32 ind = 0; ind < dft32ms_ovl; ind++ ) { Word32 result_int = L_add_sat( hCPE->output_mem_fx[0][ind], hCPE->output_mem_fx[1][ind] ); hCPE->output_mem_fx[0][ind] = Mpy_32_32( result_int, INV_SQRT_2_Q31 ); + move32(); } } } /* Update the side_gain[] parameters */ - IF( hCPE->last_element_mode != IVAS_CPE_MDCT ) + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { tmpF_fx = 0; - IF( hCPE->hStereoTCA != NULL ) + move32(); + if ( hCPE->hStereoTCA != NULL ) { tmpF_fx = side_gain_table[hCPE->hStereoTCA->indx_ica_gD]; + move32(); } set32_fx( hCPE->hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX, tmpF_fx, STEREO_DFT_BAND_MAX ); } @@ -3020,27 +3184,37 @@ void stereo_switching_dec( /* reset residual coding / ESF (secondary channel) */ set32_fx( hCPE->hStereoDft->res_cod_mem_fx, 0, STEREO_DFT_OVL_8k ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; + move16(); set32_fx( hCPE->input_mem_fx[1], 0, NS2SA( sts[0]->output_Fs, STEREO_DFT32MS_OVL_NS ) ); } - IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode != IVAS_CPE_TD && hCPE->hCoreCoder[0]->ini_frame > 0 ) + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->ini_frame > 0 ) { hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + move16(); hCPE->hStereoTD->tdm_last_SM_flag = 0; + move16(); hCPE->hStereoTD->tdm_prev_last_SM_flag = 0; + move16(); /* First frame after DFT frame AND the content is uncorrelated or xtalk -> the primary channel is forced to left */ - IF( hCPE->hStereoTD->tdm_LRTD_flag == 1 ) + if ( EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) ) { hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + move16(); } } /* no secondary channel in the previous frame -> memory resets */ - IF( hCPE->element_mode > IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_DFT ) + test(); + test(); + IF( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - IF( hCPE->last_element_brate <= IVAS_SID_5k2 && hCPE->nchan_out == 2 ) + test(); + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) && EQ_16( hCPE->nchan_out, 2 ) ) { /* reset CLDFB memories */ #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED @@ -3055,6 +3229,7 @@ void stereo_switching_dec( // sts[0]->mem_deemph = 0; sts[0]->mem_deemph_fx = 0; + move16(); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED // sts[0]->tilt_code = 0.0f; @@ -3062,7 +3237,9 @@ void stereo_switching_dec( #endif sts[0]->tilt_code_fx = 0; + move16(); sts[0]->gc_threshold_fx = 0; + move16(); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED // set_f( sts[0]->mem_syn1, 0, M ); @@ -3077,6 +3254,7 @@ void stereo_switching_dec( set16_fx( sts[0]->mem_syn_r, 0, L_SYN_MEM ); sts[1]->last_L_frame = sts[0]->last_L_frame; + move16(); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED /* reset PCh memories */ @@ -3090,8 +3268,10 @@ void stereo_switching_dec( set16_fx( sts[0]->lsp_old_fx, 0, M ); } sts[1]->last_extl = -1; + move16(); sts[1]->prev_bfi = sts[0]->prev_bfi; + move16(); #ifndef IVAS_FLOAT_FIXED set_f( sts[1]->old_pitch_buf, (float) L_SUBFR, 2 * NB_SUBFR16k ); @@ -3101,6 +3281,7 @@ void stereo_switching_dec( // fix need to do correctly set32_fx( sts[1]->old_pitch_buf_fx, L_deposit_h( L_SUBFR ), 2 * NB_SUBFR16k ); sts[1]->old_fpitchFB = 2 * L_SUBFR; + move32(); /* reset CLDFB memories */ #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED @@ -3115,13 +3296,16 @@ void stereo_switching_dec( // sts[1]->mem_deemph = 0; sts[1]->mem_deemph_fx = 0; + move16(); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED // sts[1]->tilt_code = 0.0f; // sts[1]->gc_threshold = 0.0f; #endif sts[1]->tilt_code_fx = 0; + move16(); sts[1]->gc_threshold_fx = 0; + move16(); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED // set_f( sts[1]->mem_syn1, 0, M ); @@ -3136,14 +3320,17 @@ void stereo_switching_dec( set16_fx( sts[1]->mem_syn_r, 0, L_SYN_MEM ); sts[1]->last_L_frame = sts[0]->last_L_frame; + move16(); Copy_Scale_sig( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC, sub( sts[1]->Q_exc, sts[0]->Q_exc ) ); Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); - IF( hCPE->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { sts[1]->last_core = sts[0]->last_core; + move16(); sts[1]->last_coder_type = sts[0]->last_coder_type; + move16(); #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED // mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); @@ -3163,7 +3350,7 @@ void stereo_switching_dec( Copy( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); } } - ELSE IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED // set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); @@ -3174,19 +3361,27 @@ void stereo_switching_dec( } /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ - IF( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode != IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; + move16(); sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; + move16(); sts[1]->fscale = sts[0]->fscale; + move16(); sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; + move16(); sts[1]->pit_res_max = sts[0]->pit_res_max; + move16(); sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; + move16(); sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; + move16(); #ifndef IVAS_FLOAT_FIXED sts[1]->hTcxDec->conceal_eof_gain_float = sts[0]->hTcxDec->conceal_eof_gain_float; #endif sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; + move16(); } return; @@ -3548,11 +3743,16 @@ void stereo_td2dft_update_fx( /* initialization */ sts = hCPE->hCoreCoder; - ovl = NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); - dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs ) / 48000 ); + ovl = NS2SA( i_mult( sts[n]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + move16(); + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + move16(); hq_delay_comp = NS2SA( sts[0]->output_Fs, DELAY_CLDFB_NS ); + move16(); - IF( hCPE->element_mode >= IVAS_CPE_DFT && hCPE->element_mode != IVAS_CPE_MDCT ) + test(); + test(); + IF( GE_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { IF( sts[n]->core == ACELP_CORE ) { @@ -3564,64 +3764,72 @@ void stereo_td2dft_update_fx( /* update DFT analysis overlap memory @internal_fs: BPF */ IF( sts[n]->p_bpf_noise_buf_32 ) { - Copy32( sts[n]->p_bpf_noise_buf_32 + sts[n]->L_frame - ovl, hCPE->input_mem_BPF_fx[n], ovl ); + Copy32( sts[n]->p_bpf_noise_buf_32 + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_BPF_fx[n], ovl ); } /* update DFT analysis overlap memory @output_Fs: BWE */ - IF( sts[n]->extl != -1 || ( sts[n]->bws_cnt > 0 && sts[n]->core == ACELP_CORE ) ) + test(); + test(); + IF( NE_16( sts[n]->extl, -1 ) || ( sts[n]->bws_cnt > 0 && sts[n]->core == ACELP_CORE ) ) { - Copy32( hb_synth_fx + output_frame - dft32ms_ovl, hCPE->input_mem_fx[n], dft32ms_ovl ); + Copy32( hb_synth_fx + sub( output_frame, dft32ms_ovl ), hCPE->input_mem_fx[n], dft32ms_ovl ); } } ELSE { /* update DFT analysis overlap memory @internal_fs: core synthesis, secondary channel */ - Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + Copy32( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], ovl ); } } ELSE /* TCX core */ { /* LB-TCX synthesis */ - Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + Copy32( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], ovl ); /* BPF */ IF( n == 0 && sts[n]->p_bpf_noise_buf_32 ) { - Copy32( sts[n]->p_bpf_noise_buf_32 + sts[n]->L_frame - ovl, hCPE->input_mem_BPF_fx[n], ovl ); + Copy32( sts[n]->p_bpf_noise_buf_32 + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_BPF_fx[n], ovl ); } /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ IF( sts[n]->hTcxDec != NULL ) { ovl_TCX = NS2SA( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + move16(); Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], ovl_TCX - hq_delay_comp ); Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); } } } - ELSE IF( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->input_mem_fx[0] != NULL ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && hCPE->input_mem_fx[0] != NULL ) { /* update DFT stereo OLA memories */ /*set_zero( hCPE->input_mem_LB[n], STEREO_DFT32MS_OVL_16k );*/ - L_lerp_fx_q11( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], STEREO_DFT32MS_OVL_16k, ovl ); + L_lerp_fx_q11( output_fx + sub( sts[n]->L_frame, ovl ), hCPE->input_mem_LB_fx[n], STEREO_DFT32MS_OVL_16k, ovl ); /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ IF( sts[n]->hTcxDec != NULL ) { ovl_TCX = NS2SA( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); - Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], ovl_TCX - hq_delay_comp ); - Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); + move16(); + Copy32( synth_fx + add( sts[n]->hTcxDec->L_frameTCX, sub( hq_delay_comp, ovl_TCX ) ), hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + sub( ovl_TCX, hq_delay_comp ), hq_delay_comp ); } - IF( n == 1 ) + IF( EQ_16( n, 1 ) ) { - nsLB = NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); + nsLB = NS2SA( L_mult0( sts[n]->L_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); + move16(); ns = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); - old_outLB_len = (Word16) ( ( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * sts[0]->L_frame * FRAMES_PER_SEC ) / 48000 ); - old_out_len = (Word16) ( ( STEREO_MDCT2DFT_FADE_LEN_48k * sts[0]->output_Fs ) / 48000 ); + move16(); + old_outLB_len = extract_l( Mpy_32_32( ( L_mult0( STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, i_mult( 3, sts[0]->L_frame ) ) ), 44740 ) ); + move16(); + old_out_len = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); + move16(); /* update buffers used for fading when switching to DFT Stereo */ v_add_fx( sts[0]->hHQ_core->old_outLB_fx + nsLB, sts[1]->hHQ_core->old_outLB_fx + nsLB, hCPE->old_outLB_mdct_fx, old_outLB_len ); @@ -3629,19 +3837,21 @@ void stereo_td2dft_update_fx( #ifndef MSAN_FIX for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) #else - FOR( int i = 0; i < old_outLB_len; i++ ) + FOR( Word32 i = 0; i < old_outLB_len; i++ ) #endif { hCPE->old_outLB_mdct_fx[i] = L_shr( hCPE->old_outLB_mdct_fx[i], 1 ); + move32(); } v_add_fx( sts[0]->hHQ_core->oldOut_fx + ns, sts[1]->hHQ_core->oldOut_fx + ns, hCPE->old_out_mdct_fx, old_out_len ); #ifndef MSAN_FIX for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) #else - FOR( int i = 0; i < old_out_len; i++ ) + FOR( Word32 i = 0; i < old_out_len; i++ ) #endif { hCPE->old_out_mdct_fx[i] = L_shr( hCPE->old_out_mdct_fx[i], 1 ); + move32(); } } @@ -3652,9 +3862,11 @@ void stereo_td2dft_update_fx( } /* update ovl buffer for possible switching from TD stereo SCh ACELP frame to MDCT stereo TCX frame */ - IF( hCPE->element_mode == IVAS_CPE_TD && n == 1 && sts[n]->hTcxDec == NULL ) + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && sts[n]->hTcxDec == NULL ) { - Copy32( output_fx + sts[n]->L_frame / 2, hCPE->hStereoTD->TCX_old_syn_Overl_fx, sts[n]->L_frame / 2 ); + Copy32( output_fx + shr( sts[n]->L_frame, 1 ), hCPE->hStereoTD->TCX_old_syn_Overl_fx, shr( sts[n]->L_frame, 1 ) ); } return; @@ -3708,89 +3920,102 @@ void stereo_mdct2dft_update_fx( Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ ) { - int16_t i; - int16_t fade_len, fade_len_LB; + Word16 i; + Word16 fade_len, fade_len_LB; Word32 tmpF_fx = 0; Decoder_State *st; - if ( hCPE == NULL ) + IF( hCPE == NULL ) { return; } st = hCPE->hCoreCoder[0]; - fade_len = (int16_t) ( ( STEREO_MDCT2DFT_FADE_LEN_48k * st->output_Fs ) / 48000 ); - fade_len_LB = (int16_t) ( 3 * ( STEREO_MDCT2DFT_FADE_LEN_48k * st->L_frame * FRAMES_PER_SEC ) / 48000 ); - switch ( st->output_Fs ) + fade_len = extract_l( Mpy_32_32( imult3216( st->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); // 1/48000 = 44740 (Q31) + fade_len_LB = extract_l( Mpy_32_32( imult3216( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * FRAMES_PER_SEC, st->L_frame ), 44740 ) ); // 1/48000 = 44740 (Q31) + SWITCH( st->output_Fs ) { case 16000: tmpF_fx = 53687092; + move32(); BREAK; case 32000: tmpF_fx = 26843546; + move32(); BREAK; case 48000: tmpF_fx = 17895698; + move32(); BREAK; } - for ( i = 0; i < fade_len; i++ ) + FOR( i = 0; i < fade_len; i++ ) { Word32 descen_gain; - if ( i == 0 ) + IF( EQ_16( i, 0 ) ) { descen_gain = ONE_IN_Q31; + move32(); } - else + ELSE { - descen_gain = ( fade_len - i ) * tmpF_fx; + descen_gain = W_extract_l( W_mult0_32_32( ( sub( fade_len, i ) ), tmpF_fx ) ); } Word32 temp_a = Mpy_32_32( hCPE->old_out_mdct_fx[i], descen_gain ); - Word32 ascend_gain = i * tmpF_fx; + Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); Word32 temp_b = Mpy_32_32( synth0_fx[i], ascend_gain ); synth0_fx[i] = L_add_sat( temp_a, temp_b ); + move32(); } - switch ( st->L_frame ) + SWITCH( st->L_frame ) { case 80: tmpF_fx = 71582792; + move32(); BREAK; case 160: tmpF_fx = 35791396; + move32(); BREAK; case 256: tmpF_fx = 22369622; + move32(); BREAK; case 320: tmpF_fx = 17895698; + move32(); BREAK; case 512: tmpF_fx = 11184811; + move32(); BREAK; case 640: tmpF_fx = 8947849; + move32(); BREAK; case 960: tmpF_fx = 5965232; + move32(); BREAK; default: assert( 0 ); } - for ( i = 0; i < fade_len_LB; i++ ) + FOR( i = 0; i < fade_len_LB; i++ ) { Word32 descen_gain; - if ( i == 0 ) + IF( i == 0 ) { descen_gain = ONE_IN_Q31; + move32(); } - else + ELSE { - descen_gain = ( fade_len_LB - i ) * tmpF_fx; + descen_gain = W_extract_l( W_mult0_32_32( sub( fade_len_LB, i ), tmpF_fx ) ); } Word32 temp_a = Mpy_32_32( hCPE->old_outLB_mdct_fx[i], descen_gain ); - Word32 ascend_gain = i * tmpF_fx; + Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); Word32 temp_b = Mpy_32_32( output0_fx[i], ascend_gain ); output0_fx[i] = L_add_sat( temp_a, temp_b ); } @@ -3865,26 +4090,26 @@ static Word32 ncross_corr_self_fx( signal_b_fx = &signal_fx[y]; FOR( j = 0; j < corr_len; j += subsampling ) { - c_c_fx += ( (Word64) ( signal_a_fx[j] ) * ( signal_b_fx[j] ) ); - energy_x_fx += (Word64) ( signal_a_fx[j] ) * ( signal_a_fx[j] ); - energy_y_fx += (Word64) ( signal_b_fx[j] ) * ( signal_b_fx[j] ); + c_c_fx = W_add( c_c_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_b_fx[j] ) ) ); + energy_x_fx = W_add( energy_x_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_a_fx[j] ) ) ); + energy_y_fx = W_add( energy_y_fx, W_mult0_32_32( ( signal_b_fx[j] ), ( signal_b_fx[j] ) ) ); } headroom_left_x = W_norm( energy_x_fx ); headroom_left_y = W_norm( energy_y_fx ); - IF( headroom_left_x < 32 ) + IF( LT_16( headroom_left_x, 32 ) ) { - energy_x_fx = W_shr( energy_x_fx, (Word16) ( 32 - headroom_left_x ) ); - x_q = (Word16) ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_x ) ) ); + energy_x_fx = W_shr( energy_x_fx, sub( 32, headroom_left_x ) ); + x_q = sub( 31, ( sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_x ) ) ) ); } ELSE { x_q = 31 - ( 2 * OUTPUT_Q ); } - IF( headroom_left_y < 32 ) + IF( LT_16( headroom_left_y, 32 ) ) { - energy_y_fx = W_shr( energy_y_fx, (Word16) ( 32 - headroom_left_y ) ); - y_q = (Word16) ( 31 - ( ( 2 * OUTPUT_Q ) - ( 32 - headroom_left_y ) ) ); + energy_y_fx = W_shr( energy_y_fx, sub( 32, headroom_left_y ) ); + y_q = sub( 31, ( sub( ( 2 * OUTPUT_Q ), ( sub( 32, headroom_left_y ) ) ) ) ); } ELSE { @@ -3892,26 +4117,30 @@ static Word32 ncross_corr_self_fx( } x_inv_q = x_q; + move16(); y_inv_q = y_q; + move16(); - temp_x = Sqrt32( (Word32) energy_x_fx, &x_q ); + temp_x = Sqrt32( W_extract_l( energy_x_fx ), &x_q ); IF( x_q < 0 ) { - temp_x = L_shr( temp_x, -1 * x_q ); + temp_x = L_shr( temp_x, i_mult( -1, x_q ) ); x_q = 0; + move16(); } - temp_y = Sqrt32( (Word32) energy_y_fx, &y_q ); + temp_y = Sqrt32( W_extract_l( energy_y_fx ), &y_q ); IF( y_q < 0 ) { - temp_y = L_shr( temp_y, -1 * y_q ); + temp_y = L_shr( temp_y, i_mult( -1, y_q ) ); y_q = 0; + move16(); } energy_xy_fx = Mpy_32_32( temp_x, temp_y ); - res_q = y_q + x_q; + res_q = add( y_q, x_q ); - IF( ( energy_xy_fx < L_shr( ONE_IN_Q31, (Word16) res_q ) ) || energy_xy_fx == 0 ) + IF( ( energy_xy_fx < L_shr( ONE_IN_Q31, res_q ) ) || energy_xy_fx == 0 ) { energy_xy_fx = ONE_IN_Q31; /* conceal silent frames */ res_q = 0; @@ -3919,24 +4148,26 @@ static Word32 ncross_corr_self_fx( } ELSE { - Word32 temp_x_inv = ISqrt32( (Word32) energy_x_fx, &x_inv_q ); - Word32 temp_y_inv = ISqrt32( (Word32) energy_y_fx, &y_inv_q ); + Word32 temp_x_inv = ISqrt32( W_extract_l( energy_x_fx ), &x_inv_q ); + Word32 temp_y_inv = ISqrt32( W_extract_l( energy_y_fx ), &y_inv_q ); Word16 headroom_left_c_c; - energy_xy_fx = (Word32) Mpy_32_32( temp_x_inv, temp_y_inv ); - res_q = x_inv_q + y_inv_q; + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); + res_q = add( x_inv_q, y_inv_q ); headroom_left_c_c = W_norm( c_c_fx ); c_c_fx_q = OUTPUT_Q * 2; - IF( headroom_left_c_c < 32 ) + move16(); + IF( LT_16( headroom_left_c_c, 32 ) ) { - c_c_fx = W_shr( c_c_fx, (Word16) ( 32 - headroom_left_c_c ) ); - c_c_fx_q = c_c_fx_q - ( 32 - headroom_left_c_c ); + c_c_fx = W_shr( c_c_fx, extract_l( sub( 32, headroom_left_c_c ) ) ); + c_c_fx_q = sub( c_c_fx_q, sub( 32, headroom_left_c_c ) ); } - c_c_fx = (Word64) Mpy_32_32( (Word32) c_c_fx, (Word32) energy_xy_fx ); - c_c_fx_q = (Word16) c_c_fx_q + ( 31 - res_q ) - 31; - c_c_fx = (Word32) W_shl_sat_l( c_c_fx, (Word16) ( 31 - c_c_fx_q ) ); + c_c_fx = W_deposit32_l( Mpy_32_32( W_extract_l( c_c_fx ), W_extract_l( energy_xy_fx ) ) ); + c_c_fx_q = add( c_c_fx_q, sub( sub( 31, res_q ), 31 ) ); + c_c_fx = W_extract_l( W_shl_sat_l( c_c_fx, extract_l( sub( 31, c_c_fx_q ) ) ) ); } - c_c_fx_return = (Word32) c_c_fx; + c_c_fx_return = W_extract_l( c_c_fx ); + move32(); return c_c_fx_return; } #endif @@ -4128,7 +4359,7 @@ void smooth_dft2td_transition_fx( ilen = shr( output_frame, 1 ); /* correlation length */ - corr_len = output_frame / 20; + corr_len = idiv1616( output_frame, 20 ); subsampl = 4; FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) @@ -4136,10 +4367,10 @@ void smooth_dft2td_transition_fx( /* core to external sampling frequency ratio */ Word16 q = norm_l( output_frame ); Word32 check = BASOP_Util_Divide3232_Scale( output_frame, sts[ch]->L_frame, &q ); - fac_fs_fx = check * ( 1 << ( 26 - ( 15 - q ) ) ); + fac_fs_fx = imult3216( check, shl( 1, add( 26 - 15, q ) ) ); /* Find minimum and maximum pitch*/ - ipit_min = minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ) + 4; - ipit_max = maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ) + 4; + ipit_min = add( minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); + ipit_max = add( maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); ipit_min = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_min], fac_fs_fx ), ONE_IN_Q10 ), 11 ); ipit_max = (Word16) L_shr( L_add( Mpy_32_32( sts[ch]->old_pitch_buf_fx[ipit_max], fac_fs_fx ), ONE_IN_Q10 ), 11 ); @@ -4152,7 +4383,7 @@ void smooth_dft2td_transition_fx( lsearch = s_min( lsearch, shr( output_frame, 2 ) ); /* ptr init for search of the best correlation in the past frame */ - ptE_fx = hCPE->prev_synth_chs_fx[ch] + output_frame - ipit_max - corr_len; + ptE_fx = hCPE->prev_synth_chs_fx[ch] + sub( output_frame, add( ipit_max, corr_len ) ); idiff = 0; move16(); @@ -4190,11 +4421,11 @@ void smooth_dft2td_transition_fx( } /* Set buffer for the reserved buffer of the current frame */ - ptO2_fx = tmp_out2_fx + output_frame - ilen; - set32_fx( tmp_out2_fx + output_frame - ilen, 0, ilen ); + ptO2_fx = tmp_out2_fx + sub( output_frame, ilen ); + set32_fx( tmp_out2_fx + sub( output_frame, ilen ), 0, ilen ); FOR( i = 0; i < output_frame; i++ ) { - tmp_out2_fx[i] = output_fx[ch][output_frame - 1 - i]; + tmp_out2_fx[i] = output_fx[ch][sub( output_frame, ( 1 + i ) )]; move32(); } /* ptr init for search of the best correlation of the current frame */ @@ -4221,7 +4452,7 @@ void smooth_dft2td_transition_fx( /* If the correlation is too low, don't use the prediction */ IF( GT_32( fmaxcorr_fx, DFT2TD_CORR_THRESH_FX ) ) { - pt1_fx = tmp_out2_fx + output_frame - ilen - ipit; + pt1_fx = tmp_out2_fx + sub( output_frame, add( ilen, ipit ) ); FOR( i = 0; i < ilen; i++ ) { ptO2_fx[i] = pt1_fx[i]; @@ -4250,16 +4481,17 @@ void smooth_dft2td_transition_fx( } FOR( i = 0; i < 4; i++ ) { - Word64 temp_a = W_shr( ( ( 4 - i ) * (Word64) output_fx[ch][i] + i * ptO_fx[i] ), 2 ) * ( ilen - i ); - Word64 temp_b = tmp_out2_fx[output_frame - 1 - i] * i; - output_fx[ch][i] = (Word32) W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ); + Word64 temp_a = W_shr( W_add( W_mult0_32_32( sub( 4, i ), output_fx[ch][i] ), W_mult0_32_32( i, ptO_fx[i] ) ), 2 ) * ( ilen - i ); + move64(); + Word64 temp_b = W_mult0_32_32( tmp_out2_fx[sub( output_frame, add( 1, i ) )], i ); + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); move32(); } - FOR( ; i < ilen - 4; i++ ) + FOR( ; i < sub( ilen, 4 ); i++ ) { - Word64 temp_a = (Word64) ptO_fx[i] * ( ilen - i ); - Word64 temp_b = (Word64) tmp_out2_fx[output_frame - 1 - i] * i; - output_fx[ch][i] = (Word32) W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ); + Word64 temp_a = W_mult0_32_32( ptO_fx[i], sub( ilen, i ) ); + Word64 temp_b = W_mult0_32_32( tmp_out2_fx[sub( output_frame, add( 1, i ) )], i ); + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); move32(); } j = 0; @@ -4267,10 +4499,10 @@ void smooth_dft2td_transition_fx( FOR( ; i < ilen; i++ ) { Word64 temp_a = (Word64) ptO_fx[i] * ( ilen - i ); - Word64 temp_b = W_shr( ( W_add( (Word64) ( 4 - j ) * tmp_out2_fx[output_frame - 1 - i], (Word64) j * output_fx[ch][i] ) * i ), 2 ); - output_fx[ch][i] = (Word32) W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ); + Word64 temp_b = W_shr( ( W_add( W_mult0_32_32( sub( 4, j ), tmp_out2_fx[sub( output_frame, add( 1, i ) )] ), W_mult0_32_32( j, output_fx[ch][i] ) ) * i ), 2 ); + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); move32(); - j++; + j = add( j, 1 ); } } } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index ffb63c5ce67a68584e32a756499e5f5f7e7d58ba..d9401f6654676cd1f70903e53948e4f480d97522 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -85,23 +85,34 @@ void stereo_td_init_dec_fx( ) { hStereoTD->tdm_SM_flag = 0; + move16(); hStereoTD->tdm_last_SM_flag = 0; + move16(); hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + move16(); hStereoTD->tdm_prev_last_SM_flag = 0; + move16(); hStereoTD->tdm_LRTD_flag = 0; + move16(); // hStereoTD->prevSP_ratio = 0.5f; hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 + move16(); // hStereoTD->SP_ratio_LT = 0.0f; hStereoTD->SP_ratio_LT_fx = 0; + move32(); // hStereoTD->c_LR_LT = 0.5f; hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 + move32(); hStereoTD->flag_skip_DMX = 0; + move16(); - if ( last_element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + move16(); hStereoTD->tdm_LRTD_flag = 1; + move16(); } set32_fx( hStereoTD->TCX_old_syn_Overl_fx, 0, L_FRAME16k / 2 ); @@ -142,8 +153,8 @@ void tdm_configure_dec( hStereoTD = hCPE->hStereoTD; sts = hCPE->hCoreCoder; - element_brate_adapt = hCPE->element_brate + hCPE->brate_surplus; - bstr_last_pos = (Word16) ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + (Word16) ( hCPE->brate_surplus / FRAMES_PER_SEC ); + element_brate_adapt = L_add( hCPE->element_brate, hCPE->brate_surplus ); + bstr_last_pos = add( sub( div_l( hCPE->element_brate, FRAMES_PER_SEC / 2 ), nb_bits_metadata ), div_l( hCPE->brate_surplus, FRAMES_PER_SEC / 2 ) ); /*----------------------------------------------------------------* * Decode CoreCoder signaling @@ -151,45 +162,55 @@ void tdm_configure_dec( /* temporarily decode PCh signaling */ bits_offset = sts[0]->next_bit_pos; + move16(); core = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 1 ); - bits_offset += 1; + bits_offset = add( bits_offset, 1 ); - IF( core == ACELP_CORE && hCPE->element_brate < IVAS_24k4 ) + IF( core == ACELP_CORE && LT_32( hCPE->element_brate, IVAS_24k4 ) ) { mod_ct = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 3 ); /* Only transition mode is important to decoder, otherwise mod_ct is set to AUDIO only to easy debugging IF needed */ - IF( mod_ct != TRANSITION ) + if ( NE_16( mod_ct, TRANSITION ) ) { mod_ct = AUDIO; + move16(); } } ELSE /* core != ACELP_CORE */ { mod_ct = AUDIO; /* coder_type == VOICED || coder_type == GENERIC */ + move16(); } /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); + move16(); /* Get the LRTD config flag: 1 = LRTD configuration, favor closer bitrate per channel; 0 = Pri/Sec configuration, bitrates linked wrt. the mono */ - tdm_tmp_SM_LRTD_flag = sts[1]->coder_type & 0x1; - sts[1]->coder_type >>= 1; + tdm_tmp_SM_LRTD_flag = s_and( sts[1]->coder_type, 0x1 ); + sts[1]->coder_type = shr( sts[1]->coder_type, 1 ); + move16(); hStereoTD->tdm_Pitch_reuse_flag = 0; + move16(); - IF( sts[1]->coder_type == 2 ) + IF( EQ_16( sts[1]->coder_type, 2 ) ) { sts[1]->coder_type = GENERIC; + move16(); } - ELSE IF( sts[1]->coder_type == 3 ) + ELSE IF( EQ_16( sts[1]->coder_type, 3 ) ) { sts[1]->coder_type = AUDIO; + move16(); - IF( hCPE->element_brate <= IVAS_24k4 ) + IF( LE_32( hCPE->element_brate, IVAS_24k4 ) ) { hStereoTD->tdm_Pitch_reuse_flag = 1; + move16(); sts[1]->coder_type = GENERIC; + move16(); } } @@ -198,104 +219,140 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ /* Get the correlation ratio */ - *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, (Word16) ( bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); + *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, ( sub( bstr_last_pos, ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS ) ) ), TDM_RATIO_BITS ); + move16(); hStereoTD->tdm_use_IAWB_Ave_lpc = 0; + move16(); IF( sts[1]->coder_type == INACTIVE ) { /* Get the flag on the LPC reusage type (primary channel of ave LPC */ - hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); + hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); + move16(); hStereoTD->tdm_lp_reuse_flag = 1; + move16(); } ELSE { /* Get the flag on the LPC reusage */ - hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); + hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); + move16(); } sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() */ + move16(); sts[1]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; + move16(); tdm_inst_ratio_idx = *tdm_ratio_idx; + move16(); /* update past tdm_SM_flag */ hStereoTD->tdm_prev_last_SM_flag = hStereoTD->tdm_last_SM_flag; + move16(); hStereoTD->tdm_last_SM_flag = hStereoTD->tdm_SM_flag; + move16(); idx_LRTD_pri_side = -1; - IF( hStereoTD->tdm_LRTD_flag == 1 ) + move16(); + IF( EQ_16( hStereoTD->tdm_LRTD_flag, 1 ) ) { idx_LRTD_pri_side = tdm_tmp_SM_LRTD_flag; + move16(); hStereoTD->tdm_SM_flag = 0; + move16(); IF( tdm_inst_ratio_idx == TDM_NQ ) { hStereoTD->flag_skip_DMX = 1; + move16(); } ELSE { hStereoTD->flag_skip_DMX = 0; + move16(); } /* Set primary channel */ *tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; - IF( idx_LRTD_pri_side == 1 ) + move16(); + if ( EQ_16( idx_LRTD_pri_side, 1 ) ) { *tdm_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + move16(); } } ELSE { hStereoTD->tdm_SM_flag = tdm_tmp_SM_LRTD_flag; - IF( hCPE->nchan_out == 1 ) + move16(); + if ( EQ_16( hCPE->nchan_out, 1 ) ) { /* in case of mono output, use exclusively the YX upmixing scheme in order to deal with NOOP signals */ hStereoTD->tdm_SM_flag = 0; + move16(); } } - IF( sts[1]->coder_type == INACTIVE && ( *tdm_ratio_idx >= 29 || *tdm_ratio_idx <= 1 ) ) + test(); + test(); + IF( sts[1]->coder_type == INACTIVE && ( GE_16( *tdm_ratio_idx, 29 ) || LE_16( *tdm_ratio_idx, 1 ) ) ) { hStereoTD->tdm_lp_reuse_flag = hStereoTD->tdm_use_IAWB_Ave_lpc; + move16(); hStereoTD->tdm_use_IAWB_Ave_lpc = 0; + move16(); } /*sts[1]->tdm_inst_ratio_idx = sts[0]->tdm_inst_ratio_idx;*/ - IF( hCPE->nchan_out == 1 && hCPE->hStereoDftDmx != NULL ) + test(); + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && hCPE->hStereoDftDmx != NULL ) { /* in mono DMX, only targetGain is needed */ Word16 tmpS = 20; + move16(); IF( hStereoTD->tdm_LRTD_flag == 0 ) { - tmpS = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); + tmpS = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); } hCPE->hStereoDftDmx->targetGain_fx = power_table[tmpS]; + move32(); } ELSE { IF( hStereoTD->tdm_LRTD_flag == 0 ) { - hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS, STEREO_BITS_TCA_CHAN ); - hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN, STEREO_BITS_TCA_CORRSTATS ); - hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); + hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ); + move16(); + hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ), STEREO_BITS_TCA_CORRSTATS ); + move16(); + hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, add( sub( bstr_last_pos, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); + move16(); } ELSE { hCPE->hStereoTCA->refChanIndx = L_CH_INDX; + move16(); hCPE->hStereoTCA->indx_ica_NCShift = 0; + move16(); hCPE->hStereoTCA->indx_ica_gD = 20; + move16(); } hCPE->hStereoTCA->targetGain_fx = power_table[hCPE->hStereoTCA->indx_ica_gD]; + move32(); } /* set the BW of the secondary channel */ - IF( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel >= IVAS_16k4 / FRAMES_PER_SEC ) + IF( hStereoTD->tdm_LRTD_flag && GE_16( sts[1]->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) { /* set BW of the secondary channel in LRTD stereo mode as the BW of the primary channel at higher bitrates */ sts[1]->bwidth = sts[0]->bwidth; + move16(); } ELSE { /* limit BW of the secondary channel in LRTD mode to WB for low bitrates */ sts[1]->bwidth = WB; + move16(); } /*----------------------------------------------------------------* @@ -553,14 +610,16 @@ void tdm_upmix_plain_fx( { Word16 i; - IF( plus_minus_flag == 1 ) + IF( EQ_16( plus_minus_flag, 1 ) ) { FOR( i = start_index; i < end_index; i++ ) { Word32 temp_left = L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); + move32(); Word32 temp_right = L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ); Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); + move32(); } } ELSE @@ -569,8 +628,10 @@ void tdm_upmix_plain_fx( { Word32 temp_left = L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ); Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); + move32(); Word32 temp_right = L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ); Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); + move32(); } } @@ -799,7 +860,9 @@ static void tdm_upmix_fade_fx( step_fx = inv_time[end_index - start_index]; fade_out_fx = ONE_IN_Q31; + move32(); fade_in_fx = 0; + move32(); fade_out_fx = Mpy_32_32( fade_out_fx, inv_den_LR_ratio_mem_fx ); fade_in_fx = Mpy_32_32( fade_in_fx, inv_den_LR_ratio_fx ); @@ -813,57 +876,65 @@ static void tdm_upmix_fade_fx( Word32 temp_left1 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); Word32 temp_left2 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + move32(); Word32 temp_right1 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_mem_fx ) ), PCh_2_L_fx[i] ), fade_out_fx ); Word32 temp_right2 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ), fade_in_fx ); Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + move32(); fade_in_fx = L_add( fade_in_fx, step2_fx ); fade_out_fx = L_sub( fade_out_fx, step_fx ); } } - ELSE IF( fading_type == 1 ) /* SM scheme */ + ELSE IF( EQ_16( fading_type, 1 ) ) /* SM scheme */ { FOR( i = start_index; i < end_index; i++ ) { Word32 temp_left1 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); Word32 temp_left2 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + move32(); Word32 temp_right1 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), PCh_2_L_fx[i] ), fade_out_fx ); Word32 temp_right2 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), PCh_2_L_fx[i] ), fade_in_fx ); Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + move32(); fade_in_fx = L_add( fade_in_fx, step2_fx ); fade_out_fx = L_sub( fade_out_fx, step_fx ); } } - ELSE IF( fading_type == 2 ) /* Switching from SM scheme to YX scheme */ + ELSE IF( EQ_16( fading_type, 2 ) ) /* Switching from SM scheme to YX scheme */ { FOR( i = start_index; i < end_index; i++ ) { Word32 temp_left1 = Mpy_32_32( L_sub( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); Word32 temp_left2 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + move32(); Word32 temp_right1 = Mpy_32_32( L_sub( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), PCh_2_L_fx[i] ), fade_out_fx ); Word32 temp_right2 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ), fade_in_fx ); Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + move32(); fade_in_fx = L_add( fade_in_fx, step2_fx ); fade_out_fx = L_sub( fade_out_fx, step_fx ); } } - ELSE IF( fading_type == 3 ) /* YX scheme */ + ELSE IF( EQ_16( fading_type, 3 ) ) /* YX scheme */ { FOR( i = start_index; i < end_index; i++ ) { Word32 temp_left1 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_mem_fx ), SCh_2_R_fx[i] ), fade_out_fx ); Word32 temp_left2 = Mpy_32_32( L_add( Mpy_32_32( L_sub( PCh_2_L_fx[i], SCh_2_R_fx[i] ), LR_ratio_fx ), SCh_2_R_fx[i] ), fade_in_fx ); Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); + move32(); Word32 temp_right1 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_mem_fx ) ), PCh_2_L_fx[i] ), fade_out_fx ); Word32 temp_right2 = Mpy_32_32( L_add( Mpy_32_32( L_add( PCh_2_L_fx[i], SCh_2_R_fx[i] ), L_negate( LR_ratio_fx ) ), PCh_2_L_fx[i] ), fade_in_fx ); Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); + move32(); fade_in_fx = L_add( fade_in_fx, step2_fx ); fade_out_fx = L_sub( fade_out_fx, step_fx ); @@ -1090,7 +1161,7 @@ void stereo_tdm_combine_fx( } ELSE IF( EQ_16( hCPE->hStereoTD->tdm_last_SM_flag, 1 ) ) { - IF( EQ_16( hCPE->hStereoTD->tdm_prev_last_SM_flag, 0 ) ) + IF( hCPE->hStereoTD->tdm_prev_last_SM_flag == 0 ) { stereo_tdm_coder_type = 0; /* mode 1 : Switching from YX scheme to SM scheme*/ move16(); @@ -1123,10 +1194,10 @@ void stereo_tdm_combine_fx( tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], 0, upmixing_delay, 1 ); /* Switching from YX scheme to SM scheme */ - tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, upmixing_delay + tdm_n_OVA, 0 ); + tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, add( upmixing_delay, tdm_n_OVA ), 0 ); /* Do the upmixing of the other samples with the new coefficient and formular for SM scheme */ - tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 0 ); + tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], add( upmixing_delay, tdm_n_OVA ), output_frame, 0 ); } BREAK; case ( 1 ): @@ -1141,7 +1212,7 @@ void stereo_tdm_combine_fx( } ELSE { - tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, upmixing_delay + tdm_n_OVA, 1 ); + tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, add( upmixing_delay, tdm_n_OVA ), 1 ); tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 0 ); } } @@ -1152,7 +1223,7 @@ void stereo_tdm_combine_fx( tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], 0, upmixing_delay, 0 ); /* Switching from SM scheme to YX scheme */ - tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, upmixing_delay + tdm_n_OVA, 2 ); + tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, add( upmixing_delay, tdm_n_OVA ), 2 ); /* Do the upmixing of the other samples with the new coefficient and formular for YX scheme */ tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 1 ); @@ -1170,7 +1241,7 @@ void stereo_tdm_combine_fx( } ELSE { - tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, upmixing_delay + tdm_n_OVA, 3 ); + tdm_upmix_fade_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_mem_fx, tdm_den_ratio_tabl_fx[tdm_last_ratio_idx], LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay, add( upmixing_delay, tdm_n_OVA ), 3 ); tdm_upmix_plain_fx( Left_fx, Right_fx, PCh_2_L_fx, SCh_2_R_fx, LR_ratio_fx, tdm_den_ratio_tabl_fx[tdm_ratio_idx], upmixing_delay + tdm_n_OVA, output_frame, 1 ); } } diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 218be76403458facef2ad088b6d5bda5a63d0b03..630e24d4e0918dfeda66fe360ceef6fb79316093 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -236,7 +236,8 @@ void mat2svdMat_fx( { FOR( j = 0; j < nRows; j++ ) { - svdMat[i][j] = mat[j + nRows * i]; + svdMat[i][j] = mat[add( j, i_mult( nRows, i ) )]; + move32(); } set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - nRows ); @@ -253,7 +254,8 @@ void mat2svdMat_fx( { FOR( j = 0; j < mCols; j++ ) { - svdMat[i][j] = mat[i + nRows * j]; + svdMat[i][j] = mat[add( i, i_mult( nRows, j ) )]; + move32(); } set_zero_fx( &svdMat[i][mCols], MAX_OUTPUT_CHANNELS - mCols ); @@ -288,7 +290,8 @@ void svdMat2mat_fx( { FOR( j = 0; j < mCols; j++ ) { - mat[i + nRows * j] = svdMat[i][j]; + mat[add( i, i_mult( nRows, j ) )] = svdMat[i][j]; + move32(); } } @@ -405,8 +408,11 @@ Word16 svd_fx( // int16_t max_length = ((nChannelsL > nChannelsC) ? nChannelsL : nChannelsC); Word32 secDiag_fx[MAX_OUTPUT_CHANNELS]; Word16 secDiag_fx_e = 0; + move16(); Word32 eps_x_fx = 0, temp_fx; + move16(); Word16 eps_x_fx_e = 0; + move16(); push_wmops( "svd_fx" ); set32_fx( secDiag_fx, 0, MAX_OUTPUT_CHANNELS ); @@ -417,10 +423,12 @@ Word16 svd_fx( FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { singularVectors_Left_fx[iCh][jCh] = InputMatrix[iCh][jCh]; + move32(); } } *singularValues_fx_e = 0; + move16(); /* Householder reduction */ HouseholderReduction_fx( singularVectors_Left_fx, singularValues_fx, singularVectors_Right_fx, secDiag_fx, InputMatrix_e, singularValues_fx_e, &secDiag_fx_e, nChannelsL, nChannelsC, &eps_x_fx, &eps_x_fx_e ); @@ -439,27 +447,38 @@ Word16 svd_fx( DO { condition = 0; - FOR( iCh = 0; iCh < lengthSingularValues - 1; iCh++ ) + move16(); + FOR( iCh = 0; iCh < sub( lengthSingularValues, 1 ); iCh++ ) { IF( LT_32( singularValues_fx[iCh], singularValues_fx[iCh + 1] ) ) { condition = 1; + move16(); temp_fx = singularValues_fx[iCh]; + move32(); singularValues_fx[iCh] = singularValues_fx[iCh + 1]; + move32(); singularValues_fx[iCh + 1] = temp_fx; + move32(); FOR( jCh = 0; jCh < nChannelsL; ++jCh ) { temp_fx = singularVectors_Left_fx[jCh][iCh]; + move32(); singularVectors_Left_fx[jCh][iCh] = singularVectors_Left_fx[jCh][iCh + 1]; + move32(); singularVectors_Left_fx[jCh][iCh + 1] = temp_fx; + move32(); } FOR( jCh = 0; jCh < nChannelsC; ++jCh ) { temp_fx = singularVectors_Right_fx[jCh][iCh]; + move32(); singularVectors_Right_fx[jCh][iCh] = singularVectors_Right_fx[jCh][iCh + 1]; + move32(); singularVectors_Right_fx[jCh][iCh + 1] = temp_fx; + move32(); } } } @@ -577,11 +596,16 @@ static Word16 BidagonalDiagonalisation_fx( Word32 c, s, f1, f2; Word16 c_e, s_e, f1_e, f2_e; Word16 x11_e = 0, x12_e = 0; + move16(); + move16(); Word16 temp_exp; Word32 g = 0; + move16(); Word16 g_e = 0; + move16(); Word16 convergence, iteration, found_split; Word16 error = 0; + move16(); Word16 singularValues_new_e[MAX_OUTPUT_CHANNELS], secDiag_new_e[MAX_OUTPUT_CHANNELS]; set16_fx( singularValues_new_e, *singularValues_fx_e, MAX_OUTPUT_CHANNELS ); set16_fx( secDiag_new_e, *secDiag_fx_e, MAX_OUTPUT_CHANNELS ); @@ -589,20 +613,25 @@ static Word16 BidagonalDiagonalisation_fx( FOR( iCh = nChannelsC - 1; iCh >= 0; iCh-- ) /* nChannelsC */ { convergence = 0; + move16(); iteration = 0; + move16(); split = iCh - 1; + move16(); WHILE( EQ_16( convergence, 0 ) ) { - iteration++; + iteration = add( iteration, 1 ); found_split = 1; + move16(); FOR( jCh = iCh; jCh >= 0; jCh-- ) { - split = jCh - 1; + split = sub( jCh, 1 ); IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( secDiag_fx[jCh] ), secDiag_new_e[jCh], Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is secDiag[ch] vanishing compared to eps_x */ { found_split = 0; + move16(); BREAK; } IF( LE_16( BASOP_Util_Cmp_Mant32Exp( L_abs( singularValues_fx[split] ), singularValues_new_e[split], Mpy_32_32( CONVERGENCE_FACTOR_FX, eps_x ), eps_x_e ), 0 ) ) /* is singularValues[split] vanishing compared to eps_x */ @@ -611,14 +640,28 @@ static Word16 BidagonalDiagonalisation_fx( } } - convergence = ( jCh == iCh ) ? 1 : 0; + // convergence = ( jCh == iCh ) ? 1 : 0; + IF( EQ_16( jCh, iCh ) ) + { + convergence = 1; + move16(); + } + ELSE + { + convergence = 0; + move16(); + } IF( found_split ) { s = MAX_32; + move32(); s_e = 0; + move16(); c = 0; + move32(); c_e = 0; + move16(); FOR( kCh = jCh; kCh <= iCh; kCh++ ) { @@ -636,17 +679,19 @@ static Word16 BidagonalDiagonalisation_fx( singularValues_fx[kCh] = GivensRotation_fx( g, g_e, singularValues_fx[kCh], singularValues_new_e[kCh], &singularValues_new_e[kCh] ); c = BASOP_Util_Divide3232_Scale_cadence( c, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); c_e = add( temp_exp, sub( c_e, singularValues_new_e[kCh] ) ); - IF( GT_16( c_e, 0 ) ) + IF( c_e > 0 ) { c = L_shl_sat( c, c_e ); // Q31 c_e = 0; + move16(); } s = BASOP_Util_Divide3232_Scale_cadence( -g, maxWithSign_fx( singularValues_fx[kCh] ), &temp_exp ); s_e = add( temp_exp, sub( g_e, singularValues_new_e[kCh] ) ); - IF( GT_16( s_e, 0 ) ) + IF( s_e > 0 ) { s = L_shl_sat( s, s_e ); // Q31 s_e = 0; + move16(); } ApplyRotation_fx( singularVectors_Left_fx, c, c_e, s, s_e, 0, x11_e, 0, x12_e, &f1, &f1_e, &f2, &f2_e, kCh, split, nChannelsL ); /* nChannelsL */ @@ -655,13 +700,16 @@ static Word16 BidagonalDiagonalisation_fx( IF( convergence ) { - singularValues_fx[iCh] = (Word32) singularValues_fx[iCh]; - IF( LT_32( singularValues_fx[iCh], 0 ) ) + singularValues_fx[iCh] = singularValues_fx[iCh]; + move32(); + IF( singularValues_fx[iCh] < 0 ) { singularValues_fx[iCh] = L_negate( singularValues_fx[iCh] ); + move32(); FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { singularVectors_Right_fx[nCh][iCh] = L_negate( singularVectors_Right_fx[nCh][iCh] ); + move32(); } } } @@ -672,14 +720,18 @@ static Word16 BidagonalDiagonalisation_fx( IF( LT_32( singularValues_fx[iCh], 0 ) ) { singularValues_fx[iCh] = L_negate( singularValues_fx[iCh] ); + move32(); FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { singularVectors_Right_fx[nCh][iCh] = L_negate( singularVectors_Right_fx[nCh][iCh] ); + move32(); } } error = 1; + move16(); convergence = 1; + move16(); } ELSE { @@ -691,30 +743,40 @@ static Word16 BidagonalDiagonalisation_fx( // rescaling block Word16 max_exp = -31; - FOR( iCh = 0; iCh < nChannelsC; iCh++ ){ - IF( singularValues_fx[iCh] ){ + move16(); + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) + { + if ( singularValues_fx[iCh] ) + { max_exp = s_max( max_exp, singularValues_new_e[iCh] ); -} -} -*singularValues_fx_e = max_exp; -FOR( iCh = 0; iCh < nChannelsC; iCh++ ) -{ - singularValues_fx[iCh] = L_shr_r( singularValues_fx[iCh], sub( *singularValues_fx_e, singularValues_new_e[iCh] ) ); -} + } + } + *singularValues_fx_e = max_exp; + move16(); + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) + { + singularValues_fx[iCh] = L_shr_r( singularValues_fx[iCh], sub( *singularValues_fx_e, singularValues_new_e[iCh] ) ); + move32(); + } -max_exp = -31; -FOR( iCh = 0; iCh < nChannelsC; iCh++ ){ - IF( secDiag_fx[iCh] ){ - max_exp = s_max( max_exp, secDiag_new_e[iCh] ); -} -} -*secDiag_fx_e = max_exp; -FOR( iCh = 0; iCh < nChannelsC; iCh++ ) -{ - secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); -} + max_exp = -31; + move16(); + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) + { + if ( secDiag_fx[iCh] ) + { + max_exp = s_max( max_exp, secDiag_new_e[iCh] ); + } + } + *secDiag_fx_e = max_exp; + move16(); + FOR( iCh = 0; iCh < nChannelsC; iCh++ ) + { + secDiag_fx[iCh] = L_shr_r( secDiag_fx[iCh], sub( *secDiag_fx_e, secDiag_new_e[iCh] ) ); + move32(); + } -return ( error ); + return ( error ); } #else static int16_t BidagonalDiagonalisation( @@ -845,26 +907,57 @@ static void ApplyQRTransform_fx( { Word16 ch, split; Word32 d = 0, g = 0, r = 0, x_ii = 0, x_split = 0, x_kk = 0, mu = 0, aux = 0; + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); Word16 d_e = 0, g_e = 0, r_e = 0, x_ii_e = 0, x_split_e = 0, x_kk_e = 0, mu_e = 0, aux_e = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word32 L_temp1, L_temp2, L_temp3, L_temp4; Word16 L_temp1_e, L_temp2_e, L_temp3_e, L_temp4_e, temp_exp; Word32 c = MAX_32; + move32(); Word16 c_e = 0; + move16(); Word32 s = MAX_32; + move32(); Word16 s_e = 0; + move16(); x_kk = singularValues[currentIndex]; + move32(); x_kk_e = singularValues_e[currentIndex]; + move16(); x_ii = singularValues[startIndex]; + move32(); x_ii_e = singularValues_e[startIndex]; - split = currentIndex - 1; + move16(); + split = sub( currentIndex, 1 ); + move16(); x_split = singularValues[split]; + move32(); x_split_e = singularValues_e[split]; + move16(); g = secDiag[split]; + move32(); g_e = secDiag_e[split]; + move16(); r = secDiag[currentIndex]; + move32(); r_e = secDiag_e[currentIndex]; + move16(); // d = (x_split + x_kk) * (x_split - x_kk) + (g + r) * (g - r); L_temp1 = BASOP_Util_Add_Mant32Exp( x_split, x_split_e, x_kk, x_kk_e, &L_temp1_e ); @@ -883,8 +976,17 @@ static void ApplyQRTransform_fx( g = GivensRotation_fx( MAX_32, 0, d, d_e, &g_e ); // mu = x_split / maxWithSign(d + (d >= 0.0f ? 1 : (-1)) * fabsf(g)) - r; - L_temp1 = d >= 0 ? L_abs( g ) : -L_abs( g ); + // L_temp1 = d >= 0 ? L_abs( g ) : -L_abs( g ); + IF( d >= 0 ) + { + L_temp1 = L_abs( g ); + } + ELSE + { + L_temp1 = L_negate( L_abs( g ) ); + } L_temp1_e = g_e; + move16(); L_temp2 = maxWithSign_fx( BASOP_Util_Add_Mant32Exp( d, d_e, L_temp1, L_temp1_e, &L_temp2_e ) ); mu = BASOP_Util_Divide3232_Scale_cadence( x_split, L_temp2, &mu_e ); mu_e = add( mu_e, sub( x_split_e, L_temp2_e ) ); @@ -906,19 +1008,22 @@ static void ApplyQRTransform_fx( g_e = add( c_e, secDiag_e[ch + 1] ); secDiag[ch] = GivensRotation_fx( d, d_e, r, r_e, &secDiag_e[ch] ); + move32(); c = BASOP_Util_Divide3232_Scale_cadence( d, maxWithSign_fx( secDiag[ch] ), &c_e ); c_e = add( c_e, sub( d_e, secDiag_e[ch] ) ); - IF( GT_16( c_e, 0 ) ) + IF( c_e > 0 ) { c = L_shl_sat( c, c_e ); // Q31 c_e = 0; + move16(); } s = BASOP_Util_Divide3232_Scale_cadence( r, maxWithSign_fx( secDiag[ch] ), &s_e ); s_e = add( s_e, sub( r_e, secDiag_e[ch] ) ); - IF( GT_16( s_e, 0 ) ) + IF( s_e > 0 ) { s = L_shl_sat( s, s_e ); // Q31 s_e = 0; + move16(); } r = Mpy_32_32( s, singularValues[ch + 1] ); @@ -927,12 +1032,15 @@ static void ApplyQRTransform_fx( x_split_e = add( c_e, singularValues_e[ch + 1] ); aux = g; + move32(); aux_e = g_e; + move16(); // ApplyRotation(singularVectors_Right, c, s, x_ii, aux, &d, &g, ch + 1, ch, nChannelsC); ApplyRotation_fx( singularVectors_Right, c, c_e, s, s_e, x_ii, x_ii_e, aux, aux_e, &d, &d_e, &g, &g_e, ch + 1, ch, nChannelsC ); singularValues[ch] = GivensRotation_fx( d, d_e, r, r_e, &singularValues_e[ch] ); + move32(); IF( GT_32( L_abs( singularValues[ch] ), Mpy_32_32( CONVERGENCE_FACTOR_FX, L_abs( singularValues[ch] ) ) ) ) { aux = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, singularValues[ch], &aux_e ); @@ -940,18 +1048,20 @@ static void ApplyQRTransform_fx( c = Mpy_32_32( d, aux ); c_e = add( d_e, aux_e ); - IF( GT_16( c_e, 0 ) ) + IF( c_e > 0 ) { c = L_shl_sat( c, c_e ); // Q31 c_e = 0; + move16(); } s = Mpy_32_32( r, aux ); s_e = add( r_e, aux_e ); - IF( GT_16( s_e, 0 ) ) + IF( s_e > 0 ) { s = L_shl_sat( s, s_e ); // Q31 s_e = 0; + move16(); } } @@ -960,10 +1070,15 @@ static void ApplyQRTransform_fx( } secDiag[startIndex] = 0; + move32(); secDiag[currentIndex] = d; + move32(); secDiag_e[currentIndex] = d_e; + move16(); singularValues[currentIndex] = x_ii; + move32(); singularValues_e[currentIndex] = x_ii_e; + move16(); return; } @@ -1062,16 +1177,24 @@ static void ApplyRotation_fx( Word16 temp_exp; *d = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), add( c_e, x11_e ), Mpy_32_32( s, x12 ), add( s_e, x12_e ), d_e ); + move32(); *g = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), add( c_e, x12_e ), Mpy_32_32( -s, x11 ), add( s_e, x11_e ), g_e ); + move32(); FOR( ch = 0; ch < nChannels; ch++ ) { x11 = singularVector[ch][currentIndex2]; + move32(); x12 = singularVector[ch][currentIndex1]; + move32(); singularVector[ch][currentIndex2] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x11 ), c_e, Mpy_32_32( s, x12 ), s_e, &temp_exp ); + move32(); singularVector[ch][currentIndex2] = L_shl_sat( singularVector[ch][currentIndex2], temp_exp ); + move32(); singularVector[ch][currentIndex1] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( c, x12 ), c_e, Mpy_32_32( -s, x11 ), s_e, &temp_exp ); + move32(); singularVector[ch][currentIndex1] = L_shl_sat( singularVector[ch][currentIndex1], temp_exp ); + move32(); } return; @@ -1121,15 +1244,18 @@ static void HouseholderReduction_fx( Word16 singularVectors_Left_e, Word16 *singularValues_fx_e, Word16 *secDiag_fx_e, - const int16_t nChannelsL, - const int16_t nChannelsC, + const Word16 nChannelsL, + const Word16 nChannelsC, Word32 *eps_x_fx, Word16 *eps_x_fx_e ) { - int16_t nCh; + Word16 nCh; // float g = 0.0f, sig_x = 0.0f;// to be removed Word32 g_fx = 0, sig_x_fx = 0; + move32(); + move32(); Word16 sig_x_fx_e = 0; + move16(); /* Bidiagonal Reduction for every channel */ FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ @@ -1142,7 +1268,9 @@ static void HouseholderReduction_fx( IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_temp, L_temp_e, *eps_x_fx, *eps_x_fx_e ), 1 ) ) { *eps_x_fx = L_temp; + move32(); *eps_x_fx_e = L_temp_e; + move32(); } } @@ -1212,32 +1340,39 @@ static void biDiagonalReductionLeft_fx( Word16 L_temp_e; FOR( jCh = 0; jCh < MAX_OUTPUT_CHANNELS; jCh++ ) { - set_s( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); + set16_fx( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); } secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); + move32(); // rescaling block IF( GT_16( *sig_x_e, *secDiag_e ) ) { FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ){ IF( NE_16( i, currChannel ) ){ secDiag[i] = L_shl( secDiag[i], sub( *secDiag_e, *sig_x_e ) ); + move32(); } } *secDiag_e = *sig_x_e; +move16(); } ELSE IF( LT_16( *sig_x_e, *secDiag_e ) ) { secDiag[currChannel] = L_shr_r( secDiag[currChannel], sub( *secDiag_e, *sig_x_e ) ); + move32(); } /* Setting values to 0 */ ( *sig_x ) = 0; +move32(); ( *g ) = 0; +move32(); IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ { idx = currChannel; + move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { @@ -1247,30 +1382,50 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ { norm_x = 0; + move32(); norm_x_e = 0; + move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { singularVectors[jCh][currChannel] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[jCh][currChannel], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + move32(); sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); + move16(); norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); } IF( GT_16( norm_x_e, 0 ) ) { norm_x = MAX_32; + move32(); norm_x_e = 0; + move16(); } L_temp_e = norm_x_e; + move16(); L_temp = Sqrt32( norm_x, &L_temp_e ); L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 - ( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) ); + //( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) ); + IF( singularVectors[currChannel][idx] >= 0 ) + { + ( *g ) = L_negate( L_temp ); + move32(); + } + ELSE + { + ( *g ) = L_negate( L_negate( L_temp ) ); + move32(); + } r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[currChannel], -norm_x, norm_x_e, &r_e ); singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[currChannel] ); + move32(); FOR( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { norm_x = 0; + move32(); norm_x_e = 0; + move16(); FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), add( sing_exp[jCh], *singularVectors_e ), &norm_x_e ); @@ -1282,6 +1437,7 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], *singularVectors_e, Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, sing_exp[jCh] ), &sing_exp2[jCh][iCh] ); + move32(); } } @@ -1289,11 +1445,14 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); + move32(); sing_exp2[jCh][currChannel] = add( sing_exp[jCh], *sig_x_e ); + move16(); } // rescaling block Word16 exp_max = *singularVectors_e; + move16(); FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { FOR( jCh = 0; jCh < nChannelsL; jCh++ ) @@ -1307,25 +1466,31 @@ IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */ FOR( jCh = 0; jCh < nChannelsL; jCh++ ) { singularVectors[jCh][iCh] = L_shr_r( singularVectors[jCh][iCh], sub( exp_max, sing_exp2[jCh][iCh] ) ); + move32(); } } *singularVectors_e = exp_max; + move16(); } // rescaling block singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); + move32(); IF( GT_16( *sig_x_e, *singularValues_e ) ) { FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ){ IF( NE_16( i, currChannel ) ){ singularValues[i] = L_shl( singularValues[i], sub( *singularValues_e, *sig_x_e ) ); + move32(); } } *singularValues_e = *sig_x_e; +move16(); } ELSE IF( LT_16( *sig_x_e, *singularValues_e ) ) { singularValues[currChannel] = L_shr_r( singularValues[currChannel], sub( *singularValues_e, *sig_x_e ) ); + move32(); } } @@ -1433,13 +1598,15 @@ static void biDiagonalReductionRight_fx( Word16 L_temp_e; FOR( jCh = 0; jCh < MAX_OUTPUT_CHANNELS; jCh++ ) { - set_s( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); + set16_fx( sing_exp2[jCh], *singularVectors_e, MAX_OUTPUT_CHANNELS ); } - set_s( secDiag_exp, *secDiag_e, MAX_OUTPUT_CHANNELS ); + set16_fx( secDiag_exp, *secDiag_e, MAX_OUTPUT_CHANNELS ); /* Setting values to 0 */ ( *sig_x ) = 0; + move32(); ( *g ) = 0; + move32(); IF( LT_16( currChannel, nChannelsL ) && NE_16( currChannel, sub( nChannelsC, 1 ) ) ) /* i <=m && i !=n */ { @@ -1453,37 +1620,58 @@ static void biDiagonalReductionRight_fx( IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ { norm_x = 0; + move32(); norm_x_e = 0; + move16(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ { singularVectors[currChannel][jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( *sig_x ), &sing_exp[jCh] ); + move32(); sing_exp[jCh] = add( sing_exp[jCh], sub( *singularVectors_e, *sig_x_e ) ); + move16(); norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( sing_exp[jCh], 1 ), &norm_x_e ); } IF( GT_16( norm_x_e, 0 ) ) { norm_x = MAX_32; + move32(); norm_x_e = 0; + move16(); } L_temp_e = norm_x_e; + move16(); L_temp = Sqrt32( norm_x, &L_temp_e ); L_temp = L_shl_r( L_temp, L_temp_e ); // Q31 - ( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) ); + IF( singularVectors[currChannel][idx] >= 0 ) + { + ( *g ) = L_negate( L_temp ); + move32(); + } + ELSE + { + ( *g ) = L_negate( L_negate( L_temp ) ); + move32(); + } r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), sing_exp[idx], -norm_x, norm_x_e, &r_e ); singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], sing_exp[idx], -( *g ), 0, &sing_exp[idx] ); + move32(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { secDiag[jCh] = BASOP_Util_Divide3232_Scale_cadence( singularVectors[currChannel][jCh], maxWithSign_fx( r ), &secDiag_exp[jCh] ); + move32(); secDiag_exp[jCh] = add( secDiag_exp[jCh], sub( sing_exp[jCh], r_e ) ); + move32(); } FOR( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { norm_x = 0; + move32(); norm_x_e = 0; + move16(); FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( *singularVectors_e, sing_exp[jCh] ), &norm_x_e ); @@ -1492,17 +1680,21 @@ static void biDiagonalReductionRight_fx( FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], *singularVectors_e, Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &sing_exp2[iCh][jCh] ); + move32(); } } FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { singularVectors[currChannel][jCh] = Mpy_32_32( singularVectors[currChannel][jCh], ( *sig_x ) ); + move32(); sing_exp2[currChannel][jCh] = add( sing_exp[jCh], *sig_x_e ); + move16(); } /*rescaling block*/ Word16 exp_max = *secDiag_e; + move16(); FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { exp_max = s_max( exp_max, secDiag_exp[jCh] ); @@ -1510,10 +1702,12 @@ static void biDiagonalReductionRight_fx( FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { secDiag[jCh] = L_shr_r( secDiag[jCh], sub( exp_max, secDiag_exp[jCh] ) ); + move32(); } exp_max = *singularVectors_e; + move16(); FOR( iCh = 0; iCh < nChannelsL; iCh++ ) { FOR( jCh = 0; jCh < nChannelsC; jCh++ ) @@ -1527,9 +1721,11 @@ static void biDiagonalReductionRight_fx( FOR( jCh = 0; jCh < nChannelsC; jCh++ ) { singularVectors[iCh][jCh] = L_shr_r( singularVectors[iCh][jCh], sub( exp_max, sing_exp2[iCh][jCh] ) ); + move32(); } } *singularVectors_e = exp_max; + move16(); } } @@ -1626,7 +1822,7 @@ static void singularVectorsAccumulationLeft_fx( Word16 sing_exp2[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS] = { 0 }; FOR( nCh = 0; nCh < MAX_OUTPUT_CHANNELS; nCh++ ) { - set_s( sing_exp2[nCh], singularVectors_e, MAX_OUTPUT_CHANNELS ); + set16_fx( sing_exp2[nCh], singularVectors_e, MAX_OUTPUT_CHANNELS ); } /* Processing */ @@ -1635,11 +1831,14 @@ static void singularVectorsAccumulationLeft_fx( FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* min(nChannelsL,ChannelsC) */ { t_ii = singularValues[nCh]; + move32(); t_ii_e = singularValues_e; + move16(); FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { singularVectors_Left[nCh][iCh] = 0; + move32(); } IF( t_ii ) /*if (fabsf(t_ii) > EPSILON *fabsf(t_ii)) {*/ @@ -1650,7 +1849,9 @@ static void singularVectorsAccumulationLeft_fx( FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { norm_y = 0; + move32(); norm_y_e = 0; + move16(); FOR( k = nCh + 1; k < nChannelsL; k++ ) /* nChannelsL */ { norm_y = BASOP_Util_Add_Mant32Exp( norm_y, norm_y_e, Mpy_32_32( singularVectors_Left[k][nCh], singularVectors_Left[k][iCh] ), add( sing_exp2[k][nCh], sing_exp2[k][iCh] ), &norm_y_e ); @@ -1661,13 +1862,16 @@ static void singularVectorsAccumulationLeft_fx( FOR( k = nCh; k < nChannelsL; k++ ) /* nChannelsL */ { singularVectors_Left[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[k][iCh], sing_exp2[k][iCh], Mpy_32_32( t_jj, singularVectors_Left[k][nCh] ), add( t_jj_e, sing_exp2[k][nCh] ), &sing_exp2[k][iCh] ); + move32(); } } FOR( iCh = nCh; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { singularVectors_Left[iCh][nCh] = Mpy_32_32( singularVectors_Left[iCh][nCh], t_ii ); + move32(); sing_exp2[iCh][nCh] = add( sing_exp2[iCh][nCh], t_ii_e ); + move16(); } } ELSE @@ -1675,10 +1879,12 @@ static void singularVectorsAccumulationLeft_fx( FOR( iCh = nCh; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { singularVectors_Left[iCh][nCh] = 0; + move32(); } } singularVectors_Left[nCh][nCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Left[nCh][nCh], sing_exp2[nCh][nCh], ONE_IN_Q30, 1, &sing_exp2[nCh][nCh] ); + move32(); } // fclose(fp); FOR( nCh = 0; nCh < nChannelsL; nCh++ ) @@ -1686,6 +1892,7 @@ static void singularVectorsAccumulationLeft_fx( FOR( iCh = 0; iCh < nChannelsC; iCh++ ) { singularVectors_Left[nCh][iCh] = L_shl_sat( singularVectors_Left[nCh][iCh], sing_exp2[nCh][iCh] ); + move32(); } } @@ -1779,6 +1986,7 @@ static void singularVectorsAccumulationRight_fx( /* avoid compiler warning */ t_ii = secDiag[nChannels - 1]; + move32(); FOR( nCh = nChannels - 1; nCh >= 0; nCh-- ) /* nChannelsC, min(nChannelsLmnChannelsC) otherwise */ { @@ -1792,14 +2000,18 @@ static void singularVectorsAccumulationRight_fx( { ratio_float = BASOP_Util_Divide3232_Scale_cadence( singularVectors_Left[nCh][iCh], maxWithSign_fx( singularVectors_Left[nCh][nCh + 1] ), &temp_exp1 ); singularVectors_Right[iCh][nCh] = BASOP_Util_Divide3232_Scale_cadence( ratio_float, maxWithSign_fx( t_ii ), &sing_right_exp[iCh][nCh] ); + move32(); sing_right_exp[iCh][nCh] = add( sing_right_exp[iCh][nCh], sub( temp_exp1, secDiag_e ) ); + move16(); // singularVectors_Right[iCh][nCh] = L_shl_sat( singularVectors_Right[iCh][nCh], temp_exp2 ); } FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { norm_y = 0; + move32(); norm_y_e = 0; + move16(); FOR( k = nCh + 1; k < nChannelsC; k++ ) /* nChannelsC */ { @@ -1809,8 +2021,11 @@ static void singularVectorsAccumulationRight_fx( FOR( k = nCh + 1; k < nChannelsC; k++ ) /* nChannelsC */ { singularVectors_Right[k][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors_Right[k][iCh], sing_right_exp[k][iCh], Mpy_32_32( norm_y, singularVectors_Right[k][nCh] ), add( norm_y_e, sing_right_exp[k][nCh] ), &sing_right_exp[k][iCh] ); + move32(); singularVectors_Right[k][iCh] = L_shl_sat( singularVectors_Right[k][iCh], sing_right_exp[k][iCh] ); + move32(); sing_right_exp[k][iCh] = 0; + move16(); } } } @@ -1818,10 +2033,14 @@ static void singularVectorsAccumulationRight_fx( FOR( iCh = nCh + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { singularVectors_Right[nCh][iCh] = singularVectors_Right[iCh][nCh] = 0; + move32(); + move32(); } } singularVectors_Right[nCh][nCh] = MAX_32; + move32(); t_ii = secDiag[nCh]; + move32(); } return; } @@ -1905,15 +2124,18 @@ static Word32 GivensRotation_fx( Word32 L_temp; x_abs = L_abs( x ); z_abs = L_abs( z ); + test(); IF( LE_32( x_abs, Mpy_32_32( CONVERGENCE_FACTOR_FX, x_abs ) ) && LE_32( z_abs, Mpy_32_32( CONVERGENCE_FACTOR_FX, z_abs ) ) ) { r = 0; + move32(); } - ELSE IF( GE_16( BASOP_Util_Cmp_Mant32Exp( x_abs, x_e, z_abs, z_e ), 0 ) ) + ELSE IF( BASOP_Util_Cmp_Mant32Exp( x_abs, x_e, z_abs, z_e ) >= 0 ) { IF( LE_32( x_abs, SVD_MINIMUM_VALUE_FX ) ) { r = 0; + move32(); } ELSE { @@ -1930,12 +2152,13 @@ static Word32 GivensRotation_fx( IF( LE_32( z_abs, SVD_MINIMUM_VALUE_FX ) ) { r = 0; + move32(); } ELSE { tan = BASOP_Util_Divide3232_Scale_cadence( x_abs, z_abs, &temp_exp ); temp_exp = add( temp_exp, sub( x_e, z_e ) ); - L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), 2 * temp_exp, &temp_exp ); + L_temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, Mpy_32_32( tan, tan ), shl( temp_exp, 1 ), &temp_exp ); L_temp = Sqrt32( L_temp, &temp_exp ); r = Mpy_32_32( z_abs, L_temp ); *out_e = add( z_e, temp_exp ); @@ -2000,7 +2223,7 @@ static Word32 maxWithSign_fx( { return a; } - ELSE IF( LT_32( a, 0 ) ) + ELSE IF( a < 0 ) { return -SVD_MINIMUM_VALUE_FX; } diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 342c69d71ab32d952f55ad896544c39a11963605..d51543302e0a607c2c57c0e22047e2d42f8510bf 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -77,16 +77,16 @@ void stereo_tcx_init_dec_fx( TCX_DEC_HANDLE hTcxDec = st->hTcxDec; st->rate_switching_init = 0; - st->m_frame_type = ACTIVE_FRAME; - st->core_brate = st->total_brate; move16(); + st->m_frame_type = ACTIVE_FRAME; move16(); + st->core_brate = st->total_brate; move32(); /*sampling rate*/ st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); - st->fscale = sr2fscale( st->sr_core ); move32(); + st->fscale = sr2fscale( st->sr_core ); move16(); /*frame size*/ @@ -99,27 +99,29 @@ void stereo_tcx_init_dec_fx( test(); test(); test(); - IF( ( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( ( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ), MAX_ACELP_BRATE ) ) || ( st->tcxonly && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, INT_FS_16k ) ) ) ) + IF( ( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MAX_ACELP_BRATE ) ) || ( st->tcxonly && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, INT_FS_16k ) ) ) ) { st->nb_subfr = NB_SUBFR16k; + move16(); } ELSE { st->nb_subfr = NB_SUBFR; + move16(); } move16(); /*TCX tools*/ st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag ); - st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); - st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); move16(); + st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); move16(); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); move16(); + st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); move16(); - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->igf, st->element_mode ); move16(); @@ -135,25 +137,29 @@ void stereo_tcx_init_dec_fx( st->tcxonly = getTcxonly_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MCT_flag, st->is_ism_format ); move16(); - test(); /* LPC quantization */ + test(); IF( LE_32( st->sr_core, INT_FS_16k ) && st->tcxonly == 0 ) { st->lpcQuantization = 1; + move16(); } ELSE { st->lpcQuantization = 0; + move16(); } move16(); IF( st->tcxonly == 0 ) { st->numlpc = 1; + move16(); } ELSE { st->numlpc = 2; + move16(); } move16(); } @@ -169,7 +175,7 @@ void stereo_tcx_init_dec_fx( test(); IF( ( NE_32( st->bits_frame_nominal, st->last_bits_frame_nominal ) ) || ( NE_16( st->bwidth, st->last_bwidth ) ) || - ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) || + ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( last_element_mode, IVAS_CPE_MDCT ) ) ) { /*re-initialization*/ @@ -356,24 +362,24 @@ void stereo_tcx_core_dec_fx( iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); total_nbbits = extract_l( L_tmp ); bitsRead = 0; - LSF_Q_prediction = -1; /* to avoid compilation warnings */ - move16(); + LSF_Q_prediction = -1; /* to avoid compilation warnings */ move16(); - IF( EQ_32( frameMode, FRAMEMODE_NORMAL ) ) + + IF( frameMode == FRAMEMODE_NORMAL ) { st->m_decodeMode = DEC_NO_FRAM_LOSS; + move32(); bfi = 0; move16(); - move16(); } IF( EQ_32( frameMode, FRAMEMODE_MISSING ) ) { st->m_decodeMode = DEC_CONCEALMENT_EXT; + move32(); bfi = 1; move16(); - move16(); } /* for bass postfilter */ IF( st->tcxonly ) @@ -403,6 +409,7 @@ void stereo_tcx_core_dec_fx( IF( !bfi ) { st->second_last_core = st->last_core; + move16(); move16(); dec_prm_tcx_ivas_fx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); @@ -439,10 +446,12 @@ void stereo_tcx_core_dec_fx( IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); + move16(); } ELSE { tcx_lpc_cdk = tcxlpc_get_cdk( st->coder_type ); + move16(); } Copy( st->lsf_old_fx, &lsf_fx[0], M ); @@ -455,6 +464,7 @@ void stereo_tcx_core_dec_fx( lsf_update_memory( st->narrowBand, &lsf_fx[M], st->mem_MA_fx, st->mem_MA_fx, M ); Copy( &lsf_fx[M], st->mem_AR_fx, M ); hTcxDec->envWeighted = 1; + move16(); move16(); E_LPC_lsp_unweight( &lsp_fx[M], lspnew_uw_fx, lsfnew_uw_fx, st->inv_gamma /*1.0f / st->gamma_float*/, M ); @@ -483,11 +493,11 @@ void stereo_tcx_core_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[add( imult1616( k, M ), i )], ONE_BY_THREE_Q15 ) ); - st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; - st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[add( imult1616( k, M ), i )]; + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[add( i_mult( k, M ), i )], ONE_BY_THREE_Q15 ) ); move16(); + st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; move16(); + st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[add( i_mult( k, M ), i )]; move16(); } } @@ -501,10 +511,12 @@ void stereo_tcx_core_dec_fx( IF( st->tcxonly == 0 || LT_16( st->core, TCX_10_CORE ) ) { st->numlpc = 1; + move16(); } ELSE { st->numlpc = 2; + move16(); } move16(); @@ -550,6 +562,7 @@ void stereo_tcx_core_dec_fx( E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } + test(); if ( st->enablePlcWaveadjust && bfi ) { st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); @@ -560,7 +573,7 @@ void stereo_tcx_core_dec_fx( * TD-TCX concealment *--------------------------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { assert( bfi ); /*must only happen in BFI*/ @@ -594,7 +607,7 @@ void stereo_tcx_core_dec_fx( test(); IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( Aq_fx, st->mem_Aq, imult1616( st->nb_subfr, ( M + 1 ) ) ); + Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); } /* PLC: [TCX: Tonal Concealment] */ @@ -618,6 +631,7 @@ void stereo_tcx_core_dec_fx( IF( !bfi ) { st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); + move16(); } IF( hTcxDec->enableTcxLpc ) @@ -733,7 +747,7 @@ void stereo_tcx_core_dec_fx( IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); - Copy( Aq_fx, st->mem_Aq, imult1616( st->nb_subfr, ( M + 1 ) ) ); + Copy( Aq_fx, st->mem_Aq, i_mult( st->nb_subfr, ( M + 1 ) ) ); } } } @@ -755,10 +769,17 @@ void stereo_tcx_core_dec_fx( /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ Word16 prev_codec_mode = st->codec_mode; - st->codec_mode = MODE2; move16(); + st->codec_mode = MODE2; move16(); - FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->tcxonly ? GENERIC : st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_FER_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); + IF( st->tcxonly ) + { + FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, GENERIC, pitch_C, synth_fx, &st->lp_ener_FER_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); + } + ELSE + { + FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_FER_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); + } st->codec_mode = prev_codec_mode; move16(); } @@ -770,7 +791,7 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ test(); - IF( bfi && NE_16( st->last_core, ACELP_CORE ) ) + IF( bfi && st->last_core != ACELP_CORE ) { /* Update FEC_scale_syn parameters */ IF( hTcxLtpDec->tcxltp_gain == 0 ) @@ -808,8 +829,8 @@ void stereo_tcx_core_dec_fx( } ELSE { - Copy( &lsp_fx[st->numlpc * M], st->lsp_old_fx, M ); - Copy( &lsf_fx[st->numlpc * M], st->lsf_old_fx, M ); + Copy( &lsp_fx[i_mult( st->numlpc, M )], st->lsp_old_fx, M ); + Copy( &lsf_fx[i_mult( st->numlpc, M )], st->lsf_old_fx, M ); } Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); @@ -821,7 +842,7 @@ void stereo_tcx_core_dec_fx( /* update CNG parameters in active frames */ test(); test(); - IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc && st->core != ACELP_CORE ) { Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; assert( EQ_16( st->L_frame, L_FRAME ) ); @@ -846,15 +867,17 @@ void stereo_tcx_core_dec_fx( cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); } /* Set 16k LSP flag for CNG buffer */ + // st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); IF( EQ_16( st->L_frame, L_FRAME ) ) { st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; + move16(); } ELSE { st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; + move16(); } - move16(); } st->last_is_cng = 0; @@ -913,8 +936,8 @@ void stereo_tcx_core_dec_fx( /* updates */ st->last_voice_factor_fx = 0; - st->last_coder_type = st->coder_type; move16(); + st->last_coder_type = st->coder_type; move16(); /* -------------------------------------------------------------- * @@ -952,7 +975,6 @@ void stereo_tcx_core_dec_fx( /* Generate additional comfort noise to mask potential coding artefacts */ test(); - test(); IF( EQ_16( st->m_frame_type, ACTIVE_FRAME ) && st->flag_cna && !st->cna_dirac_flag ) { test(); @@ -1808,12 +1830,12 @@ static void dec_prm_tcx_ivas_fx( move16(); } start_bit_pos = st->next_bit_pos; + move16(); /* Init LTP data */ st->hTcxDec->tcx_hm_LtpPitchLag = -1; - st->hTcxLtpDec->tcxltp_gain = 0; - move16(); move16(); + st->hTcxLtpDec->tcxltp_gain = 0; move16(); /*--------------------------------------------------------------------------------* @@ -1829,8 +1851,9 @@ static void dec_prm_tcx_ivas_fx( { st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core */ move16(); + test(); - IF( EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->last_core == ACELP_CORE && st->last_core_from_bs != ACELP_CORE ) { /* A mismatch between the memory and the last_core from the bitstream indicates a frame was lost. If prev_bfi is @@ -1845,7 +1868,7 @@ static void dec_prm_tcx_ivas_fx( test(); test(); test(); - IF( NE_16( st->last_core, st->last_core_from_bs ) && ( NE_16( st->last_core_from_bs, TCX_20_CORE ) && NE_16( st->last_core_from_bs, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) ) + IF( NE_16( st->last_core, st->last_core_from_bs ) && ( NE_16( st->last_core_from_bs, TCX_20_CORE ) && NE_16( st->last_core_from_bs, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && st->last_core_from_bs == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) ) { Word16 Q_old_Aq_12_8 = Q12; move16(); diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 4731bf883ae645f25f18d3a2e1cf099a75ebb67e..feae9373c294c31f87ab8e97e082670c03938032 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -249,10 +249,10 @@ void tdm_low_rate_dec_fx( move16(); st->GSC_IVAS_mode = 0; - st->GSC_noisy_speech = 1; - hGSCDec->noise_lev = 14; move16(); + st->GSC_noisy_speech = 1; move16(); + hGSCDec->noise_lev = 14; move16(); pit_band_idx = 10 + BAND1k2; @@ -266,18 +266,22 @@ void tdm_low_rate_dec_fx( // set_f(exc, 0, L_FRAME); // set_f(dct_epit, 0, L_FRAME); // set_f(pitch_buf, L_SUBFR, NB_SUBFR); - set_s( exc, 0, L_FRAME ); - set_s( dct_epit, 0, L_FRAME ); - set_s( pitch_buf, shl( L_SUBFR, Q6 ), NB_SUBFR ); + set16_fx( exc, 0, L_FRAME ); + set16_fx( dct_epit, 0, L_FRAME ); + set16_fx( pitch_buf, shl( L_SUBFR, Q6 ), NB_SUBFR ); st->bpf_off = 1; move16(); st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); move16(); st->bfi_pitch_frame = L_FRAME; + move16(); Diff_len = L_FRAME / 2; + move16(); st->bpf_off = 0; + move16(); attack_flag = 0; + move16(); move16(); move16(); @@ -289,6 +293,7 @@ void tdm_low_rate_dec_fx( /* find the current total number of bits used */ tmp_nb_bits_tot = st->next_bit_pos; + move16(); move16(); if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) @@ -333,7 +338,7 @@ void tdm_low_rate_dec_fx( *--------------------------------------------------------------------------------------*/ // set_f(voice_factors, 0.0f, NB_SUBFR16k); - set_s( voice_factors, 0, NB_SUBFR16k ); + set16_fx( voice_factors, 0, NB_SUBFR16k ); IF( st->hBWE_TD != NULL ) { @@ -345,7 +350,7 @@ void tdm_low_rate_dec_fx( ELSE { // set_f(bwe_exc, 0, L_FRAME32k); - set_s( bwe_exc, 0, L_FRAME32k ); + set16_fx( bwe_exc, 0, L_FRAME32k ); } } @@ -362,7 +367,7 @@ void tdm_low_rate_dec_fx( * Channel aware mode parameters *--------------------------------------------------------------------------------------*/ - set_s( st->tilt_code_dec_fx, 0, NB_SUBFR16k ); + set16_fx( st->tilt_code_dec_fx, 0, NB_SUBFR16k ); return; } @@ -536,13 +541,13 @@ void decod_gen_2sbfr_ivas_fx( // float code[2 * L_SUBFR]; /* algebraic codevector */ // const float *p_Aq; /* Pointer to frame LP coefficient */ // float *pt_pitch; /* pointer to floating pitch */ - Word16 gain_pit = 0; /* pitch gain */ - Word32 gain_code = 0; /* gain/normalized gain of the algebraic excitation */ - Word32 norm_gain_code = 0; /* normalized gain of the algebraic excitation */ - Word16 gain_inov = 0; /* Innovation gain */ + Word16 gain_pit = 0; /* pitch gain */ move16(); + Word32 gain_code = 0; /* gain/normalized gain of the algebraic excitation */ move32(); + Word32 norm_gain_code = 0; /* normalized gain of the algebraic excitation */ move32(); + Word16 gain_inov = 0; /* Innovation gain */ move16(); // Word16 gains_mem[2 * (NB_SUBFR - 1)]; /* pitch gain and code gain from previous subframes */ Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ @@ -565,8 +570,11 @@ void decod_gen_2sbfr_ivas_fx( move16(); T0 = PIT_MIN; + move16(); T0_frac = 0; + move16(); error = 0; + move16(); move16(); move16(); @@ -695,15 +703,16 @@ void decod_gen_2sbfr_ivas_fx( pt_pitch++; *pt_pitch = *( pt_pitch - 1 ); + move16(); pt_pitch++; gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; - gain_buf[shr( add( i_subfr, L_SUBFR ), 6 ) /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; - st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; - st->tilt_code_dec_fx[shr( add( i_subfr, L_SUBFR ), 6 ) /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; move16(); + gain_buf[shr( add( i_subfr, L_SUBFR ), 6 ) /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; move16(); + st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; move16(); + st->tilt_code_dec_fx[shr( add( i_subfr, L_SUBFR ), 6 ) /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; move16(); // st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code; // st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code; diff --git a/lib_rend/ivas_mcmasa_ana.c b/lib_rend/ivas_mcmasa_ana.c index d210b360385a87b1e836c863e29b6eb05b63144d..b0c4e82a0918a267761096addd99eebb42b31cd1 100644 --- a/lib_rend/ivas_mcmasa_ana.c +++ b/lib_rend/ivas_mcmasa_ana.c @@ -172,59 +172,75 @@ ivas_error ivas_mcmasa_ana_open( IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) ) { nchan_inp = 6; - Copy32( ls_azimuth_CICP6_fx, ls_azimuth_fx, nchan_inp - 1 ); - Copy32( ls_elevation_CICP6_fx, ls_elevation_fx, nchan_inp - 1 ); + move16(); + Copy32( ls_azimuth_CICP6_fx, ls_azimuth_fx, 5 ); /* nchan_inp - 1 */ + Copy32( ls_elevation_CICP6_fx, ls_elevation_fx, 5 ); /* nchan_inp - 1 */ hMcMasa->numHorizontalChannels = 5; + move16(); hMcMasa->isHorizontalSetup = 1; + move16(); } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) ) { nchan_inp = 8; - Copy32( ls_azimuth_CICP12_fx, ls_azimuth_fx, nchan_inp - 1 ); - Copy32( ls_elevation_CICP12_fx, ls_elevation_fx, nchan_inp - 1 ); + move16(); + Copy32( ls_azimuth_CICP12_fx, ls_azimuth_fx, 7 ); /* nchan_inp - 1 */ + Copy32( ls_elevation_CICP12_fx, ls_elevation_fx, 7 ); /* nchan_inp - 1 */ hMcMasa->numHorizontalChannels = 7; + move16(); hMcMasa->isHorizontalSetup = 1; + move16(); } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) ) { nchan_inp = 8; - Copy32( ls_azimuth_CICP14_fx, ls_azimuth_fx, nchan_inp - 1 ); - Copy32( ls_elevation_CICP14_fx, ls_elevation_fx, nchan_inp - 1 ); + move16(); + Copy32( ls_azimuth_CICP14_fx, ls_azimuth_fx, 7 ); /* nchan_inp - 1 */ + Copy32( ls_elevation_CICP14_fx, ls_elevation_fx, 7 ); /* nchan_inp - 1 */ hMcMasa->numHorizontalChannels = 5; + move16(); hMcMasa->isHorizontalSetup = 0; + move16(); } ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) ) { nchan_inp = 10; - Copy32( ls_azimuth_CICP16_fx, ls_azimuth_fx, nchan_inp - 1 ); - Copy32( ls_elevation_CICP16_fx, ls_elevation_fx, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP16_fx, ls_azimuth_fx, 9 ); /* nchan_inp - 1 */ + Copy32( ls_elevation_CICP16_fx, ls_elevation_fx, 9 ); /* nchan_inp - 1 */ hMcMasa->numHorizontalChannels = 5; + move16(); hMcMasa->isHorizontalSetup = 0; + move16(); } ELSE { nchan_inp = 12; - Copy32( ls_azimuth_CICP19_fx, ls_azimuth_fx, nchan_inp - 1 ); - Copy32( ls_elevation_CICP19_fx, ls_elevation_fx, nchan_inp - 1 ); + move16(); + Copy32( ls_azimuth_CICP19_fx, ls_azimuth_fx, 11 ); /* nchan_inp - 1 */ + Copy32( ls_elevation_CICP19_fx, ls_elevation_fx, 11 ); /* nchan_inp - 1 */ hMcMasa->numHorizontalChannels = 7; + move16(); hMcMasa->isHorizontalSetup = 0; + move16(); } numAnalysisChannels = sub( nchan_inp, 1 ); /* Determine the number of bands */ hMcMasa->nbands = MASA_FREQUENCY_BANDS; - + move16(); /* Determine band grouping */ Copy( MASA_band_grouping_24, hMcMasa->band_grouping, 24 + 1 ); maxBin = extract_l( W_extract_h( W_add( W_mult_32_32( input_Fs, INV_CLDFB_BANDWIDTH_Q31 ), ONE_IN_Q31 /*0.5f in Q31*/ ) ) ); - FOR( i = 1; i < hMcMasa->nbands + 1; i++ ) + FOR( i = 1; i < add( hMcMasa->nbands, 1 ); i++ ) { IF( GE_16( hMcMasa->band_grouping[i], maxBin ) ) { hMcMasa->band_grouping[i] = maxBin; + move16(); hMcMasa->nbands = i; + move16(); break; } } @@ -234,9 +250,10 @@ ivas_error ivas_mcmasa_ana_open( /* open/initialize CLDFB */ hMcMasa->num_Cldfb_instances = numAnalysisChannels; + move16(); FOR( i = 0; i < hMcMasa->num_Cldfb_instances; i++ ) { - IF( ( error = openCldfb_ivas( &( hMcMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas( &( hMcMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, input_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -308,22 +325,32 @@ ivas_error ivas_mcmasa_ana_open( FOR( i = 0; i < numAnalysisChannels; i++ ) { hMcMasa->chnlToFoaMtx_fx[0][i] = ONE_IN_Q31; + move32(); hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_fx[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation_fx[i], 91 ), 7 ) ) ) ); + move32(); hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation_fx[i], 91 ), 7 ) ) ), 16 ); + move32(); hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_fx[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation_fx[i], 91 ), 7 ) ) ) ); + move32(); hMcMasa->chnlToFoaEvenMtx_fx[0][i] = ONE_IN_Q31; + move32(); hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even_fx[i], 91 ), 7 ) ) ), 16 ); + move32(); hMcMasa->chnlToFoaEvenMtx_fx[2][i] = 0; + move32(); hMcMasa->chnlToFoaEvenMtx_fx[3][i] = L_shl( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even_fx[i], 91 ), 7 ) ) ), 16 ); + move32(); } Copy32( ls_azimuth_fx, hMcMasa->ls_azimuth_fx, numAnalysisChannels ); FOR( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) { - left_min_fx = L_shl( 360, 22 ); - right_min_fx = L_shl( -360, 22 ); + left_min_fx = 360 << 22; + move32(); + right_min_fx = -( 360 << 22 ); + move32(); FOR( j = 0; j < hMcMasa->numHorizontalChannels; j++ ) { @@ -337,34 +364,47 @@ ivas_error ivas_mcmasa_ana_open( { azi_diff_fx = L_add( azi_diff_fx, 360 << 22 ); } - + test(); IF( LT_32( azi_diff_fx, left_min_fx ) && GT_32( azi_diff_fx, 0 ) ) { hMcMasa->leftNearest[i] = j; + move16(); left_min_fx = azi_diff_fx; + move32(); } - + test(); IF( GT_32( azi_diff_fx, right_min_fx ) && LT_32( azi_diff_fx, 0 ) ) { hMcMasa->rightNearest[i] = j; + move16(); right_min_fx = azi_diff_fx; + move32(); } } } hMcMasa->prevMultiChEne_fx = 0; + move32(); hMcMasa->prevDownmixEne_fx = 0; + move32(); hMcMasa->prevMultiChEne_e = 0; + move16(); hMcMasa->prevDownmixEne_e = 0; + move16(); hMcMasa->prevEQ_e = 1; + move16(); hMcMasa->prevEQ_fx = 1073741824; - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + move32(); + input_frame = (Word16) Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ); + move16(); FOR( i = 0; i < input_frame; i++ ) { hMcMasa->interpolator_fx[i] = div_s( i, input_frame ); + move16(); } hMcMasa->index_buffer_intensity = 0; + move16(); IF( ( hMcMasa->hMasaOut = (MASA_DECODER_EXT_OUT_META_HANDLE) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) { @@ -616,7 +656,8 @@ void ivas_mcmasa_ana_close( { Word16 i, j; - IF( hMcMasa == NULL || *hMcMasa == NULL ) + test(); + if ( hMcMasa == NULL || *hMcMasa == NULL ) { return; } @@ -650,31 +691,6 @@ void ivas_mcmasa_ana_close( free( ( *hMcMasa )->buffer_intensity_real_vert_fx[j] ); ( *hMcMasa )->buffer_intensity_real_vert_fx[j] = NULL; } -#if 0 /*TODO: To be removed later( freeing float buffer)*/ - FOR ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - FOR ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - free( ( *hMcMasa )->direction_vector_m[i][j] ); - ( *hMcMasa )->direction_vector_m[i][j] = NULL; - } - - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) - { - free( ( *hMcMasa )->buffer_intensity_real[i][j] ); - ( *hMcMasa )->buffer_intensity_real[i][j] = NULL; - } - - free( ( *hMcMasa )->direction_vector_m[i] ); - ( *hMcMasa )->direction_vector_m[i] = NULL; - } - - FOR ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) - { - free( ( *hMcMasa )->buffer_intensity_real_vert[j] ); - ( *hMcMasa )->buffer_intensity_real_vert[j] = NULL; - } -#endif free( ( *hMcMasa )->hMasaOut ); ( *hMcMasa )->hMasaOut = NULL; @@ -779,7 +795,7 @@ void ivas_mcmasa_ana_fx( /* Downmix */ - ivas_mcmasa_dmx_fx( hMcMasa, data, 31 - q_data, input_frame, nchan_transport, nchan_inp ); + ivas_mcmasa_dmx_fx( hMcMasa, data, sub( 31, q_data ), input_frame, nchan_transport, nchan_inp ); return; @@ -870,6 +886,7 @@ void ivas_mcmasa_param_est_ana_fx( Word16 lsEnergy_e[MCMASA_MAX_ANA_CHANS]; Word32 lsEnergySum_fx, maxEne_fx; Word16 lsEnergySum_e = 0; + move16(); Word16 maxEne_e; Word32 angleDist_fx, minAngleDist_fx; Word32 currentAzi_fx; @@ -896,8 +913,10 @@ void ivas_mcmasa_param_est_ana_fx( Word16 numAnalysisChannels; Word16 spreadCoh_e; num_freq_bins = hMcMasa->cldfbAnaEnc[0]->no_channels; + move16(); num_freq_bands = hMcMasa->nbands; - l_ts = input_frame / CLDFB_NO_COL_MAX; + move16(); + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); numAnalysisChannels = sub( nchan_inp, 1 ); set16_fx( q_vdv, 31, MASA_FREQUENCY_BANDS ); @@ -906,16 +925,24 @@ void ivas_mcmasa_param_est_ana_fx( FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { mrange[0] = hMcMasa->block_grouping[block_m_idx]; + move16(); mrange[1] = hMcMasa->block_grouping[block_m_idx + 1]; + move16(); FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = 0; + move16(); hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; + move16(); hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; + move16(); hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] = 0; + move16(); hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] = 0; + move16(); hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] = 0; + move16(); } /* Need to initialize renormalization_factors, and variables to be normalized */ @@ -940,11 +967,15 @@ void ivas_mcmasa_param_est_ana_fx( FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { Word16 cr_q = MAX_16, ci_q = MAX_16, sf, c_e; + move16(); + move16(); Word16 inp_q = q_data; + move16(); FOR( i = 0; i < numAnalysisChannels; i++ ) { inp_q = q_data; - cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hMcMasa->cldfbAnaEnc[i], &inp_q ); + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][i_mult( l_ts, ts )] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hMcMasa->cldfbAnaEnc[i], &inp_q ); cr_q = s_min( cr_q, getScaleFactor32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); ci_q = s_min( ci_q, getScaleFactor32( Chnl_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ); } @@ -957,17 +988,21 @@ void ivas_mcmasa_param_est_ana_fx( inp_q = add( inp_q, sf ); c_e = sub( 31, inp_q ); hMcMasa->chnlToFoaMtx_e = c_e; + move16(); /* Compute channel-based energy for metadata processing */ FOR( band_m_idx = 0; band_m_idx < num_freq_bands; band_m_idx++ ) { brange[0] = hMcMasa->band_grouping[band_m_idx]; + move16(); brange[1] = hMcMasa->band_grouping[band_m_idx + 1]; + move16(); FOR( j = brange[0]; j < brange[1]; j++ ) { FOR( i = 0; i < numAnalysisChannels; i++ ) { Word32 temp = L_add( Mult_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ), Mult_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ) ); - hMcMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->energy_fx[block_m_idx][band_m_idx], hMcMasa->energy_e[block_m_idx][band_m_idx], temp, (c_e) *2, &hMcMasa->energy_e[block_m_idx][band_m_idx] ); + hMcMasa->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->energy_fx[block_m_idx][band_m_idx], hMcMasa->energy_e[block_m_idx][band_m_idx], temp, shl( c_e, 1 ), &hMcMasa->energy_e[block_m_idx][band_m_idx] ); + move32(); } } } @@ -976,7 +1011,9 @@ void ivas_mcmasa_param_est_ana_fx( FOR( i = 0; i < num_freq_bands; i++ ) { brange[0] = hMcMasa->band_grouping[i]; + move16(); brange[1] = hMcMasa->band_grouping[i + 1]; + move16(); FOR( j = brange[0]; j < brange[1]; j++ ) { compute_cov_mtx_fx( Chnl_RealBuffer_fx, Chnl_ImagBuffer_fx, j, numAnalysisChannels, &( COVls[i] ), c_e ); @@ -1057,45 +1094,55 @@ void ivas_mcmasa_param_est_ana_fx( /* Direction estimation */ computeIntensityVector_ana_fx( hMcMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, num_freq_bands, intensity_real_fx ); /*2+q-31*/ - computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], 2 * c_e ); /*Q30*/ + computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], intensity_real_fx[2], 0, num_freq_bands, direction_vector_fx[0], direction_vector_fx[1], direction_vector_fx[2], shl( c_e, 1 ) ); /*Q30*/ /* Power and intensity estimation for diffuseness */ computeIntensityVector_ana_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, num_freq_bands, intensity_even_real_fx ); /*2*(q)-31*/ computeReferencePower_ana_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, reference_power_fx[ts], num_freq_bands ); /*2*q-30*/ /* Fill buffers of length "averaging_length" time slots for intensity and energy */ - hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ + hMcMasa->index_buffer_intensity = add( ( hMcMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ), 1 ); /* averaging_length = 32 */ index = hMcMasa->index_buffer_intensity; + move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ Copy32( intensity_even_real_fx[i], &( hMcMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); } - hMcMasa->buffer_intensity_real_q[index - 1] = 2 * inp_q - 31; - Copy32( reference_power_fx[ts], &( hMcMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); - hMcMasa->buffer_energy_q[index - 1] = 2 * inp_q - 30; + hMcMasa->buffer_intensity_real_q[index - 1] = sub( shl( inp_q, 1 ), 31 ); + move16(); + Copy32( reference_power_fx[ts], &( hMcMasa->buffer_energy_fx[i_mult( index - 1, num_freq_bands )] ), num_freq_bands ); + hMcMasa->buffer_energy_q[index - 1] = sub( shl( inp_q, 1 ), 30 ); + move16(); computeDiffuseness_fixed( hMcMasa->buffer_intensity_real_fx, hMcMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hMcMasa->buffer_intensity_real_q, hMcMasa->buffer_energy_q, out_exp ); /* Compute vertical diffuseness, and tune original diffuseness if needed */ IF( !hMcMasa->isHorizontalSetup ) { Copy32( intensity_real_fx[2], &( hMcMasa->buffer_intensity_real_vert_fx[index - 1][0] ), num_freq_bands ); - hMcMasa->buffer_intensity_real_vert_q[index - 1] = 2 * inp_q - 31; + hMcMasa->buffer_intensity_real_vert_q[index - 1] = sub( shl( inp_q, 1 ), 31 ); + move16(); computeVerticalDiffuseness_fx( hMcMasa->buffer_intensity_real_vert_fx, hMcMasa->buffer_energy_fx, num_freq_bands, vertical_diffuseness_vector_fx, hMcMasa->buffer_intensity_real_vert_q, hMcMasa->buffer_energy_q ); v_min_fx( diffuseness_vector_fx, out_exp, vertical_diffuseness_vector_fx, q_vdv, diffuseness_vector_fx, out_exp, num_freq_bands ); } FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { norm_tmp_fx = L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ), 1 ); /*2q-30*/ - hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), 2 * c_e, &hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); - hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), 2 * c_e, &hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); - hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), 2 * c_e, &hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] ); - diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 1 ), 2 * c_e - 1, &diffuseness_e[band_m_idx] ); - renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], 2 * c_e - 1, &renormalization_factor_diff_e[band_m_idx] ); + hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), shl( c_e, 1 ), &hMcMasa->direction_vector_e[0][block_m_idx][band_m_idx] ); + hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), shl( c_e, 1 ), &hMcMasa->direction_vector_e[1][block_m_idx][band_m_idx] ); + hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hMcMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx], Mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), shl( c_e, 1 ), &hMcMasa->direction_vector_e[2][block_m_idx][band_m_idx] ); + diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( diffuseness_m_fx[band_m_idx], diffuseness_e[band_m_idx], L_shl( Mult_32_32( reference_power_fx[ts][band_m_idx], diffuseness_vector_fx[band_m_idx] ), 1 ), sub( shl( c_e, 1 ), 1 ), &diffuseness_e[band_m_idx] ); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_e[band_m_idx], reference_power_fx[ts][band_m_idx], sub( shl( c_e, 1 ), 1 ), &renormalization_factor_diff_e[band_m_idx] ); + move32(); + move32(); + move32(); + move32(); + move32(); } } FOR( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) { Word16 max_e = MIN_16; + move16(); FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { max_e = s_max( max_e, hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx] ); @@ -1103,11 +1150,13 @@ void ivas_mcmasa_param_est_ana_fx( max_e = add( max_e, 1 ); /*1 as guard bit to prevent overflow*/ FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v_fx[d] = L_shr( hMcMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx], max_e - hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx] ); + dir_v_fx[d] = L_shr( hMcMasa->direction_vector_m_fx[d][block_m_idx][band_m_idx], sub( max_e, hMcMasa->direction_vector_e[d][block_m_idx][band_m_idx] ) ); + move32(); } Word16 div_q = sub( 31, max_e ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, div_q, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); elevation_m_values_fx[block_m_idx][band_m_idx] = L_add( elevation_m_values_fx[block_m_idx][band_m_idx], L_shr( elevation_m_values_fx[block_m_idx][band_m_idx], 5 ) ); + move32(); } /* Coherence processing */ @@ -1118,30 +1167,40 @@ void ivas_mcmasa_param_est_ana_fx( { FOR( j = i; j < numAnalysisChannels; j++ ) { - Word32 temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( COVls[band_m_idx].xr_fx[i][j], COVls[band_m_idx].xr_fx[i][j] ), 2 * COVls[band_m_idx].xr_e[i][j], Mult_32_32( COVls[band_m_idx].xi_fx[i][j], COVls[band_m_idx].xi_fx[i][j] ), 2 * COVls[band_m_idx].xi_e[i][j], &absCOVls_e[i][j] ); + Word32 temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( COVls[band_m_idx].xr_fx[i][j], COVls[band_m_idx].xr_fx[i][j] ), shl( COVls[band_m_idx].xr_e[i][j], 1 ), Mult_32_32( COVls[band_m_idx].xi_fx[i][j], COVls[band_m_idx].xi_fx[i][j] ), shl( COVls[band_m_idx].xi_e[i][j], 1 ), &absCOVls_e[i][j] ); absCOVls_fx[i][j] = Sqrt32( temp, &absCOVls_e[i][j] ); + move32(); } lsEnergy_fx[i] = absCOVls_fx[i][i]; + move32(); lsEnergy_e[i] = absCOVls_e[i][i]; + move16(); } /* Find loudest channel */ maxEne_fx = lsEnergy_fx[0]; + move32(); maxEne_e = lsEnergy_e[0]; + move16(); loudestCh = 0; FOR( i = 1; i < numAnalysisChannels; i++ ) { IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( lsEnergy_fx[i], lsEnergy_e[i], maxEne_fx, maxEne_e ), 1 ) ) { maxEne_fx = lsEnergy_fx[i]; + move32(); maxEne_e = lsEnergy_e[i]; + move16(); loudestCh = i; + move16(); } } /* Compute surrounding coherence */ surrCoh_fx = ONE_IN_Q31; + move32(); surrCoh_e = 0; + move16(); FOR( i = 0; i < numAnalysisChannels; i++ ) { IF( NE_16( i, loudestCh ) ) @@ -1149,36 +1208,56 @@ void ivas_mcmasa_param_est_ana_fx( IF( LT_16( i, loudestCh ) ) { i1 = i; + move16(); i2 = loudestCh; + move16(); } ELSE { i1 = loudestCh; + move16(); i2 = i; + move16(); } - Word16 temp_exp = lsEnergy_e[i1] + lsEnergy_e[i2]; + Word16 temp_exp = add( lsEnergy_e[i1], lsEnergy_e[i2] ); Word32 temp = Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i2] ), EPSILON_FX ), &temp_exp ); tempCoh_e = 0; + move16(); tempCoh_fx = L_shl( BASOP_Util_Divide3232_Scale( absCOVls_fx[i1][i2], temp, &tempCoh_e ), 16 ); - tempCoh_e = absCOVls_e[i1][i2] - temp_exp + tempCoh_e; + tempCoh_e = add( sub( absCOVls_e[i1][i2], temp_exp ), tempCoh_e ); IF( NE_16( BASOP_Util_Cmp_Mant32Exp( surrCoh_fx, surrCoh_e, tempCoh_fx, tempCoh_e ), -1 ) ) { surrCoh_fx = tempCoh_fx; + move32(); surrCoh_e = tempCoh_e; + move16(); } } } surrCoh_fx = L_shl( surrCoh_fx, surrCoh_e ); surrCoh_e = 0; + move16(); surrCoh_fx = Mult_32_32( surrCoh_fx, surrCoh_fx ); - surrCoh_fx = ( LT_32( surrCoh_fx, ONE_IN_Q31 ) ) ? surrCoh_fx : ONE_IN_Q31; - surrCoh_fx = ( GT_32( surrCoh_fx, 0 ) ) ? surrCoh_fx : 0; + IF( LT_32( surrCoh_fx, ONE_IN_Q31 ) ) + { + surrCoh_fx = surrCoh_fx; + move32(); + } + ELSE + { + surrCoh_fx = ONE_IN_Q31; + move32(); + } + surrCoh_fx = L_max( surrCoh_fx, 0 ); /* Compute spread coherence */ IF( LT_32( elevation_m_values_fx[block_m_idx][band_m_idx], NEAR_HORIZONTAL_PLANE_ELEVATION_FX ) ) /* Computed only near horizontal plane */ { minAngleDist_fx = 754974720; /*Q22*/ + move32(); i1 = 0; + move16(); currentAzi_fx = azimuth_m_values_fx[block_m_idx][band_m_idx]; + move32(); FOR( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) { angleDist_fx = L_abs( L_sub( currentAzi_fx, hMcMasa->ls_azimuth_fx[i] ) ); @@ -1189,13 +1268,17 @@ void ivas_mcmasa_param_est_ana_fx( IF( LT_32( angleDist_fx, minAngleDist_fx ) ) { minAngleDist_fx = angleDist_fx; + move32(); i1 = i; + move16(); } } i2 = hMcMasa->leftNearest[i1]; + move16(); i3 = hMcMasa->rightNearest[i1]; + move16(); Word16 temp_e = add( lsEnergy_e[i2], lsEnergy_e[i3] ); - Word32 temp = Sqrt32( Mult_32_32( lsEnergy_fx[i2], lsEnergy_fx[i3] ) + EPSILON_FX, &temp_e ); + Word32 temp = Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i2], lsEnergy_fx[i3] ), EPSILON_FX ), &temp_e ); IF( LT_16( i2, i3 ) ) { stereoCoh_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i2][i3], temp, &stereoCoh_e ); @@ -1214,9 +1297,10 @@ void ivas_mcmasa_param_est_ana_fx( temp2 = L_add( temp2, EPSILON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp1, temp2, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp1_e, temp2_e ) ); - lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); stereoness_fx = Mult_32_32( stereoCoh_fx, lsEnergyRelation_fx ); stereoness_e = stereoCoh_e; + move16(); IF( LT_16( i1, i2 ) ) { temp_e = add( lsEnergy_e[i1], lsEnergy_e[i2] ); @@ -1232,13 +1316,13 @@ void ivas_mcmasa_param_est_ana_fx( tempCoh_fx = L_shl( tempCoh_fx, 16 ); IF( LT_16( i1, i3 ) ) { - temp_e = lsEnergy_e[i1] + lsEnergy_e[i3]; + temp_e = add( lsEnergy_e[i1], lsEnergy_e[i3] ); tempCoh2_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i1][i3], ( Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i3] ), EPSILON_FX ), &temp_e ) ), &tempCoh2_e ); tempCoh2_e = add( tempCoh2_e, sub( absCOVls_e[i1][i3], temp_e ) ); } ELSE { - temp_e = lsEnergy_e[i1] + lsEnergy_e[i3]; + temp_e = add( lsEnergy_e[i1], lsEnergy_e[i3] ); tempCoh2_fx = BASOP_Util_Divide3232_Scale( absCOVls_fx[i3][i1], ( Sqrt32( L_add( Mult_32_32( lsEnergy_fx[i1], lsEnergy_fx[i3] ), EPSILON_FX ), &temp_e ) ), &tempCoh2_e ); tempCoh2_e = add( tempCoh2_e, sub( absCOVls_e[i3][i1], temp_e ) ); } @@ -1246,82 +1330,129 @@ void ivas_mcmasa_param_est_ana_fx( IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tempCoh_fx, tempCoh_e, tempCoh2_fx, tempCoh2_e ), -1 ) ) { cohPanCoh_fx = tempCoh_fx; + move32(); cohPanCoh_e = tempCoh_e; + move16(); } ELSE { cohPanCoh_fx = tempCoh2_fx; + move32(); cohPanCoh_e = tempCoh2_e; + move16(); } cohPanCoh_fx = L_shl( cohPanCoh_fx, cohPanCoh_e ); /*Q31*/ cohPanCoh_e = 0; + move16(); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i2], L_add( lsEnergy_fx[i1], EPSILON_FX ), &lsEnergyRelation_e ); - lsEnergyRelation_e += lsEnergy_e[i2] - lsEnergy_e[i1]; + lsEnergyRelation_e = add( lsEnergyRelation_e, sub( lsEnergy_e[i2], lsEnergy_e[i1] ) ); tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i1], L_add( lsEnergy_fx[i2], EPSILON_FX ), &tempLsEnergyRelation_e ); - tempLsEnergyRelation_e += lsEnergy_e[i1] - lsEnergy_e[i2]; + tempLsEnergyRelation_e = add( tempLsEnergyRelation_e, sub( lsEnergy_e[i1], lsEnergy_e[i2] ) ); IF( NE_16( BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ), -1 ) ) { lsEnergyRelation_fx = tempLsEnergyRelation_fx; + move32(); lsEnergyRelation_e = tempLsEnergyRelation_e; + move16(); } tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i3], L_add( lsEnergy_fx[i1], EPSILON_FX ), &tempLsEnergyRelation_e ); tempLsEnergyRelation_e = add( tempLsEnergyRelation_e, sub( lsEnergy_e[i3], lsEnergy_e[i1] ) ); IF( NE_16( BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ), -1 ) ) { lsEnergyRelation_fx = tempLsEnergyRelation_fx; + move32(); lsEnergyRelation_e = tempLsEnergyRelation_e; + move16(); } - tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i1], ( lsEnergy_fx[i3] + EPSILON_FX ), &tempLsEnergyRelation_e ); + tempLsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( lsEnergy_fx[i1], L_add( lsEnergy_fx[i3], EPSILON_FX ), &tempLsEnergyRelation_e ); tempLsEnergyRelation_e = add( tempLsEnergyRelation_e, sub( lsEnergy_e[i1], lsEnergy_e[i3] ) ); IF( NE_16( BASOP_Util_Cmp_Mant32Exp( lsEnergyRelation_fx, lsEnergyRelation_e, tempLsEnergyRelation_fx, tempLsEnergyRelation_e ), -1 ) ) { lsEnergyRelation_fx = tempLsEnergyRelation_fx; + move32(); lsEnergyRelation_e = tempLsEnergyRelation_e; + move16(); } - lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); /*Q31*/ - cohwideness_fx = Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ); /*cohPanCoh_e*/ + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); /*Q31*/ + cohwideness_fx = Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ); /*cohPanCoh_e*/ IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( cohwideness_fx, cohPanCoh_e, stereoness_fx, stereoness_e ), 1 ) ) { spreadCoh_fx = cohwideness_fx; + move32(); spreadCoh_e = cohPanCoh_e; + move16(); } ELSE { spreadCoh_fx = stereoness_fx; + move32(); spreadCoh_e = stereoness_e; + move16(); } - IF( LT_16( spreadCoh_e, 0 ) ) + IF( ( spreadCoh_e < 0 ) ) { spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); spreadCoh_e = 0; + move16(); } - IF( GT_32( spreadCoh_fx, L_shl_sat( 1, 31 - spreadCoh_e - 1 /*0.5f with exp=spreadCoh_e*/ ) ) ) + IF( GT_32( spreadCoh_fx, L_shl_sat( 1, sub( 30, spreadCoh_e ) /*0.5f with exp=spreadCoh_e*/ ) ) ) { IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( cohwideness_fx, cohPanCoh_e, stereoness_fx, stereoness_e ), 1 ) ) { - tempCoh_fx = BASOP_Util_Add_Mant32Exp( stereoness_fx, stereoness_e, -L_sub( cohwideness_fx, L_shl( 1, 31 - cohPanCoh_e - 1 ) ), cohPanCoh_e, &tempCoh_e ); - IF( LT_16( tempCoh_e, 0 ) ) + tempCoh_fx = BASOP_Util_Add_Mant32Exp( stereoness_fx, stereoness_e, L_negate( L_sub( cohwideness_fx, L_shl( 1, sub( 30, cohPanCoh_e ) ) ) ), cohPanCoh_e, &tempCoh_e ); + IF( ( tempCoh_e < 0 ) ) { tempCoh_fx = L_shl( tempCoh_fx, tempCoh_e ); tempCoh_e = 0; + move16(); + } + IF( GT_32( tempCoh_fx, L_shl_sat( 1, sub( 30, tempCoh_e ) ) ) ) + { + spreadCoh_fx = tempCoh_fx; + move32(); + } + ELSE + { + spreadCoh_fx = L_shl_sat( 1, sub( 30, tempCoh_e ) ); } - spreadCoh_fx = GT_32( tempCoh_fx, L_shl_sat( 1, 31 - tempCoh_e - 1 ) ) ? tempCoh_fx : L_shl_sat( 1, 31 - tempCoh_e - 1 ); spreadCoh_e = tempCoh_e; + move16(); } } - IF( LT_16( spreadCoh_e, 0 ) ) + IF( ( spreadCoh_e < 0 ) ) { spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); spreadCoh_e = 0; + move16(); + } + + IF( ( LT_32( spreadCoh_fx, L_shl_sat( 1, sub( 31, spreadCoh_e ) ) ) ) ) + { + spreadCoh_fx = spreadCoh_fx; + move32(); + } + ELSE + { + spreadCoh_fx = L_shl_sat( 1, sub( 31, spreadCoh_e ) ); + } + IF( ( spreadCoh_fx > 0 ) ) + { + spreadCoh_fx = spreadCoh_fx; + move32(); + } + ELSE + { + spreadCoh_fx = 0; + move32(); } - spreadCoh_fx = ( LT_32( spreadCoh_fx, L_shl_sat( 1, 31 - spreadCoh_e ) ) ) ? spreadCoh_fx : L_shl_sat( 1, 31 - spreadCoh_e ); - spreadCoh_fx = ( spreadCoh_fx > 0 ) ? spreadCoh_fx : 0; spreadCoh_fx = L_shl( spreadCoh_fx, spreadCoh_e ); /*Q31*/ /* Compute energy ratio tuning parameter */ lsEnergySum_fx = 0; + move32(); lsEnergySum_e = 0; + move16(); FOR( i = 0; i < numAnalysisChannels; i++ ) { lsEnergySum_fx = BASOP_Util_Add_Mant32Exp( lsEnergy_fx[i], lsEnergy_e[i], lsEnergySum_fx, lsEnergySum_e, &lsEnergySum_e ); @@ -1329,23 +1460,55 @@ void ivas_mcmasa_param_est_ana_fx( lsEnergySum_fx = L_add_sat( lsEnergySum_fx, EPSILON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp1, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp1_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp2, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp2_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, 16 + lsEnergyRelation_e ); + lsEnergyRelation_fx = L_shl( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); - cohRatio_fx = GT_32( stereoRatio_fx, cohPanRatio_fx ) ? stereoRatio_fx : cohPanRatio_fx; /*Q31*/ - cohRatio_fx = ( LT_32( cohRatio_fx, ONE_IN_Q31 ) ) ? cohRatio_fx : ONE_IN_Q31; - cohRatio_fx = ( GT_32( cohRatio_fx, 0 ) ) ? cohRatio_fx : 0; + IF( GT_32( stereoRatio_fx, cohPanRatio_fx ) ) + { + cohRatio_fx = stereoRatio_fx; + move32(); + } + ELSE + { + cohRatio_fx = cohPanRatio_fx; + move32(); + } + + IF( LT_32( cohRatio_fx, ONE_IN_Q31 ) ) + { + cohRatio_fx = cohRatio_fx; + move32(); + } + ELSE + { + cohRatio_fx = ONE_IN_Q31; + move32(); + } + + IF( cohRatio_fx > 0 ) + { + cohRatio_fx = cohRatio_fx; + move32(); + } + ELSE + { + cohRatio_fx = 0; + move32(); + } } ELSE /* Otherwise, set spread coherence to zero */ { spreadCoh_fx = 0; + move32(); cohRatio_fx = 0; + move32(); lsEnergySum_fx = 0; + move32(); FOR( i = 0; i < numAnalysisChannels; i++ ) { lsEnergySum_fx = BASOP_Util_Add_Mant32Exp( lsEnergy_fx[i], lsEnergy_e[i], lsEnergySum_fx, lsEnergySum_e, &lsEnergySum_e ); @@ -1354,9 +1517,12 @@ void ivas_mcmasa_param_est_ana_fx( } /* Store values */ - spreadCoherence_fx[block_m_idx][band_m_idx] = spreadCoh_fx; /*Q31*/ + spreadCoherence_fx[block_m_idx][band_m_idx] = spreadCoh_fx; /*Q31*/ + move32(); surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; /*Q31*/ - coherentEnergyRatio_fx[band_m_idx] = cohRatio_fx; /*Q31*/ + move32(); + coherentEnergyRatio_fx[band_m_idx] = cohRatio_fx; /*Q31*/ + move32(); } /* Determine energy ratios */ @@ -1366,16 +1532,29 @@ void ivas_mcmasa_param_est_ana_fx( IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { diffuseness_m_fx[band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); + move32(); diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); - diffuseness_m_fx[band_m_idx] = L_shl_sat( diffuseness_m_fx[band_m_idx], 16 + diffuseness_m_e ); + diffuseness_m_fx[band_m_idx] = L_shl_sat( diffuseness_m_fx[band_m_idx], add( 16, diffuseness_m_e ) ); + move32(); } ELSE { diffuseness_m_fx[band_m_idx] = 0; + move32(); } energyRatio_fx[block_m_idx][band_m_idx] = L_sub( ONE_IN_Q31, diffuseness_m_fx[band_m_idx] ); - energyRatio_fx[block_m_idx][band_m_idx] = GT_32( energyRatio_fx[block_m_idx][band_m_idx], coherentEnergyRatio_fx[band_m_idx] ) ? energyRatio_fx[block_m_idx][band_m_idx] : coherentEnergyRatio_fx[band_m_idx]; + move32(); + IF( GT_32( energyRatio_fx[block_m_idx][band_m_idx], coherentEnergyRatio_fx[band_m_idx] ) ) + { + energyRatio_fx[block_m_idx][band_m_idx] = energyRatio_fx[block_m_idx][band_m_idx]; + move32(); + } + ELSE + { + energyRatio_fx[block_m_idx][band_m_idx] = coherentEnergyRatio_fx[band_m_idx]; + move32(); + } } } return; @@ -1886,19 +2065,22 @@ static void ivas_mcmasa_dmx_fx( const Word16 nchan_transport, const Word16 nchan_inp ) { - int16_t i, j; - int16_t numAnalysisChannels; + Word16 i, j; + Word16 numAnalysisChannels; Word32 dmx_c_fx; Word32 multiChEne_fx, downmixEne_fx; Word32 prevEQ_fx, currEQ_fx, instEQ_fx; Word32 alpha_fx, L_tmp, L_tmp1; Word16 multiChEne_e, scale, downmixEne_e = 0, prevEQ_e, tmp, currEQ_e, instEQ_e; + move16(); - numAnalysisChannels = nchan_inp - 1; + numAnalysisChannels = sub( nchan_inp, 1 ); multiChEne_fx = 0; + move32(); multiChEne_e = 0; + move16(); FOR( j = 0; j < numAnalysisChannels; j++ ) { @@ -1908,47 +2090,54 @@ static void ivas_mcmasa_dmx_fx( L_tmp = Mpy_32_32( L_tmp1, L_tmp1 ); // data_e + data_e multiChEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, scale + scale, multiChEne_fx, multiChEne_e, &scale ); multiChEne_e = scale; + move16(); } } - IF( nchan_transport == 2 ) + IF( EQ_16( nchan_transport, 2 ) ) { Word16 numSideChannels; /* Channels other than left, right, center */ Word16 leftIndex, rightIndex; - numSideChannels = numAnalysisChannels / 2 - 1; + numSideChannels = sub( shr( numAnalysisChannels, 1 ), 1 ); FOR( j = 0; j < numSideChannels; j++ ) { - leftIndex = j * 2 + 3; - rightIndex = j * 2 + 4; + leftIndex = add( shl( j, 1 ), 3 ); + rightIndex = add( shl( j, 1 ), 4 ); FOR( i = 0; i < input_frame; i++ ) { data_f_fx[0][i] = L_add( data_f_fx[0][i], data_f_fx[leftIndex][i] ); + move32(); data_f_fx[1][i] = L_add( data_f_fx[1][i], data_f_fx[rightIndex][i] ); + move32(); } } FOR( i = 0; i < input_frame; i++ ) { - dmx_c_fx = (Word32) W_shr( W_mult_32_32( INV_SQRT2_FX, data_f_fx[2][i] ), 32 ); - + dmx_c_fx = W_extract_h( W_mult_32_32( INV_SQRT2_FX, data_f_fx[2][i] ) ); + move32(); data_f_fx[0][i] = L_add( dmx_c_fx, data_f_fx[0][i] ); + move32(); data_f_fx[1][i] = L_add( dmx_c_fx, data_f_fx[1][i] ); + move32(); } } - ELSE IF( nchan_transport == 1 ) + ELSE IF( EQ_16( nchan_transport, 1 ) ) { FOR( i = 0; i < input_frame; i++ ) { FOR( j = 1; j < numAnalysisChannels; j++ ) { data_f_fx[0][i] = L_add( data_f_fx[0][i], data_f_fx[j][i] ); + move32(); } } } downmixEne_fx = 0; + move32(); FOR( j = 0; j < nchan_transport; j++ ) { @@ -1961,6 +2150,7 @@ static void ivas_mcmasa_dmx_fx( } alpha_fx = 214748364; // Q31 + move32(); L_tmp = Mpy_32_32( alpha_fx, multiChEne_fx ); L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevMultiChEne_fx ); @@ -1972,26 +2162,31 @@ static void ivas_mcmasa_dmx_fx( hMcMasa->prevDownmixEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, downmixEne_e, L_tmp1, hMcMasa->prevDownmixEne_e, &hMcMasa->prevDownmixEne_e ); prevEQ_fx = hMcMasa->prevEQ_fx; + move32(); prevEQ_e = hMcMasa->prevEQ_e; + move16(); tmp = BASOP_Util_Divide3232_Scale( hMcMasa->prevMultiChEne_fx, L_add( hMcMasa->prevDownmixEne_fx, EPSILON_FX ), &scale ); - currEQ_e = scale + ( hMcMasa->prevMultiChEne_e - hMcMasa->prevDownmixEne_e ); + currEQ_e = add( scale, sub( hMcMasa->prevMultiChEne_e, hMcMasa->prevDownmixEne_e ) ); currEQ_fx = Sqrt32( L_deposit_h( tmp ), &currEQ_e ); hMcMasa->prevEQ_fx = currEQ_fx; + move32(); hMcMasa->prevEQ_e = currEQ_e; + move16(); FOR( i = 0; i < input_frame; i++ ) { L_tmp = Mpy_32_32( L_deposit_h( hMcMasa->interpolator_fx[i] ), currEQ_fx ); L_tmp1 = L_sub( 1073741824, L_lshr( L_deposit_h( hMcMasa->interpolator_fx[i] ), 1 ) ); L_tmp1 = Mpy_32_32( L_tmp1, prevEQ_fx ); - instEQ_fx = BASOP_Util_Add_Mant32Exp( L_tmp, currEQ_e, L_tmp1, prevEQ_e + 1, &instEQ_e ); + instEQ_fx = BASOP_Util_Add_Mant32Exp( L_tmp, currEQ_e, L_tmp1, add( prevEQ_e, 1 ), &instEQ_e ); FOR( j = 0; j < nchan_transport; j++ ) { data_f_fx[j][i] = Mpy_32_32( instEQ_fx, data_f_fx[j][i] ); - + move32(); + move32(); data_f_fx[j][i] = L_shl( data_f_fx[j][i], instEQ_e ); } } @@ -2031,12 +2226,14 @@ static void compute_cov_mtx_fx( d = si[j][freq]; norm_c = norm_l( c ); norm_d = norm_l( d ); - c = L_shl( c, norm_c ); /*inp_exp-norm_c*/ - d = L_shl( d, norm_d ); /*inp_exp-norm_d*/ - temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( a, c ), 2 * inp_exp - norm_a - norm_c, Mult_32_32( b, d ), 2 * inp_exp - norm_b - norm_d, &shift ); /*exp=inp_exp-norm_ab+inp_exp-norm_cd*/ + c = L_shl( c, norm_c ); /*inp_exp-norm_c*/ + d = L_shl( d, norm_d ); /*inp_exp-norm_d*/ + temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( a, c ), sub( shl( inp_exp, 1 ), add( norm_a, norm_c ) ), Mult_32_32( b, d ), sub( shl( inp_exp, 1 ), add( norm_b, norm_d ) ), &shift ); /*exp=inp_exp-norm_ab+inp_exp-norm_cd*/ COVls->xr_fx[i][j] = BASOP_Util_Add_Mant32Exp( COVls->xr_fx[i][j], COVls->xr_e[i][j], temp, shift, &COVls->xr_e[i][j] ); - temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( b, c ), 2 * inp_exp - norm_b - norm_c, -Mult_32_32( a, d ), 2 * inp_exp - norm_a - norm_d, &shift ); + move32(); + temp = BASOP_Util_Add_Mant32Exp( Mult_32_32( b, c ), sub( shl( inp_exp, 1 ), add( norm_b, norm_c ) ), L_negate( Mult_32_32( a, d ) ), sub( shl( inp_exp, 1 ), add( norm_a, norm_d ) ), &shift ); COVls->xi_fx[i][j] = BASOP_Util_Add_Mant32Exp( COVls->xi_fx[i][j], COVls->xi_e[i][j], temp, shift, &COVls->xi_e[i][j] ); + move32(); } } @@ -2092,6 +2289,7 @@ static void computeVerticalDiffuseness_fx( Word32 energy_slow[MASA_FREQUENCY_BANDS]; Word16 i, k; Word32 tmp = 0; + move32(); const Word32 *p_tmp_c; Word16 intensity_slow_e[MASA_FREQUENCY_BANDS], energy_slow_e[MASA_FREQUENCY_BANDS]; @@ -2104,17 +2302,19 @@ static void computeVerticalDiffuseness_fx( FOR( i = 0; i < DIRAC_NO_COL_AVG_DIFF; ++i ) { /* Energy slow */ - p_tmp_c = buffer_energy + i * num_freq_bands; + p_tmp_c = buffer_energy + i_mult( i, num_freq_bands ); FOR( k = 0; k < num_freq_bands; k++ ) { - energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k], *( p_tmp_c ), 31 - buffer_energy_q[i], &energy_slow_e[k] ); /*q=min_q*/ + energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k], *( p_tmp_c ), sub( 31, buffer_energy_q[i] ), &energy_slow_e[k] ); /*q=min_q*/ + move32(); p_tmp_c++; } /* Intensity slow */ FOR( k = 0; k < num_freq_bands; k++ ) { - intensity_slow[k] = BASOP_Util_Add_Mant32Exp( intensity_slow[k], intensity_slow_e[k], buffer_intensity[i][k], 31 - buffer_intensity_q[i], &intensity_slow_e[k] ); /*q=min_q*/ + intensity_slow[k] = BASOP_Util_Add_Mant32Exp( intensity_slow[k], intensity_slow_e[k], buffer_intensity[i][k], sub( 31, buffer_intensity_q[i] ), &intensity_slow_e[k] ); /*q=min_q*/ + move32(); } } @@ -2122,30 +2322,34 @@ static void computeVerticalDiffuseness_fx( FOR( k = 0; k < num_freq_bands; k++ ) { intensity_slow_abs[k] = L_abs( intensity_slow[k] ); /*min_q*/ + move32(); } /* Compute Diffuseness */ FOR( i = 0; i < num_freq_bands; ++i ) { Word16 tmp_e1, tmp_e2; - tmp = BASOP_Util_Divide3232_Scale( intensity_slow_abs[i], ( energy_slow[i] + EPSILON_FX_SMALL ), &tmp_e1 ); - tmp_e1 += intensity_slow_e[i] - energy_slow_e[i]; - tmp = BASOP_Util_Divide3232_Scale( tmp - L_shr( VERTICAL_ENERGY_RATIO_OFFSET_FX, tmp_e1 ), ONE_IN_Q15 - VERTICAL_ENERGY_RATIO_OFFSET_FX, &tmp_e2 ); /* Tuned to avoid effect due to ambience of vertically un-even setups */ - tmp_e2 += tmp_e1; - tmp = L_sub( L_shl( 1, 15 - tmp_e2 ), tmp ); + tmp = BASOP_Util_Divide3232_Scale( intensity_slow_abs[i], L_add( energy_slow[i], EPSILON_FX_SMALL ), &tmp_e1 ); + tmp_e1 = add( tmp_e1, sub( intensity_slow_e[i], energy_slow_e[i] ) ); + tmp = BASOP_Util_Divide3232_Scale( L_sub( tmp, L_shr( VERTICAL_ENERGY_RATIO_OFFSET_FX, tmp_e1 ) ), L_sub( ONE_IN_Q15, VERTICAL_ENERGY_RATIO_OFFSET_FX ), &tmp_e2 ); /* Tuned to avoid effect due to ambience of vertically un-even setups */ + tmp_e2 = add( tmp_e2, tmp_e1 ); + tmp = L_sub( L_shl( 1, sub( 15, tmp_e2 ) ), tmp ); IF( tmp < 0 ) { tmp = 0; + move32(); } - ELSE IF( tmp >= L_shl( 1, 15 - tmp_e2 ) ) + ELSE IF( GE_32( tmp, L_shl( 1, sub( 15, tmp_e2 ) ) ) ) { tmp = ONE_IN_Q31; + move32(); } ELSE { - tmp = L_shl( tmp, 16 + tmp_e2 ); + tmp = L_shl( tmp, add( 16, tmp_e2 ) ); } diffuseness[i] = tmp; + move32(); } return; @@ -2225,25 +2429,32 @@ static void computeEvenLayout_fx( Word16 numChannelsHalf; lsSpacing = L_shl( L_mult0( 360, div_s( 1, numChannels ) ), 6 ); /*Q.21*/ - oddLayout = numChannels % 2; + oddLayout = (UWord8) s_and( numChannels, 1 ); + move16(); numChannelsHalf = shr( numChannels, 1 ); Copy32( ls_azimuth, ls_azimuth_temp, numChannels ); Scale_sig32( ls_azimuth_temp, numChannels, -1 ); /*Q.21*/ FOR( i = 0; i < numChannels; i++ ) { - smallestAzimuth = L_shl( 1000, 21 ); /*Q21*/ + smallestAzimuth = 1000 << 21; /*Q21*/ + move32(); smallestAzimuthIndex = 0; + move16(); FOR( j = 0; j < numChannels; j++ ) { IF( LT_32( ls_azimuth_temp[j], smallestAzimuth ) ) { smallestAzimuth = ls_azimuth_temp[j]; + move32(); smallestAzimuthIndex = j; + move16(); } } ls_azimuth_order[i] = smallestAzimuthIndex; - ls_azimuth_temp[smallestAzimuthIndex] = L_shl( 1000, 21 ); + move32(); + ls_azimuth_temp[smallestAzimuthIndex] = ( 1000 << 21 ); + move32(); } IF( oddLayout ) @@ -2258,11 +2469,13 @@ static void computeEvenLayout_fx( FOR( i = 0; i < numChannels; i++ ) { ls_azimuth_even_ordered[i] = W_extract_l( W_add( W_mult_32_16( lsSpacing, i ), startAzimuth ) ); /*Q.22*/ + move32(); } FOR( i = 0; i < numChannels; i++ ) { ls_azimuth_even[ls_azimuth_order[i]] = L_shl( L_shr( L_add( ls_azimuth_even_ordered[i], ONE_IN_Q21 ), 22 ), 22 ); /*((a+2^21)/2^22)*2^22*/ + move32(); } return; @@ -2432,64 +2645,83 @@ void ivas_create_masa_out_meta_fx( ) { - const uint8_t ivasmasaFormatDescriptor[8] = { 0x49, 0x56, 0x41, 0x53, 0x4D, 0x41, 0x53, 0x41 }; /* "IVASMASA" */ - int16_t i, sf, band; - uint8_t numFrequencyBands; - uint8_t numDirections; - uint16_t spherical_index; + const UWord8 ivasmasaFormatDescriptor[8] = { 0x49, 0x56, 0x41, 0x53, 0x4D, 0x41, 0x53, 0x41 }; /* "IVASMASA" */ + Word16 i, sf, band; + UWord8 numFrequencyBands; + UWord8 numDirections; + UWord16 spherical_index; numDirections = 1; + move16(); numFrequencyBands = MASA_FREQUENCY_BANDS; + move16(); /* Construct descriptive meta */ - for ( i = 0; i < 8; i++ ) + FOR( i = 0; i < 8; i++ ) { extOutMeta->descriptiveMeta.formatDescriptor[i] = ivasmasaFormatDescriptor[i]; + move16(); } - extOutMeta->descriptiveMeta.numberOfDirections = numDirections - 1; - extOutMeta->descriptiveMeta.numberOfChannels = (uint8_t) ( nchan_transport - 1 ); + extOutMeta->descriptiveMeta.numberOfDirections = (UWord8) sub( numDirections, 1 ); + move16(); + extOutMeta->descriptiveMeta.numberOfChannels = (UWord8) sub( nchan_transport, 1 ); + move16(); /* Following correspond to "unknown" values */ extOutMeta->descriptiveMeta.sourceFormat = 0x0u; + move16(); extOutMeta->descriptiveMeta.transportDefinition = 0x0u; + move16(); extOutMeta->descriptiveMeta.channelAngle = 0x0u; + move16(); extOutMeta->descriptiveMeta.channelDistance = 0x0u; + move16(); extOutMeta->descriptiveMeta.channelLayout = 0x0u; + move16(); /* Construct spatial metadata from estimated values */ - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { /* Spherical index */ - for ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { spherical_index = index_theta_phi_16_fx( &elevation_m_values[sf][band], &azimuth_m_values[sf][band], Sph_Grid16 ); + move16(); extOutMeta->directionIndex[0][sf][band] = spherical_index; + move16(); extOutMeta->directionIndex[1][sf][band] = SPH_IDX_FRONT; + move16(); } /* Direct-to-total ratio */ - for ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { - extOutMeta->directToTotalRatio[0][sf][band] = (uint8_t) L_shr( energyRatio[sf][band], energyRatio_q - 8 ); + extOutMeta->directToTotalRatio[0][sf][band] = (UWord8) L_shr( energyRatio[sf][band], sub( energyRatio_q, 8 ) ); + move16(); extOutMeta->directToTotalRatio[1][sf][band] = 0; + move16(); } /* Spread coherence */ - for ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { - extOutMeta->spreadCoherence[0][sf][band] = (uint8_t) L_shr( spreadCoherence[sf][band], spreadCoherence_q - 8 ); + extOutMeta->spreadCoherence[0][sf][band] = (UWord8) L_shr( spreadCoherence[sf][band], sub( spreadCoherence_q, 8 ) ); + move16(); extOutMeta->spreadCoherence[1][sf][band] = 0; + move16(); } /* Diffuse-to-total ratio = 1 - sum(direct-to-total ratios) */ - for ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { - extOutMeta->diffuseToTotalRatio[sf][band] = UINT8_MAX - (uint8_t) L_shr( energyRatio[sf][band], energyRatio_q - 8 ); + extOutMeta->diffuseToTotalRatio[sf][band] = (UWord8) sub( UINT8_MAX, (UWord8) L_shr( energyRatio[sf][band], sub( energyRatio_q, 8 ) ) ); + move16(); } /* Surround coherence */ - for ( band = 0; band < numFrequencyBands; band++ ) + FOR( band = 0; band < numFrequencyBands; band++ ) { - extOutMeta->surroundCoherence[sf][band] = (uint8_t) L_shr( surroundingCoherence[sf][band], surroundingCoherence_q - 8 ); + extOutMeta->surroundCoherence[sf][band] = (UWord8) L_shr( surroundingCoherence[sf][band], sub( surroundingCoherence_q, 8 ) ); + move16(); } } diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 70a9cad1069708ec2c93baf7d72e0b2690bd8ae5..b2ebebb87b8c8dd787ee9de5f8d4db77a03f7b7d 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -130,33 +130,35 @@ ivas_error ivas_td_binaural_open_unwrap_fx( move16(); /* Mixer spatial setup */ pBinRendTd->TdRend_MixSpatSpec_p->UseCommonDistAttenModel = TRUE; + move16(); pBinRendTd->TdRend_MixSpatSpec_p->DistAttenModel = 0; /* 0=Turned off, else use TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED */ move16(); - IF( ( error = TDREND_MIX_Init_fx( pBinRendTd, hHrtfTD, pBinRendTd->TdRend_MixSpatSpec_p, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_Init_fx( pBinRendTd, hHrtfTD, pBinRendTd->TdRend_MixSpatSpec_p, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } /* Set the attenuation (or can set MixSpatSpec.DistAttenModel above) */ - IF( ( error = TDREND_MIX_SetDistAttenModel( pBinRendTd, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SetDistAttenModel( pBinRendTd, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ), IVAS_ERR_OK ) ) { return error; } /* Add sources to module and mixer, headphones */ PosType = TDREND_POSTYPE_ABSOLUTE; /* or TDREND_POSTYPE_RELATIVE_TO_LISTENER */ - + move16(); nchan_rend = nchan_transport; move16(); - IF( EQ_16( ivas_format, MC_FORMAT ) && NE_16( transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + test(); + if ( EQ_16( ivas_format, MC_FORMAT ) && NE_16( 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( nS = 0; nS < nchan_rend; nS++ ) { - IF( ( error = TDREND_MIX_AddSrc_fx( pBinRendTd, &SrcInd[nS], PosType ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_AddSrc_fx( pBinRendTd, &SrcInd[nS], PosType ) ), IVAS_ERR_OK ) ) { return error; } @@ -216,26 +218,27 @@ ivas_error ivas_td_binaural_open_unwrap_fx( move32(); // TDREND_SRC_SPATIAL_t *SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p; - IF( ( error = TDREND_MIX_SRC_SetPos_fx( pBinRendTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetPos_fx( pBinRendTd, nS, Pos_fx ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = TDREND_MIX_SRC_SetDir_fx( pBinRendTd, nS, Dir_fx, Q30 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetDir_fx( pBinRendTd, nS, Dir_fx, Q30 ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = TDREND_MIX_SRC_SetPlayState( pBinRendTd, nS, TDREND_PLAYSTATUS_PLAYING ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetPlayState( pBinRendTd, nS, TDREND_PLAYSTATUS_PLAYING ) ), IVAS_ERR_OK ) ) { return error; } /*TDREND_SRC_SPATIAL_t **/ // SrcSpatial_p = pBinRendTd->Sources[nS]->SrcSpatial_p; - IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ), IVAS_ERR_OK ) ) { return error; } } } - + test(); + test(); IF( EQ_16( ivas_format, ISM_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { DirAtten_p = pBinRendTd->DirAtten_p; @@ -250,14 +253,14 @@ ivas_error ivas_td_binaural_open_unwrap_fx( } ELSE { - DirAtten_p->ConeInnerAngle_fx = L_deposit_h( directivity[nS * 3] ); // 9Q6 -> 9Q22 - DirAtten_p->ConeOuterAngle_fx = L_deposit_h( directivity[nS * 3 + 1] ); // 9Q6 -> 9Q22 - DirAtten_p->ConeOuterGain_fx = L_shr( L_deposit_h( directivity[nS * 3 + 2] ), 1 ); // 0Q15 -> 1Q30 + DirAtten_p->ConeInnerAngle_fx = L_deposit_h( directivity[nS * 3] ); // 9Q6 -> 9Q22 + DirAtten_p->ConeOuterAngle_fx = L_deposit_h( directivity[add( nS * 3, 1 )] ); // 9Q6 -> 9Q22 + DirAtten_p->ConeOuterGain_fx = L_shr( L_deposit_h( directivity[add( nS * 3, 2 )] ), 1 ); // 0Q15 -> 1Q30 } move32(); move32(); move32(); - IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ), IVAS_ERR_OK ) ) { return error; } @@ -265,10 +268,11 @@ ivas_error ivas_td_binaural_open_unwrap_fx( } *hBinRendererTd = pBinRendTd; - + test(); IF( NE_16( ivas_format, MASA_ISM_FORMAT ) && NE_16( ivas_format, SBA_ISM_FORMAT ) ) { *binaural_latency_ns = Mult_32_32( ( *hBinRendererTd )->HrFiltSet_p->latency_s_fx, 1000000000 ); + move32(); } return error; @@ -398,49 +402,25 @@ ivas_error ivas_td_binaural_open_unwrap( DirAtten_p->ConeInnerAngle = 360.0f; DirAtten_p->ConeOuterAngle = 360.0f; DirAtten_p->ConeOuterGain = 1.0f; -#ifdef IVAS_FLOAT_FIXED - DirAtten_p->ConeInnerAngle_fx = DEG_360_IN_Q22; - DirAtten_p->ConeOuterAngle_fx = DEG_360_IN_Q22; - DirAtten_p->ConeOuterGain_fx = ONE_IN_Q30; -#endif if ( ( error = TDREND_MIX_SRC_SetPos( pBinRendTd, nS, Pos ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED - // Can remove this once TDREND_MIX_SRC_SetPos_fx is integrated above. - pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[0] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[0], Q25 ); - pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[1] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[1], Q25 ); - pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p_fx[2] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Pos_p[2], Q25 ); -#endif if ( ( error = TDREND_MIX_SRC_SetDir( pBinRendTd, nS, Dir ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED - // Can remove this once TDREND_MIX_SRC_SetDir_fx is integrated above. - pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[0] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[0], Q30 ); - pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[1] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[1], Q30 ); - pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p_fx[2] = float_to_fix( pBinRendTd->Sources[nS]->SrcSpatial_p->Front_p[2], Q30 ); -#endif if ( ( error = TDREND_MIX_SRC_SetPlayState( pBinRendTd, nS, TDREND_PLAYSTATUS_PLAYING ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = TDREND_MIX_SRC_SetDirAtten( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } -#endif } } @@ -462,22 +442,10 @@ ivas_error ivas_td_binaural_open_unwrap( DirAtten_p->ConeOuterAngle = directivity[nS * 3 + 1]; DirAtten_p->ConeOuterGain = directivity[nS * 3 + 2]; } -#ifdef IVAS_FLOAT_FIXED - DirAtten_p->ConeInnerAngle_fx = float_to_fix( DirAtten_p->ConeInnerAngle, Q22 ); - DirAtten_p->ConeOuterAngle_fx = float_to_fix( DirAtten_p->ConeOuterAngle, Q22 ); - DirAtten_p->ConeOuterGain_fx = float_to_fix( DirAtten_p->ConeOuterGain, Q30 ); -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = TDREND_MIX_SRC_SetDirAtten_fx( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = TDREND_MIX_SRC_SetDirAtten( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } -#endif } } @@ -504,6 +472,7 @@ void ivas_td_binaural_close_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd /* i/o: TD binaural object renderer handle */ ) { + test(); IF( hBinRendererTd == NULL || *hBinRendererTd == NULL ) { return; @@ -599,7 +568,8 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( move16(); FOR( nS = 0; nS < num_src; nS++ ) { - IF( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ + test(); + IF( !( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( nS, lfe_idx ) ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = output_fx[nS]; /* Q11 */ hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; @@ -613,7 +583,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( IF( EQ_16( subframe_idx, ism_md_subframe_update ) ) { /* Update object position(s) */ - IF( ( error = TDREND_Update_object_positions_fx( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_Update_object_positions_fx( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ), IVAS_ERR_OK ) ) { return error; } @@ -623,13 +593,13 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( Word16 tmp_headRotEnabled; tmp_headRotEnabled = 0; move16(); - IF( enableCombinedOrientation != NULL ) + if ( enableCombinedOrientation != NULL ) { tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; move16(); } - IF( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, &Quaternions[hCombinedOrientationData->subframe_idx], &Pos[hCombinedOrientationData->subframe_idx] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, &Quaternions[hCombinedOrientationData->subframe_idx], &Pos[hCombinedOrientationData->subframe_idx] ) ), IVAS_ERR_OK ) ) { return error; } @@ -643,7 +613,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( Scale_sig32( output_fx[i], L_FRAME48k, -4 ); } - IF( ( error = ivas_reverb_process_fx( hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_reverb_process_fx( hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx ) ), IVAS_ERR_OK ) ) { return error; } @@ -660,7 +630,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( } /* Render subframe */ - IF( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update ) ), IVAS_ERR_OK ) ) { return error; } @@ -671,7 +641,8 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( move16(); FOR( nS = 0; nS < num_src; nS++ ) { - IF( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ + test(); + IF( !( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( nS, lfe_idx ) ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p_fx += subframe_length; c_indx = add( c_indx, 1 ); @@ -829,11 +800,14 @@ ivas_error TDREND_GetMix_fx( Word16 intp_count; Word16 subframe_update_flag; Word16 hrf_left_delta_e = 0, hrf_right_delta_e = 0; + move16(); + move16(); subframe_update_flag = (Word16) EQ_16( subframe_idx, ism_md_subframe_update ); + move16(); error = IVAS_ERR_OK; - + move32(); /* Clear the output buffer to accumulate rendered sources */ set32_fx( output_buf[0], 0, subframe_length ); set32_fx( output_buf[1], 0, subframe_length ); @@ -855,7 +829,7 @@ ivas_error TDREND_GetMix_fx( /* Update rendering params if needed */ test(); test(); - IF( ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) && ( hBinRendererTd->Listener_p->PoseUpdated || SrcSpatial_p->Updated ) ) + IF( EQ_16( SrcRend_p->PlayStatus, TDREND_PLAYSTATUS_PLAYING ) && ( hBinRendererTd->Listener_p->PoseUpdated || SrcSpatial_p->Updated ) ) { TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( hBinRendererTd, SrcRend_p, SrcSpatial_p, Src_p->hrf_left_prev_fx, &Src_p->hrf_left_prev_e, Src_p->hrf_right_prev_fx, &Src_p->hrf_right_prev_e, @@ -866,7 +840,8 @@ ivas_error TDREND_GetMix_fx( } /* Render source if needed */ - IF( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING ) ) + test(); + IF( EQ_16( SrcRend_p->InputAvailable, TRUE ) && EQ_16( SrcRend_p->PlayStatus, TDREND_PLAYSTATUS_PLAYING ) ) { error = TDREND_REND_RenderSourceHRFilt_fx( Src_p, hrf_left_delta, &hrf_left_delta_e, hrf_right_delta, &hrf_right_delta_e, intp_count, output_buf, subframe_length ); @@ -966,7 +941,7 @@ static void TDREND_Clear_Update_flags_fx( hBinRendererTd->Listener_p->PoseUpdated = FALSE; move16(); - for ( i = 0; i < hBinRendererTd->NumOfSrcs; i++ ) + FOR( i = 0; i < hBinRendererTd->NumOfSrcs; i++ ) { hBinRendererTd->Sources[i]->SrcSpatial_p->Updated = FALSE; move16(); @@ -1022,7 +997,7 @@ ivas_error TDREND_Update_object_positions_fx( { test(); test(); - IF( in_format == ISM_FORMAT || in_format == MASA_ISM_FORMAT || in_format == SBA_ISM_FORMAT ) + IF( EQ_16( in_format, ISM_FORMAT ) || EQ_16( in_format, MASA_ISM_FORMAT ) || EQ_16( in_format, SBA_ISM_FORMAT ) ) { /* Update the source positions */ /* Source position and direction */ @@ -1030,15 +1005,18 @@ ivas_error TDREND_Update_object_positions_fx( angles_to_vec_fx( ONE_IN_Q14, hIsmMetaData[nS]->yaw_fx, hIsmMetaData[nS]->pitch_fx, Dir_fx ); DirAtten_p->ConeInnerAngle_fx = DEG_360_IN_Q22; + move32(); DirAtten_p->ConeOuterAngle_fx = DEG_360_IN_Q22; + move32(); DirAtten_p->ConeOuterGain_fx = ONE_IN_Q30; + move32(); - IF( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = TDREND_MIX_SRC_SetDirAtten_fx( hBinRendererTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetDirAtten_fx( hBinRendererTd, nS, DirAtten_p ) ), IVAS_ERR_OK ) ) { return error; } @@ -1048,20 +1026,24 @@ ivas_error TDREND_Update_object_positions_fx( Pos_fx[0] = 0; /* Pos[1] = hIsmMetaData[nS]->azimuth / 90.f; */ Pos_fx[1] = L_shl( Mpy_32_32_r( hIsmMetaData[nS]->azimuth_fx, 23860929 /* 1 / 90.f in Q31 */ ), Q3 ); /* Q25 */ + move32(); Pos_fx[2] = 0; + move32(); - IF( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ), IVAS_ERR_OK ) ) { return error; } hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_NON_DIEGETIC; + move16(); } ELSE { hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_ABSOLUTE; + move16(); } - IF( ( error = TDREND_MIX_SRC_SetDir_fx( hBinRendererTd, nS, Dir_fx, Q30 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_MIX_SRC_SetDir_fx( hBinRendererTd, nS, Dir_fx, Q30 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1239,19 +1221,26 @@ ivas_error TDREND_Update_listener_orientation_fx( /* Obtain head rotation matrix */ QuatToRotMat_fx( *headPosition_fx, Rmat_fx ); // Rmat_fx Q: 2*Qx-32 - Rmat_q = 2 * headPosition_q - 32; + Rmat_q = sub( shl( headPosition_q, 1 ), 32 ); /* Apply rotation matrix to looking vector [1;0;0] */ FrontVec_fx[0] = Rmat_fx[0][0]; + move32(); FrontVec_fx[1] = Rmat_fx[0][1]; + move32(); FrontVec_fx[2] = Rmat_fx[0][2]; + move32(); /* Apply rotation matrix to up vector [0;0;1] */ UpVec_fx[0] = Rmat_fx[2][0]; + move32(); UpVec_fx[1] = Rmat_fx[2][1]; + move32(); UpVec_fx[2] = Rmat_fx[2][2]; + move32(); orient_q = Rmat_q; + move16(); IF( Pos_fx != NULL ) { @@ -1267,24 +1256,37 @@ ivas_error TDREND_Update_listener_orientation_fx( Pos_p_fx[1] = 0; Pos_p_fx[2] = 0; } + move32(); + move32(); + move32(); } ELSE { /* Oriented with looking vector along the x axis */ FrontVec_fx[0] = ONE_IN_Q30; + move32(); FrontVec_fx[1] = 0; + move32(); FrontVec_fx[2] = 0; + move32(); /* Oriented with up vector along the z axis */ UpVec_fx[0] = 0; + move32(); UpVec_fx[1] = 0; + move32(); UpVec_fx[2] = ONE_IN_Q30; + move32(); orient_q = Q30; + move32(); /* Listener at the origin */ Pos_p_fx[0] = 0; + move32(); Pos_p_fx[1] = 0; + move32(); Pos_p_fx[2] = 0; + move32(); } /* Set the listener position and orientation:*/ @@ -1321,7 +1323,7 @@ ivas_error ivas_td_binaural_open_ext_fx( IF( NE_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF( ( error = getAudioConfigNumChannels( inConfig, &nchan_transport ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } @@ -1329,12 +1331,23 @@ ivas_error ivas_td_binaural_open_ext_fx( ELSE { nchan_transport = customLsInput->num_spk; + move16(); } *num_src = nchan_transport; + move16(); transport_config = inConfig; - ivas_format = ( EQ_16( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) ? MC_FORMAT : ISM_FORMAT; - + move16(); + IF( ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) + { + ivas_format = MC_FORMAT; + move16(); + } + ELSE + { + ivas_format = ISM_FORMAT; + move16(); + } hTransSetup.ls_azimuth_fx = NULL; hTransSetup.ls_elevation_fx = NULL; @@ -1344,7 +1357,7 @@ ivas_error ivas_td_binaural_open_ext_fx( hTransSetup.ls_elevation_fx = customLsInput->ls_elevation_fx; } - IF( NULL != hRendCfg ) + if ( NULL != hRendCfg ) { directivity_fx = hRendCfg->directivity_fx; } @@ -1423,7 +1436,7 @@ ivas_error ivas_td_binaural_renderer_ext_fx( { ISM_METADATA_FRAME hIsmMetaDataFrame; ISM_METADATA_HANDLE hIsmMetaData[1]; - Word16 lfe_idx; + Word16 lfe_idx, exp_tmp; Word16 num_src; IVAS_FORMAT ivas_format; IVAS_REND_AudioConfigType inConfigType; @@ -1434,7 +1447,6 @@ ivas_error ivas_td_binaural_renderer_ext_fx( FOR( Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { p_output_fx[i] = output[i]; - move32(); } push_wmops( "ivas_td_binaural_renderer_ext" ); @@ -1454,14 +1466,23 @@ ivas_error ivas_td_binaural_renderer_ext_fx( IF( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { - IF( ( error = getAudioConfigNumChannels( inConfig, &num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &num_src ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - lfe_idx = ( customLsInput->num_lfe > 0 ) ? customLsInput->lfe_idx[0] : -1; + IF( customLsInput->num_lfe > 0 ) + { + lfe_idx = customLsInput->lfe_idx[0]; + move16(); + } + ELSE + { + lfe_idx = -1; + move16(); + } num_src = add( customLsInput->num_spk, customLsInput->num_lfe ); } } @@ -1489,54 +1510,48 @@ ivas_error ivas_td_binaural_renderer_ext_fx( move16(); } - Word16 num_subframes = (int16_t) ( ( output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); - for ( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + Word16 num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( output_frame, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), output_Fs, &exp_tmp ); + IF( sub( 15, exp_tmp ) ) + { + num_subframes = shr( num_subframes, sub( 15, exp_tmp ) ); + } + FOR( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { Word16 idx = subframe_idx; + move16(); Word16 pos_q = Q25; + move16(); IF( ( *hCombinedOrientationData )->listenerPos != NULL ) { - ( *hCombinedOrientationData )->listenerPos[idx].x_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].x_fx, ( *hCombinedOrientationData )->listenerPos[idx].q_fact - pos_q ); - ( *hCombinedOrientationData )->listenerPos[idx].y_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].y_fx, ( *hCombinedOrientationData )->listenerPos[idx].q_fact - pos_q ); - ( *hCombinedOrientationData )->listenerPos[idx].z_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].z_fx, ( *hCombinedOrientationData )->listenerPos[idx].q_fact - pos_q ); + ( *hCombinedOrientationData )->listenerPos[idx].x_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].x_fx, sub( ( *hCombinedOrientationData )->listenerPos[idx].q_fact, pos_q ) ); + move32(); + ( *hCombinedOrientationData )->listenerPos[idx].y_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].y_fx, sub( ( *hCombinedOrientationData )->listenerPos[idx].q_fact, pos_q ) ); + move32(); + ( *hCombinedOrientationData )->listenerPos[idx].z_fx = L_shr( ( *hCombinedOrientationData )->listenerPos[idx].z_fx, sub( ( *hCombinedOrientationData )->listenerPos[idx].q_fact, pos_q ) ); + move32(); ( *hCombinedOrientationData )->listenerPos[idx].q_fact = pos_q; + move16(); } FOR( int i = 0; i < 3; i++ ) { - pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = L_shr( pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], pTDRend->hBinRendererTd->Listener_p->Pos_q - pos_q ); + pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = L_shr( pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], sub( pTDRend->hBinRendererTd->Listener_p->Pos_q, pos_q ) ); pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; + move32(); move16(); } } - IF( ( error = ivas_td_binaural_renderer_unwrap_fx( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, - ism_md_subframe_update_ext, p_output_fx, output_frame, (Word16) ( ( output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_renderer_unwrap_fx( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, + ism_md_subframe_update_ext, p_output_fx, output_frame, num_subframes ) ), + IVAS_ERR_OK ) ) { return error; } - -#if 0 // TO-BE-REMOVED - for (Word16 subframe_idx = 0; subframe_idx < (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); subframe_idx++) - { - if (subframe_idx == ism_md_subframe_update_ext) - { - Word16 i = 0; - FOR(Word16 ns = 0; ns < num_src; ns++) - { - if(ns != lfe_idx){ - fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Front_p_fx, pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Front_p, Q30, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); - fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx, pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p, pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); - - i = add(i, 1); - } - } - } - } -#endif IF( hReverb != NULL ) { *exp = sub( *exp, 2 ); + move16(); } pop_wmops(); @@ -1646,10 +1661,15 @@ static void angles_to_vec_fx( { Word16 elevation_fx, azimuth_fx; elevation_fx = (Word16) L_shr( Mult_32_16( elevation, 91 ), 7 ); + move16(); azimuth_fx = (Word16) L_shr( Mult_32_16( azimuth, 91 ), 7 ); + move16(); vec[0] = L_mult( radius, mult( getCosWord16R2( elevation_fx ), getCosWord16R2( azimuth_fx ) ) ); + move32(); vec[1] = L_mult( radius, mult( getCosWord16R2( elevation_fx ), getSineWord16R2( azimuth_fx ) ) ); + move32(); vec[2] = L_mult( radius, getSineWord16R2( elevation_fx ) ); + move32(); return; } #else diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index 5f888df99b4e1284ec7fd15c9034de10ab1f082e..c2fe6a26264b311296c35d9203ddab89d9bb48f0 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -208,6 +208,7 @@ void GetFilterFromAngle_fx( { GenerateITD_fx( Elev_fx, Azim_fx, &HrFiltSet_p->ModelParamsITD, &HrFiltSet_p->ModelEval ); *itd = extract_l( HrFiltSet_p->ModelEval.itdMod_fx ); + move16(); } ELSE { @@ -223,7 +224,7 @@ static Word32 round_fixed( /* o : Output value Q0 */ Word16 q /* i : Input q-factor */ ) { - Word32 half = L_shl( 1, ( q - 1 ) ); + Word32 half = L_shl( 1, sub( q, 1 ) ); half = L_shr( half, 1 ); // one guard bit num = L_shr( num, 1 ); // one guard bit @@ -240,7 +241,7 @@ static Word32 round_fixed( /* o : Output value Q0 */ } WHILE( q != 0 ) { - num = num / 2; // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf. + num = ( num / 2 ); // using "/ 2" here because it rounds towards 0, whereas L_shr rounds towards -inf. q = sub( q, 1 ); } return num; @@ -424,7 +425,7 @@ static void GenerateFilter_fx( move16(); knot_interval = L_deposit_h( BASOP_Util_Divide3216_Scale( L_sub( model->azimKSeq_fx[k][model->azimDim3[k]], model->azimKSeq_fx[k][0] ), model->azimDim3[k], &tmp_e ) ); - tmp_e = add( tmp_e, sub( 9, 15 ) ); + tmp_e = add( tmp_e, 9 - 15 ); knot_interval = L_shr( knot_interval, sub( 9, tmp_e ) ); // variable Q to Q22 getPeriodicBSplineSampVec_fx( modelEval->azimBfVec_fx[p], AzIdx[p], model->azimDim3[k], azim, &num_az_idx[p], @@ -440,8 +441,10 @@ static void GenerateFilter_fx( { FOR( i = 0; i < num_az_idx[p]; i++ ) { - modelEval->BM_fx[qp + i] = L_shl( Mpy_32_32( modelEval->elevBfVec_fx[p], modelEval->azimBfVec_fx[p][i] ), Q30 - ( Q30 * 2 - 31 ) ); // Q30 - BM_idx[qp + i] = add( model->azim_start_idx[EvIdx[p]], AzIdx[p][i] ); + modelEval->BM_fx[add( qp, i )] = L_shl( Mpy_32_32( modelEval->elevBfVec_fx[p], modelEval->azimBfVec_fx[p][i] ), 1 ); /*Q30 - ( Q30 * 2 - 31 )*/ // Q30 + move32(); + BM_idx[add( qp, i )] = add( model->azim_start_idx[EvIdx[p]], AzIdx[p][i] ); + move16(); } qp = add( qp, num_az_idx[p] ); } @@ -472,9 +475,10 @@ static void GenerateFilter_fx( /* Energy is precalculated part updated with square of BM value. Store index for sorting */ FOR( i = 0; i < qp; i++ ) { - modelEval->BMEnergiesL[i].val_fx = Mpy_32_32( Mpy_32_32( modelEval->BM_fx[i], modelEval->BM_fx[i] ) /*Q29*/, model->EL_fx[iSec * model->AlphaN + BM_idx[i]] ); // exp: model->EL_e + 2 - modelEval->BMEnergiesR[i].val_fx = Mpy_32_32( Mpy_32_32( modelEval->BM_fx[i], modelEval->BM_fx[i] ) /*Q29*/, model->ER_fx[iSec * model->AlphaN + BM_idx[i]] ); // exp: model->ER_e + 2 - + modelEval->BMEnergiesL[i].val_fx = Mpy_32_32( Mpy_32_32( modelEval->BM_fx[i], modelEval->BM_fx[i] ) /*Q29*/, model->EL_fx[add( i_mult( iSec, model->AlphaN ), BM_idx[i] )] ); // exp: model->EL_e + 2 + modelEval->BMEnergiesR[i].val_fx = Mpy_32_32( Mpy_32_32( modelEval->BM_fx[i], modelEval->BM_fx[i] ) /*Q29*/, model->ER_fx[add( i_mult( iSec, model->AlphaN ), BM_idx[i] )] ); // exp: model->ER_e + 2 + move32(); + move32(); modelEval->BMEnergiesL[i].i = i; move16(); modelEval->BMEnergiesR[i].i = i; @@ -486,8 +490,8 @@ static void GenerateFilter_fx( /* Number of basis components actually used. */ p = s_min( HRTF_MODEL_N_CPTS_VAR[iSec], qp ); - SkipSmallest_ValueIndex_fx( modelEval->UseIndsL, modelEval->BMEnergiesL, qp, qp - p ); - SkipSmallest_ValueIndex_fx( modelEval->UseIndsR, modelEval->BMEnergiesR, qp, qp - p ); + SkipSmallest_ValueIndex_fx( modelEval->UseIndsL, modelEval->BMEnergiesL, qp, sub( qp, p ) ); + SkipSmallest_ValueIndex_fx( modelEval->UseIndsR, modelEval->BMEnergiesR, qp, sub( qp, p ) ); /* Account for lost energy */ FOR( i = 0; i < p; i++ ) @@ -522,18 +526,23 @@ static void GenerateFilter_fx( index = L_add( BM_idx[modelEval->BMEnergiesL[modelEval->UseIndsL[i]].i], imult3216( model->AlphaN, k ) ); tmp32 = Mpy_32_32( modelEval->BM_fx[modelEval->BMEnergiesL[modelEval->UseIndsL[i]].i], model->AlphaL_fx[index] ); modelEval->hrfModL_fx[k] = BASOP_Util_Add_Mant32Exp( modelEval->hrfModL_fx[k], tmp_hrfModL_e, tmp32, add( model->AlphaL_e, 1 ), &tmp_hrfModL_e ); - + move32(); index = L_add( BM_idx[modelEval->BMEnergiesR[modelEval->UseIndsR[i]].i], imult3216( model->AlphaN, k ) ); tmp32 = Mpy_32_32( modelEval->BM_fx[modelEval->BMEnergiesR[modelEval->UseIndsR[i]].i], model->AlphaR_fx[index] ); modelEval->hrfModR_fx[k] = BASOP_Util_Add_Mant32Exp( modelEval->hrfModR_fx[k], tmp_hrfModR_e, tmp32, add( model->AlphaR_e, 1 ), &tmp_hrfModR_e ); + move32(); } /* Account for lost energy */ modelEval->hrfModL_fx[k] = Mpy_32_32( modelEval->hrfModL_fx[k], ScaleL ); + move32(); modelEval->hrfModR_fx[k] = Mpy_32_32( modelEval->hrfModR_fx[k], ScaleR ); + move32(); /* NOTE: Assuming that finally, hrfMod values will be <= 1. Hence making it Q30 */ modelEval->hrfModL_fx[k] = L_shl( modelEval->hrfModL_fx[k], sub( add( tmp_hrfModL_e, ScaleL_e ), 1 ) ); // assuming Q30 modelEval->hrfModR_fx[k] = L_shl( modelEval->hrfModR_fx[k], sub( add( tmp_hrfModR_e, ScaleR_e ), 1 ) ); // assuming Q30 + move32(); + move32(); } } @@ -693,7 +702,7 @@ static void GenerateITD_fx( { azim_fx = L_sub( azim_fx, DEG_360_IN_Q22 ); } - IF( azim_fx < 0 ) + if ( azim_fx < 0 ) { azim_fx = L_add( azim_fx, DEG_360_IN_Q22 ); } @@ -706,12 +715,12 @@ static void GenerateITD_fx( azim_itd_fx = azim_fx; move32(); - IF( GT_32( azim_fx, DEG_180_IN_Q22 ) ) + if ( GT_32( azim_fx, DEG_180_IN_Q22 ) ) { /* Flip spline functions around 180 deg */ azim_itd_fx = L_sub( DEG_360_IN_Q22, azim_fx ); } - getStandardBSplineSampVec_fx( modelEval->azimBfVecITD_fx, AzIdx, &num_az_idx, ( model->azimDim3 + 1 ) / 2, azim_itd_fx, model->azimKSeq_fx, + getStandardBSplineSampVec_fx( modelEval->azimBfVecITD_fx, AzIdx, &num_az_idx, shr( add( model->azimDim3, 1 ), 1 ), azim_itd_fx, model->azimKSeq_fx, model->azimSegSamples, model->azimBsLen, model->azimBsStart, model->azimBsShape_fx ); IF( GT_32( azim_fx, DEG_180_IN_Q22 ) ) { @@ -748,7 +757,7 @@ static void GenerateITD_fx( /* Compute BM_ITD */ elev_offset = 0; move16(); - IF( EQ_32( model->elevKSeq_fx[0], -DEG_90_IN_Q22 ) ) + if ( EQ_32( model->elevKSeq_fx[0], -DEG_90_IN_Q22 ) ) { elev_offset = sub( 1, model->azimDim3 ); } @@ -756,19 +765,25 @@ static void GenerateITD_fx( move16(); FOR( p = 0; p < num_ev_idx; p++ ) { + test(); + test(); + test(); test(); IF( EvIdx[p] == 0 && EQ_32( model->elevKSeq_fx[EvIdx[p]], -DEG_90_IN_Q22 ) ) { modelEval->BM_ITD_fx[qp] = modelEval->elevBfVecITD_fx[p]; // Q30 move32(); BM_idx[qp] = imult1616( EvIdx[p], model->azimDim3 ); + move16(); qp = add( qp, 1 ); } - ELSE IF( EQ_16( EvIdx[p], sub( model->elevDim3, 1 ) ) && EQ_32( model->elevKSeq_fx[EvIdx[p] - 2], DEG_90_IN_Q22 ) ) + ELSE IF( EQ_16( EvIdx[p], sub( model->elevDim3, 1 ) ) && EQ_32( model->elevKSeq_fx[sub( EvIdx[p], 2 )], DEG_90_IN_Q22 ) ) { /* NB: -2 in if() condition above as number of knot points is numBF-2 */ modelEval->BM_ITD_fx[qp] = modelEval->elevBfVecITD_fx[p]; // Q30 + move32(); BM_idx[qp] = add( imult1616( EvIdx[p], model->azimDim3 ), elev_offset ); + move16(); qp = add( qp, 1 ); } ELSE @@ -776,7 +791,9 @@ static void GenerateITD_fx( FOR( i = 0; i < num_az_idx; i++ ) { modelEval->BM_ITD_fx[qp + i] = L_shl( Mpy_32_32( modelEval->elevBfVecITD_fx[p], modelEval->azimBfVecITD_fx[i] ), 1 ); // Q30 + move32(); BM_idx[qp + i] = add( add( imult1616( EvIdx[p], model->azimDim3 ), elev_offset ), AzIdx[i] ); + move16(); } qp = add( qp, num_az_idx ); } @@ -784,7 +801,7 @@ static void GenerateITD_fx( /* Compute ITD */ AlphaN = add( imult1616( model->elevDim3, model->azimDim3 ), elev_offset ); - IF( EQ_32( model->elevKSeq_fx[model->elevDim3 - 3], DEG_90_IN_Q22 ) ) /* Constant azimuth basis function */ + if ( EQ_32( model->elevKSeq_fx[sub( model->elevDim3, 3 )], DEG_90_IN_Q22 ) ) /* Constant azimuth basis function */ { AlphaN = sub( AlphaN, sub( model->azimDim3, 1 ) ); } @@ -801,6 +818,7 @@ static void GenerateITD_fx( move32(); modelEval->itdMod_fx = BASOP_Util_Add_Mant32Exp( modelEval->itdMod_fx, itdMod_e, Mpy_32_32( modelEval->BM_ITD_fx[i], model->W_fx[index] ), add( model->W_e, 1 ), &tmp_e ); itdMod_e = tmp_e; + move16(); } Word32 tmp32 = Mpy_32_16_1( modelEval->itdMod_fx, model->resamp_factor_fx ); // Q = 31 - ( itdMod_e + 1 ) @@ -905,7 +923,7 @@ static void getPeriodicBSplineSampVec_fx( ELSE { tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( knot_interval_fx, SegSamples, &tmp_e1 ) ); - tmp_e1 = add( tmp_e1, sub( 9, 15 ) ); + tmp_e1 = add( tmp_e1, 9 - 15 ); tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( L_sub( t_fx, azimKSeq_0_fx ), tmp32, &tmp_e2 ) ); tmp_e2 = add( tmp_e2, sub( 9, tmp_e1 ) ); tmp32 = L_shr( tmp32, sub( 9, tmp_e2 ) ); // Q22 (assuming tmp32 will be in range of Q22) @@ -926,14 +944,17 @@ static void getPeriodicBSplineSampVec_fx( IF( d0 % SegSamples == 0 ) { *num_az_idx = sub( *num_az_idx, 1 ); /* on the knot points, the last basis function is zero */ + move16(); } FOR( i = 0; i < *num_az_idx; i++ ) { d = sub( d0, imult1616( ( sub( add( i, nI ), 1 ) ), SegSamples ) ); /* offset of knot_interval */ d = sub( d0, imult1616( sub( add( i, nI ), 1 ), SegSamples ) ); - BfVec_fx[i] = azimBsShape_fx[abs_s( d ) * subSampFactor]; + BfVec_fx[i] = azimBsShape_fx[i_mult( abs_s( d ), subSampFactor )]; + move32(); AzIdx[i] = add( nI, i ) % NumBFs; + move16(); } return; @@ -1020,7 +1041,7 @@ static void getStandardBSplineSampVec_fx( /* assuming triple knot at the first knot */ knot_interval_fx = L_deposit_h( BASOP_Util_Divide3216_Scale( L_sub( KSeq_fx[NumBFs - 3], KSeq_fx[0] ), sub( NumBFs, 3 ), &tmp_e1 ) ); - tmp_e1 = add( tmp_e1, sub( 9, 15 ) ); + tmp_e1 = add( tmp_e1, 9 - 15 ); /* index of closest sample point */ tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( knot_interval_fx, SegSamples, &tmp_e2 ) ); @@ -1043,6 +1064,7 @@ static void getStandardBSplineSampVec_fx( IF( d0 % SegSamples == 0 ) { *num_idx = sub( *num_idx, 1 ); /* on the knot points, the last basis function is zero */ + move16(); } FOR( i = 0; i < *num_idx; i++ ) @@ -1059,8 +1081,10 @@ static void getStandardBSplineSampVec_fx( { d = sub( shl( sub( BsLen[shape_idx], 1 ), 1 ), d ); } - BfVec_fx[i] = BsShape_fx[BsStart[shape_idx] + abs_s( d )]; /*TT, verify if abs is needed */ + BfVec_fx[i] = BsShape_fx[add( BsStart[shape_idx], abs_s( d ) )]; /*TT, verify if abs is needed */ + move32(); NzIdx[i] = add( nI, i ); + move16(); } return; @@ -1085,12 +1109,15 @@ void HRTF_model_precalc( FOR( i = 0; i < HRTF_MODEL_N_SECTIONS; i++ ) { model->iSecFirst[i] = imult1616( i, sec_length ); + move16(); } FOR( i = 0; i < HRTF_MODEL_N_SECTIONS - 1; i++ ) { model->iSecLast[i] = sub( imult1616( add( i, 1 ), sec_length ), 1 ); + move16(); } model->iSecLast[HRTF_MODEL_N_SECTIONS - 1] = sub( model->K, 1 ); /* Final section is longer if (K % nSec) > 0 */ + move16(); maximum_fx( model->azimDim3, model->elevDim3, &model->azimDim3Max ); return; } diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index e333a56b1db47b8567e23e8ab640a5b45ee654e8..06a645622c6d0c8b7e187dc3fd9a6a3fdcbe4846 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -83,7 +83,8 @@ void TDREND_MIX_LIST_SetPos_fx( TDREND_MIX_Listener_t *Listener_p; Listener_p = hBinRendererTd->Listener_p; - + test(); + test(); IF( NE_32( Pos_p[0], Listener_p->Pos_fx[0] ) || NE_32( Pos_p[1], Listener_p->Pos_fx[1] ) || NE_32( Pos_p[2], Listener_p->Pos_fx[2] ) ) { /* Set position */ @@ -181,6 +182,7 @@ ivas_error TDREND_MIX_LIST_SetOrient_fx( /* Evaluate the normalized orientation vectors and set pose update flag */ List_p->PoseUpdated = TDREND_SPATIAL_EvalOrthonormOrient_fx( List_p->Front_fx, List_p->Up_fx, List_p->Right_fx, FrontVec_p_fx, UpVec_p_fx, orient_q ); + move16(); return IVAS_ERR_OK; } @@ -326,17 +328,21 @@ ivas_error TDREND_MIX_Init_fx( IF( MixSpatSpec_p != NULL ) { hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; + move16(); hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; + move16(); } ELSE { hBinRendererTd->UseCommonDistAttenModel = TRUE; + move16(); hBinRendererTd->DistAttenModel = 0x0000; /* Distance attenuation not activated; */ + move16(); } - move16(); /* Init virtual and rendering listeners for spatial mixers */ TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 ); hBinRendererTd->Listener_p->Pos_q = Q25; + move16(); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Vel_fx, 0, 0, 0 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Front_fx, 0, 0, -ONE_IN_Q30 ); TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Up_fx, 0, ONE_IN_Q30, 0 ); @@ -349,7 +355,7 @@ ivas_error TDREND_MIX_Init_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - IF( ( error = DefaultBSplineModel_fx( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DefaultBSplineModel_fx( hBinRendererTd->HrFiltSet_p, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -365,7 +371,7 @@ ivas_error TDREND_MIX_Init_fx( } return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED ivas_error TDREND_MIX_Init( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ @@ -376,11 +382,7 @@ ivas_error TDREND_MIX_Init( { ivas_error error; -#ifdef IVAS_FLOAT_FIXED - hBinRendererTd->Gain_fx = ONE_IN_Q14; -#else hBinRendererTd->Gain = 1.0f; -#endif /* Init source list */ /* Spatial settings */ @@ -396,21 +398,12 @@ ivas_error TDREND_MIX_Init( } /* Init virtual and rendering listeners for spatial mixers */ -#ifndef IVAS_FLOAT_FIXED TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Pos, 0.0f, 0.0f, 0.0f ); TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Vel, 0.0f, 0.0f, 0.0f ); TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Front, 0.0f, 0.0f, -1.0f ); TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Up, 0.0f, 1.0f, 0.0f ); TDREND_SPATIAL_VecInit( hBinRendererTd->Listener_p->Right, 1.0f, 0.0f, 0.0f ); -#endif -#ifdef IVAS_FLOAT_FIXED - TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 ); - hBinRendererTd->Listener_p->Pos_q = Q25; - TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Vel_fx, 0, 0, 0 ); - TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Front_fx, 0, 0, -ONE_IN_Q30 ); - TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Up_fx, 0, ONE_IN_Q30, 0 ); - TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Right_fx, ONE_IN_Q30, 0, 0 ); -#endif + /* Init HR filter set */ if ( *hHrtfTD == NULL ) { @@ -419,17 +412,10 @@ ivas_error TDREND_MIX_Init( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = DefaultBSplineModel_fx( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = DefaultBSplineModel( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) { return error; } -#endif *hHrtfTD = hBinRendererTd->HrFiltSet_p; } else @@ -444,7 +430,7 @@ ivas_error TDREND_MIX_Init( return IVAS_ERR_OK; } - +#endif /*-------------------------------------------------------------------* * TDREND_MIX_SetDistAttenModel() @@ -459,6 +445,7 @@ ivas_error TDREND_MIX_SetDistAttenModel( ) { /* Value validation */ + test(); IF( LT_16( DistAttenModel, TDREND_DIST_ATTEN_MODEL_INV_DIST ) || GT_16( DistAttenModel, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ) { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid distance attenuation model!\n" ) ); @@ -467,6 +454,7 @@ ivas_error TDREND_MIX_SetDistAttenModel( { /* Set the common distance attenuation model */ hBinRendererTd->DistAttenModel = DistAttenModel; + move32(); /* If using common distance attenuation model, set it. */ IF( hBinRendererTd->UseCommonDistAttenModel ) @@ -474,6 +462,7 @@ ivas_error TDREND_MIX_SetDistAttenModel( hBinRendererTd->DistAttenEnabled = TRUE; move16(); hBinRendererTd->DistAttenModel = DistAttenModel; + move32(); } } return IVAS_ERR_OK; @@ -524,11 +513,14 @@ ivas_error TDREND_MIX_AddSrc_fx( ivas_error error; error = IVAS_ERR_OK; - + move32(); /* Get unique source index */ *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); - hBinRendererTd->MaxSrcInd++; - hBinRendererTd->NumOfSrcs++; + move16(); + hBinRendererTd->MaxSrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); + move16(); + hBinRendererTd->NumOfSrcs = add( hBinRendererTd->NumOfSrcs, 1 ); + move16(); IF( GT_16( hBinRendererTd->NumOfSrcs, MAX_NUM_TDREND_CHANNELS ) ) { @@ -536,6 +528,7 @@ ivas_error TDREND_MIX_AddSrc_fx( } ELSE { + test(); IF( LT_16( PosType, TDREND_POSTYPE_ABSOLUTE ) || GT_16( PosType, TDREND_POSTYPE_NON_DIEGETIC ) ) { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid position type!\n" ) ); @@ -543,7 +536,7 @@ ivas_error TDREND_MIX_AddSrc_fx( ELSE { /* Alloc and init a complete source: signal+spatial+rend components */ - IF( ( error = TDREND_SRC_Alloc( &Src_p ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_SRC_Alloc( &Src_p ) ), IVAS_ERR_OK ) ) { return error; } @@ -556,6 +549,7 @@ ivas_error TDREND_MIX_AddSrc_fx( Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; move16(); Src_p->SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; + move32(); } /* Add source to mixer */ hBinRendererTd->Sources[*SrcInd] = Src_p; @@ -564,7 +558,7 @@ ivas_error TDREND_MIX_AddSrc_fx( return error; } -#endif // IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED ivas_error TDREND_MIX_AddSrc( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ @@ -599,11 +593,7 @@ ivas_error TDREND_MIX_AddSrc( { return error; } -#ifdef IVAS_FLOAT_FIXED - TDREND_SRC_Init_fx( Src_p, PosType ); -#else TDREND_SRC_Init( Src_p, PosType ); -#endif /* Special OpenAL initialization due to a common distance attenuation model */ if ( hBinRendererTd->DistAttenModel != 0 ) @@ -618,7 +608,7 @@ ivas_error TDREND_MIX_AddSrc( return error; } - +#endif /*-------------------------------------------------------------------* * BSplineModelEvalAlloc() @@ -682,37 +672,23 @@ static ivas_error DefaultBSplineModel_fx( Word16 i, j; ivas_error error; HrFiltSet_p->FilterMethod = TDREND_HRFILT_Method_BSplineModel; + move16(); model = &( HrFiltSet_p->ModelParams ); modelITD = &( HrFiltSet_p->ModelParamsITD ); SWITCH( output_Fs ) { case 48000: -#if 0 /*To be removed later : floating point pointer initialization*/ - HrFiltSet_p->lr_energy_and_iac[0] = defaultHRIR_left_avg_power_48kHz; - HrFiltSet_p->lr_energy_and_iac[1] = defaultHRIR_right_avg_power_48kHz; - HrFiltSet_p->lr_energy_and_iac[2] = defaultHRIR_coherence_48kHz; -#endif HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_48kHz_fx; HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_48kHz_fx; HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_48kHz_fx; BREAK; case 32000: -#if 0 /*To be removed later : floating point pointer initialization*/ - HrFiltSet_p->lr_energy_and_iac[0] = defaultHRIR_left_avg_power_32kHz; - HrFiltSet_p->lr_energy_and_iac[1] = defaultHRIR_right_avg_power_32kHz; - HrFiltSet_p->lr_energy_and_iac[2] = defaultHRIR_coherence_32kHz; -#endif HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_32kHz_fx; HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_32kHz_fx; HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_32kHz_fx; BREAK; case 16000: -#if 0 /*To be removed later : floating point pointer initialization*/ - HrFiltSet_p->lr_energy_and_iac[0] = defaultHRIR_left_avg_power_16kHz; - HrFiltSet_p->lr_energy_and_iac[1] = defaultHRIR_right_avg_power_16kHz; - HrFiltSet_p->lr_energy_and_iac[2] = defaultHRIR_coherence_16kHz; -#endif HrFiltSet_p->lr_energy_and_iac_fx[0] = defaultHRIR_left_avg_power_16kHz_fx; HrFiltSet_p->lr_energy_and_iac_fx[1] = defaultHRIR_right_avg_power_16kHz_fx; HrFiltSet_p->lr_energy_and_iac_fx[2] = defaultHRIR_coherence_16kHz_fx; @@ -762,36 +738,9 @@ static ivas_error DefaultBSplineModel_fx( model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx; model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; - /* float parameters */ -#if 0 /*To be removed later Floating point initializations */ - model->elevKSeq = (const float *) defaultHRIR_rom_elevKSeq; - model->elevBsShape = (const float *) defaultHRIR_rom_elevBsShape; -#endif // 1 model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx; model->elevBsShape_fx = (const Word32 *) defaultHRIR_rom_elevBsShape_fx; -#if 0 /*To be removed later : Floating point memory allocation*/ - IF ( ( model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); - } - model->azimBsShape[0] = (const float *)defaultHRIR_rom_azimBsShape; - IF ( ( model->azimKSeq = (float **) malloc( 18 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); - } - IF( ( model->azimKSeq[0] = (float *) malloc( 2 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); - } - IF( ( model->azimKSeq[model->elevDim3 - 1] = (float *) malloc( 2 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); - } - model->azimKSeq[0][0] = 0.0f; - model->azimKSeq[model->elevDim3 - 1][0] = 0.0f; - model->azimKSeq[0][1] = 360.0f; - model->azimKSeq[model->elevDim3 - 1][1] = 360.0f; -#endif + IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); @@ -818,18 +767,8 @@ static ivas_error DefaultBSplineModel_fx( move32(); move32(); - FOR( i = 1; i < model->elevDim3 - 1; i++ ) + FOR( i = 1; i < sub( model->elevDim3, 1 ); i++ ) { -#if 0 /*To be removed later : Floating point initialization*/ - IF ( ( model->azimKSeq[i] = (float *) malloc( model->azimDim2[i] * sizeof( float * ) ) ) == NULL ) /* azimDim2[i] = 91, i=2..15 */ - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); - } - FOR ( j = 0; j < model->azimDim2[i]; j++ ) - { - model->azimKSeq[i][j] = (float) defaultHRIR_rom_azimSegSamples[0] * j; - } -#endif IF( ( model->azimKSeq_fx[i] = (Word32 *) malloc( model->azimDim2[i] * sizeof( Word32 * ) ) ) == NULL ) /* azimDim2[i] = 91, i=2..15 */ { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); @@ -837,23 +776,13 @@ static ivas_error DefaultBSplineModel_fx( FOR( j = 0; j < model->azimDim2[i]; j++ ) { model->azimKSeq_fx[i][j] = L_shl( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); + move32(); } - j = j; } SWITCH( output_Fs ) { case 48000: -#if 0 /*To be removed later : floating point pointer initialization*/ - model->AlphaL = (const float *) defaultHRIR_rom_AlphaL48; - model->AlphaR = (const float *) defaultHRIR_rom_AlphaR48; - model->EL = (const float *) defaultHRIR_rom_EL48; - model->ER = (const float *) defaultHRIR_rom_ER48; - IF ( HrFiltSet_p->ModelParams.UseItdModel ) - { - modelITD->resamp_factor = 1.0f; - } -#endif model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; model->AlphaL_e = 1; move16(); @@ -875,16 +804,6 @@ static ivas_error DefaultBSplineModel_fx( } BREAK; case 32000: -#if 0 /*To be removed later : floating point pointer initialization*/ - model->AlphaL = (const float *) defaultHRIR_rom_AlphaL32; - model->AlphaR = (const float *) defaultHRIR_rom_AlphaR32; - model->EL = (const float *) defaultHRIR_rom_EL32; - model->ER = (const float *) defaultHRIR_rom_ER32; - IF ( HrFiltSet_p->ModelParams.UseItdModel ) - { - modelITD->resamp_factor = RESAMPLE_FACTOR_32_48; - } -#endif model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; model->AlphaL_e = 1; move16(); @@ -906,16 +825,6 @@ static ivas_error DefaultBSplineModel_fx( } BREAK; case 16000: -#if 0 /*To be removed later : floating point pointer initialization*/ - model->AlphaL = (const float *) defaultHRIR_rom_AlphaL16; - model->AlphaR = (const float *) defaultHRIR_rom_AlphaR16; - model->EL = (const float *) defaultHRIR_rom_EL16; - model->ER = (const float *) defaultHRIR_rom_ER16; - IF ( HrFiltSet_p->ModelParams.UseItdModel ) - { - modelITD->resamp_factor = RESAMPLE_FACTOR_16_48; - } -#endif model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; model->AlphaL_e = 1; move16(); @@ -968,9 +877,6 @@ static ivas_error DefaultBSplineModel_fx( move16(); modelITD->elevBsStart[3] = 21; move16(); -#if 0 /*To be removed later : floating point pointer initialization*/ - modelITD->elevKSeq = defaultHRIR_rom_ITD_elevKSeq; -#endif modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; modelITD->azimBsLen[0] = 11; @@ -992,12 +898,6 @@ static ivas_error DefaultBSplineModel_fx( modelITD->azimSegSamples = 10; move16(); -#if 0 /*To be removed later : floating point pointer initialization*/ - modelITD->azimKSeq = defaultHRIR_rom_ITD_azimKSeq; - modelITD->W = (const float *) defaultHRIR_rom_ITD_W; - modelITD->azimBsShape = (const float *) defaultHRIR_rom_ITD_azimBsShape; - modelITD->elevBsShape = (const float *) defaultHRIR_rom_ITD_elevBsShape; -#endif modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; modelITD->W_fx = (const Word32 *) defaultHRIR_rom_ITD_W_fx; // Q25 modelITD->W_e = 6; @@ -1014,7 +914,7 @@ static ivas_error DefaultBSplineModel_fx( HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; move16(); - IF( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index a094559538449474145f5ffc5b414047ffc4a132..6bb4b0c4409eb87b912ce00b1fee1833e8a30af8 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -200,7 +200,7 @@ void TDREND_Apply_ITD_fx( tlen3 = s_max( 0, sub( SFX_SPAT_BIN_SINC_M, currShift ) ); /* Make sure there is enough look-ahead for the sinc resampling */ transition_len = sub( length, tlen3 ); - IF( ( ( *previtd ) * itd ) < 0 ) + IF( i_mult( ( *previtd ), itd ) < 0 ) { /* ITD sign change - apply shift on both channels */ Word16 tmp1 = imult1616( transition_len, prevShift ); @@ -211,6 +211,7 @@ void TDREND_Apply_ITD_fx( Word16 tmp_e2 = BASOP_Util_Add_MantExp( tmp3, tmp_e, ONE_IN_Q14, 0, &tmp4 ); tmp4 = shr( tmp4, sub( 15, tmp_e2 ) ); // Q0 tlen1 = tmp4; + move16(); tlen2 = sub( transition_len, tlen1 ); pstart1_fx = p_input_fx - prevShift; @@ -374,7 +375,9 @@ static void sincResample_fx( // epsilon: 1e-15f const Word32 eps = 1208925824; + move32(); const Word16 eps_e = -49; + move16(); /* avoid division by 0 */ IF( 0 == length_out ) @@ -407,8 +410,8 @@ static void sincResample_fx( p_mid_fx = input_fx + t; p_forward_fx = p_mid_fx + 1; p_backward_fx = p_mid_fx - 1; - p_sinc_forward_fx = SincTable_fx + SFX_SPAT_BIN_NUM_SUBSAMPLES - snc0; - p_sinc_backward_fx = SincTable_fx + SFX_SPAT_BIN_NUM_SUBSAMPLES + snc0; + p_sinc_forward_fx = SincTable_fx + sub( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); + p_sinc_backward_fx = SincTable_fx + add( SFX_SPAT_BIN_NUM_SUBSAMPLES, snc0 ); tmp_fx = Mpy_32_32( *p_mid_fx, SincTable_fx[snc0] ); /* Middle point */ @@ -554,8 +557,8 @@ void TDREND_firfilt_fx( /* Apply linear gain interpolation in case of abrupt gain changes */ gain_tmp_fx = add( gain_tmp_fx, step_fx ); signal_fx[i] = Mpy_32_16_1( tmp_fx, gain_tmp_fx ); - - IF( i < intp_count ) + move32(); + IF( LT_16( i, intp_count ) ) { v_add_fx( filter_fx, filter_delta_fx, filter_fx, filterlength ); } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 4fb0b4734254bb112adc03ab87e4b0f47a68a1c1..15159cacfc42f3033e1178aa8abc26da784588ff 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -85,10 +85,16 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( ELSE { SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; - SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], SrcSpatial_p->q_Pos_p - Q25 ); - SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], SrcSpatial_p->q_Pos_p - Q25 ); - SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], SrcSpatial_p->q_Pos_p - Q25 ); + SrcSpatial_p->Pos_p_fx[0] = L_shr( SrcSpatial_p->Pos_p_fx[0], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + move32(); + SrcSpatial_p->Pos_p_fx[1] = L_shr( SrcSpatial_p->Pos_p_fx[1], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + move32(); + SrcSpatial_p->Pos_p_fx[2] = L_shr( SrcSpatial_p->Pos_p_fx[2], sub( SrcSpatial_p->q_Pos_p, Q25 ) ); + move32(); SrcSpatial_p->q_Pos_p = Q25; + move16(); + test(); + test(); IF( NE_32( SrcSpatial_p->Pos_p_fx[0], Vec_p[0] ) || NE_32( SrcSpatial_p->Pos_p_fx[1], Vec_p[1] ) || NE_32( SrcSpatial_p->Pos_p_fx[2], Vec_p[2] ) ) { Copy32( Vec_p, SrcSpatial_p->Pos_p_fx, 3 ); @@ -258,6 +264,7 @@ ivas_error TDREND_MIX_SRC_SetPlayState( ELSE { hBinRendererTd->Sources[SrcInd]->SrcRend_p->PlayStatus = PlayStatus; + move32(); } return IVAS_ERR_OK; } @@ -322,6 +329,7 @@ static void TDREND_SRC_REND_Init_fx( SrcRend_p->InputAvailable = FALSE; move16(); SrcRend_p->PlayStatus = TDREND_PLAYSTATUS_PLAYING; + move16(); /* SrcGain */ FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { @@ -357,33 +365,17 @@ static void TDREND_SRC_REND_Init( /* SrcGain */ for ( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { -#ifndef IVAS_FLOAT_FIXED SrcRend_p->SrcGainMin_p[nC] = 0.0f; SrcRend_p->SrcGain_p[nC] = 1.0f; SrcRend_p->SrcGainMax_p[nC] = 1.0f; -#else - SrcRend_p->SrcGainMin_p_fx[nC] = ONE_IN_Q14; - move16(); - SrcRend_p->SrcGain_p_fx[nC] = ONE_IN_Q14; - move16(); - SrcRend_p->SrcGainMax_p_fx[nC] = ONE_IN_Q14; - move16(); -#endif } SrcRend_p->SrcGainUpdated = FALSE; /* Init directional and distance gains */ for ( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { -#ifndef IVAS_FLOAT_FIXED SrcRend_p->DirGain_p[nC] = 1.0f; SrcRend_p->DistGain_p[nC] = 1.0f; -#else - SrcRend_p->DirGain_p_fx[nC] = ONE_IN_Q14; - move16(); - SrcRend_p->DistGain_p_fx[nC] = ONE_IN_Q14; - move16(); -#endif } @@ -560,13 +552,13 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( HrFiltSet_p = hBinRendererTd->HrFiltSet_p; *filterlength = s_min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); - - IF( SrcSpatial_p->PosType == TDREND_POSTYPE_ABSOLUTE ) + move16(); + IF( EQ_16( SrcSpatial_p->PosType, TDREND_POSTYPE_ABSOLUTE ) ) { /* Absolute position */ TDREND_SPATIAL_VecMapToNewCoordSystem_fx( SrcSpatial_p->Pos_p_fx, Listener_p->Pos_fx, Listener_p->Front_fx, Listener_p->Up_fx, Listener_p->Right_fx, ListRelPos, ListRelPosAbs ); - ListRelPos_e = 62 - Q25 - Q30; // output q of above function is Q25 + Q30 - 31. so exp will be 62 - Q25 - Q30. + ListRelPos_e = 7; // output q of above function is Q25 + Q30 - 31. so exp will be 62 - Q25 - Q30. move16(); ListRelDist = TDREND_SPATIAL_VecNorm_fx( ListRelPos, ListRelPos_e, &ListRelDist_e ); @@ -616,139 +608,149 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams_fx( IF( hBinRendererTd->DistAttenEnabled ) { SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; + move32(); *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); + move32(); } } - ELSE{ - IF( SrcSpatial_p->DistAttenEnabled ){ - *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); - } -} + ELSE IF( SrcSpatial_p->DistAttenEnabled ) + { -/* Update total gains */ -*Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); + *SrcRend_p->DistGain_p_fx = TDREND_SRC_SPATIAL_GetDistGain_fx( &SrcSpatial_p->DistAtten, ListRelDist, ListRelDist_e ); + move32(); + } -/* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ -Word32 ele_tmp = Src_p->elev_prev_fx; -IF( GT_32( ele_tmp, DEG_180_IN_Q22 ) ) -{ - ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); -} -ELSE IF( LT_32( ele_tmp, -DEG_180_IN_Q22 ) ) -{ - ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); -} -elev_delta = L_sub( Elev, ele_tmp ); -Word32 azi_tmp = Src_p->azim_prev_fx; -IF( GT_32( azi_tmp, DEG_180_IN_Q22 ) ) -{ - azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); -} -ELSE IF( LT_32( azi_tmp, -DEG_180_IN_Q22 ) ) -{ - azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); -} -azim_delta = L_sub( Azim, azi_tmp ); + /* Update total gains */ + *Gain = extract_h( L_shl( Mpy_32_32( L_shl( L_mult( *SrcRend_p->SrcGain_p_fx, *SrcRend_p->DirGain_p_fx ), 1 ), L_shl( L_mult( *SrcRend_p->DistGain_p_fx, hBinRendererTd->Gain_fx ), 1 ) ), 1 ) ); + move16(); + /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ + Word32 ele_tmp = Src_p->elev_prev_fx; + move32(); + IF( GT_32( ele_tmp, DEG_180_IN_Q22 ) ) + { + ele_tmp = L_sub( ele_tmp, DEG_360_IN_Q22 ); + } + ELSE IF( LT_32( ele_tmp, -DEG_180_IN_Q22 ) ) + { + ele_tmp = L_add( ele_tmp, DEG_360_IN_Q22 ); + } + elev_delta = L_sub( Elev, ele_tmp ); -Src_p->elev_prev_fx = Elev; -move32(); -Src_p->azim_prev_fx = Azim; -move32(); + Word32 azi_tmp = Src_p->azim_prev_fx; + IF( GT_32( azi_tmp, DEG_180_IN_Q22 ) ) + { + azi_tmp = L_sub( azi_tmp, DEG_360_IN_Q22 ); + } + ELSE IF( LT_32( azi_tmp, -DEG_180_IN_Q22 ) ) + { + azi_tmp = L_add( azi_tmp, DEG_360_IN_Q22 ); + } + azim_delta = L_sub( Azim, azi_tmp ); -/* map to -180:180 range */ -IF( GT_32( azim_delta, DEG_180_IN_Q22 ) ) -{ - azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); -} -ELSE IF( LT_32( azim_delta, -DEG_180_IN_Q22 ) ) -{ - azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); -} -Word16 tmp1 = extract_l( Mpy_32_32( L_abs( azim_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 -Word16 tmp2 = extract_l( Mpy_32_32( L_abs( elev_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 -*intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); -} -ELSE /* TDREND_POSTYPE_NON_DIEGETIC */ -{ - *itd = 0; - move16(); - *Gain = ONE_IN_Q14; - move16(); - set32_fx( hrf_left, 0, *filterlength ); - set32_fx( hrf_right, 0, *filterlength ); - hrf_left[0] = L_shr( L_add( SrcSpatial_p->Pos_p_fx[1], ONE_IN_Q25 ), 1 ); // Q25 - move32(); - hrf_right[0] = L_sub( ONE_IN_Q25, hrf_left[0] ); // Q25 - move32(); - hrf_left_e = 6; - move16(); - hrf_right_e = 6; - move16(); - *intp_count = MAX_INTERPOLATION_STEPS; - move16(); - Src_p->elev_prev_fx = 0; - move16(); - Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ - move16(); -} + Src_p->elev_prev_fx = Elev; + move32(); + Src_p->azim_prev_fx = Azim; + move32(); -test(); -IF( ( *intp_count > 0 ) && subframe_update_flag ) -{ - /* Set deltas for interpolation */ - Word16 tmp_e; - tmp_e = s_max( *hrf_left_prev_e, hrf_left_e ); - FOR( Word16 i = 0; i < *filterlength; i++ ) + /* map to -180:180 range */ + IF( GT_32( azim_delta, DEG_180_IN_Q22 ) ) + { + azim_delta = L_sub( azim_delta, DEG_360_IN_Q22 ); + } + ELSE IF( LT_32( azim_delta, -DEG_180_IN_Q22 ) ) + { + azim_delta = L_add( azim_delta, DEG_360_IN_Q22 ); + } + Word16 tmp1 = extract_l( Mpy_32_32( L_abs( azim_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 + Word16 tmp2 = extract_l( Mpy_32_32( L_abs( elev_delta ), 100 << Q9 ) ); // Q22 + Q9 - Q31 = Q0 + *intp_count = s_min( MAX_INTERPOLATION_STEPS, s_max( tmp1, tmp2 ) ); + move16(); + } + ELSE /* TDREND_POSTYPE_NON_DIEGETIC */ { - hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); - hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); + *itd = 0; + move16(); + *Gain = ONE_IN_Q14; + move16(); + set32_fx( hrf_left, 0, *filterlength ); + set32_fx( hrf_right, 0, *filterlength ); + hrf_left[0] = L_shr( L_add( SrcSpatial_p->Pos_p_fx[1], ONE_IN_Q25 ), 1 ); // Q25 + move32(); + hrf_right[0] = L_sub( ONE_IN_Q25, hrf_left[0] ); // Q25 + move32(); + hrf_left_e = 6; + move16(); + hrf_right_e = 6; + move16(); + *intp_count = MAX_INTERPOLATION_STEPS; + move16(); + Src_p->elev_prev_fx = 0; + move16(); + Src_p->azim_prev_fx = DEG_360_IN_Q22; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ + move16(); } - *hrf_left_prev_e = tmp_e; - move16(); - hrf_left_e = tmp_e; - move16(); - v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); - *hrf_left_delta_e = tmp_e; - move16(); - Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); - v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); + test(); + IF( ( *intp_count > 0 ) && subframe_update_flag ) + { + /* Set deltas for interpolation */ + Word16 tmp_e; + tmp_e = s_max( *hrf_left_prev_e, hrf_left_e ); + FOR( Word16 i = 0; i < *filterlength; i++ ) + { + hrf_left[i] = L_shr( hrf_left[i], sub( tmp_e, hrf_left_e ) ); + move32(); + hrf_left_prev[i] = L_shr( hrf_left_prev[i], sub( tmp_e, *hrf_left_prev_e ) ); + move32(); + } + *hrf_left_prev_e = tmp_e; + move16(); + hrf_left_e = tmp_e; + move16(); + v_sub_32( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); + *hrf_left_delta_e = tmp_e; + move16(); + + Word32 fac = L_deposit_h( div_s( 1, *intp_count ) ); + v_multc_fixed( hrf_left_delta, fac, hrf_left_delta, *filterlength ); - tmp_e = s_max( *hrf_right_prev_e, hrf_right_e ); - FOR( Word16 i = 0; i < *filterlength; i++ ) + tmp_e = s_max( *hrf_right_prev_e, hrf_right_e ); + FOR( Word16 i = 0; i < *filterlength; i++ ) + { + hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); + move32(); + hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); + move32(); + } + *hrf_right_prev_e = tmp_e; + move16(); + hrf_right_e = tmp_e; + move16(); + v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); + *hrf_right_delta_e = tmp_e; + move16(); + + v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); + } + ELSE { - hrf_right[i] = L_shr( hrf_right[i], sub( tmp_e, hrf_right_e ) ); - hrf_right_prev[i] = L_shr( hrf_right_prev[i], sub( tmp_e, *hrf_right_prev_e ) ); + /* No interpolation, just set the new filters and reset deltas */ + Copy32( hrf_left, hrf_left_prev, *filterlength ); + *hrf_left_prev_e = hrf_left_e; + move16(); + Copy32( hrf_right, hrf_right_prev, *filterlength ); + *hrf_right_prev_e = hrf_right_e; + move16(); + set32_fx( hrf_left_delta, 0, *filterlength ); + set32_fx( hrf_right_delta, 0, *filterlength ); + *hrf_left_delta_e = 0; + move16(); + *hrf_right_delta_e = 0; + move16(); } - *hrf_right_prev_e = tmp_e; - move16(); - hrf_right_e = tmp_e; - move16(); - v_sub_32( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); - *hrf_right_delta_e = tmp_e; - move16(); - v_multc_fixed( hrf_right_delta, fac, hrf_right_delta, *filterlength ); -} -ELSE -{ - /* No interpolation, just set the new filters and reset deltas */ - Copy32( hrf_left, hrf_left_prev, *filterlength ); - *hrf_left_prev_e = hrf_left_e; - move16(); - Copy32( hrf_right, hrf_right_prev, *filterlength ); - *hrf_right_prev_e = hrf_right_e; - move16(); - set32_fx( hrf_left_delta, 0, *filterlength ); - set32_fx( hrf_right_delta, 0, *filterlength ); - *hrf_left_delta_e = 0; - move16(); - *hrf_right_delta_e = 0; - move16(); -} - -return; + return; } #endif @@ -835,6 +837,7 @@ static void TDREND_SRC_SPATIAL_Init_fx( move16(); /* Source position, velocity and direction vectors */ SrcSpatial_p->PosType = PosType; + move32(); FOR( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { /* Source position */ @@ -846,6 +849,7 @@ static void TDREND_SRC_SPATIAL_Init_fx( #ifdef MSAN_FIX SrcSpatial_p->q_Pos_p = Q31; + move16(); #endif /* Source directional attenuation */ @@ -862,6 +866,7 @@ static void TDREND_SRC_SPATIAL_Init_fx( SrcSpatial_p->DistAttenEnabled = FALSE; move16(); SrcSpatial_p->DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; + move16(); SrcSpatial_p->DistAtten.RefDist_fx = ONE_IN_Q30; move32(); SrcSpatial_p->DistAtten.MaxDist_fx = 2113929216; /* Maximum radius (2^ISM_RADIUS_NBITS-1)*0.25 */ /*15.75 in Q27*/ @@ -888,15 +893,8 @@ static void TDREND_SRC_SPATIAL_Init( { /* Source position */ TDREND_SPATIAL_VecInit( SrcSpatial_p->Pos_p + nC * 3, 0.0f, 0.0f, 0.0f ); -#ifdef IVAS_FLOAT_FIXED - TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Pos_p_fx + nC * 3, 0, 0, 0 ); -#endif - /* Source direction */ TDREND_SPATIAL_VecInit( SrcSpatial_p->Front_p + nC * 3, 0.0f, 0.0f, 1.0f ); -#ifdef IVAS_FLOAT_FIXED - TDREND_SPATIAL_VecInit_fx( SrcSpatial_p->Front_p_fx + nC * 3, 0, 0, ONE_IN_Q30 ); -#endif } /* Source directional attenuation */ @@ -904,30 +902,13 @@ static void TDREND_SRC_SPATIAL_Init( SrcSpatial_p->DirAtten.ConeInnerAngle = 360.0f; SrcSpatial_p->DirAtten.ConeOuterAngle = 360.0f; SrcSpatial_p->DirAtten.ConeOuterGain = 1.0f; -#ifdef IVAS_FLOAT_FIXED - SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DEG_360_IN_Q22; - move32(); - SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DEG_360_IN_Q22; - move32(); - SrcSpatial_p->DirAtten.ConeOuterGain_fx = ONE_IN_Q30; - move32(); -#endif /* Source distance attenuation */ SrcSpatial_p->DistAttenEnabled = FALSE; SrcSpatial_p->DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; -#ifndef IVAS_FLOAT_FIXED SrcSpatial_p->DistAtten.RefDist = 1.0f; SrcSpatial_p->DistAtten.MaxDist = 15.75f; /* Maximum radius (2^ISM_RADIUS_NBITS-1)*0.25 */ SrcSpatial_p->DistAtten.RollOffFactor = 1.0f; -#else - SrcSpatial_p->DistAtten.RefDist_fx = ONE_IN_Q30; - move32(); - SrcSpatial_p->DistAtten.MaxDist_fx = 2113929216; /* Maximum radius (2^ISM_RADIUS_NBITS-1)*0.25 */ /*15.75 in Q27*/ - move32(); - SrcSpatial_p->DistAtten.RollOffFactor_fx = ONE_IN_Q30; - move16(); -#endif return; } @@ -968,12 +949,6 @@ static void TDREND_SRC_SPATIAL_SetDirAtten( SrcSpatial_p->DirAtten.ConeOuterAngle = DirAtten_p->ConeOuterAngle; SrcSpatial_p->DirAtten.ConeOuterGain = DirAtten_p->ConeOuterGain; -#ifdef IVAS_FLOAT_FIXED - SrcSpatial_p->DirAtten.ConeInnerAngle_fx = DirAtten_p->ConeInnerAngle_fx; - SrcSpatial_p->DirAtten.ConeOuterAngle_fx = DirAtten_p->ConeOuterAngle_fx; - SrcSpatial_p->DirAtten.ConeOuterGain_fx = DirAtten_p->ConeOuterGain_fx; -#endif - return; } #endif @@ -1212,7 +1187,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( BREAK; } - DistGain_fx = shr( DistGain_fx, 1 - DistGain_e ); // Reducing it to Q14 + DistGain_fx = shr( DistGain_fx, sub( 1, DistGain_e ) ); // Reducing it to Q14 return DistGain_fx; } @@ -1223,7 +1198,7 @@ static Word16 TDREND_SRC_SPATIAL_GetDistGain_fx( * * Allocate a source. --------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error TDREND_SRC_Alloc( TDREND_SRC_t **Src_pp /* i/o: Source */ ) @@ -1232,7 +1207,7 @@ ivas_error TDREND_SRC_Alloc( TDREND_SRC_t *Src_p; error = IVAS_ERR_OK; - + move32(); *Src_pp = NULL; /* Allocate the TDREND_SRC_t variable */ @@ -1243,12 +1218,12 @@ ivas_error TDREND_SRC_Alloc( Src_p->SrcSpatial_p = NULL; /* If source type is dynamic alloc the TDREND_SRC_SPATIAL_t variable */ - IF( ( error = TDREND_SRC_SPATIAL_Alloc( &Src_p->SrcSpatial_p ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_SRC_SPATIAL_Alloc( &Src_p->SrcSpatial_p ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = TDREND_SRC_REND_Alloc( &Src_p->SrcRend_p ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = TDREND_SRC_REND_Alloc( &Src_p->SrcRend_p ) ), IVAS_ERR_OK ) ) { return error; } @@ -1257,7 +1232,41 @@ ivas_error TDREND_SRC_Alloc( return error; } +#else +ivas_error TDREND_SRC_Alloc( + TDREND_SRC_t **Src_pp /* i/o: Source */ +) +{ + ivas_error error; + TDREND_SRC_t *Src_p; + + error = IVAS_ERR_OK; + *Src_pp = NULL; + + /* Allocate the TDREND_SRC_t variable */ + if ( ( Src_p = (TDREND_SRC_t *) malloc( sizeof( TDREND_SRC_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, " TDREND_SRC_Alloc: Allocation error\n" ) ); + } + + Src_p->SrcSpatial_p = NULL; + /* If source type is dynamic alloc the TDREND_SRC_SPATIAL_t variable */ + if ( ( error = TDREND_SRC_SPATIAL_Alloc( &Src_p->SrcSpatial_p ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = TDREND_SRC_REND_Alloc( &Src_p->SrcRend_p ) ) != IVAS_ERR_OK ) + { + return error; + } + + *Src_pp = Src_p; + + return error; +} +#endif /*-------------------------------------------------------------------* * TDREND_SRC_Dealloc() @@ -1378,16 +1387,9 @@ void TDREND_SRC_Init( Src_p->itd = 0; Src_p->previtd = 0; Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ -#ifndef IVAS_FLOAT_FIXED set_f( Src_p->mem_itd, 0.0f, ITD_MEM_LEN ); set_f( Src_p->mem_hrf_left, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); set_f( Src_p->mem_hrf_right, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); -#endif -#ifdef IVAS_FLOAT_FIXED - set32_fx( Src_p->mem_itd_fx, 0, ITD_MEM_LEN ); - set32_fx( Src_p->mem_hrf_left_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); - set32_fx( Src_p->mem_hrf_right_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); -#else set_f( Src_p->hrf_left_prev, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); set_f( Src_p->hrf_right_prev, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); Src_p->hrf_left_prev[0] = 1; @@ -1396,19 +1398,6 @@ void TDREND_SRC_Init( Src_p->elev_prev = 0.0f; Src_p->Gain = 1; Src_p->prevGain = 1.0f; -#endif -#ifdef IVAS_FLOAT_FIXED - set32_fx( Src_p->hrf_left_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); - set32_fx( Src_p->hrf_right_prev_fx, 0, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); - Src_p->hrf_left_prev_fx[0] = ONE_IN_Q30; - Src_p->hrf_left_prev_e = 1; - Src_p->hrf_right_prev_fx[0] = ONE_IN_Q30; - Src_p->hrf_right_prev_e = 1; - Src_p->azim_prev_fx = 0; - Src_p->elev_prev_fx = 0; - Src_p->Gain_fx = ONE_IN_Q14; - Src_p->prevGain_fx = ONE_IN_Q14; -#endif return; } diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index b224af67205a8f5a88bfb217308f04985f348729..a7c92ec704baf454684a8e516089890dc50c14cc 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -527,6 +527,150 @@ void ivas_output_init( *-----------------------------------------------------------------*/ /*! r: number of decoder buffers */ +#ifndef IVAS_FLOAT_FIXED +int16_t ivas_get_nchan_buffers_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t sba_analysis_order, /* i : SBA order evaluated in SBA decoder */ + const int32_t ivas_total_brate /* i : total IVAS bitrate */ +) +{ + int16_t nchan_out_buff; + AUDIO_CONFIG output_config; + + output_config = st_ivas->hDecoderConfig->output_config; + + nchan_out_buff = MAX_OUTPUT_CHANNELS; + + if ( st_ivas->ivas_format == MONO_FORMAT ) + { + nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; + } + else if ( st_ivas->ivas_format == STEREO_FORMAT ) + { + nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, CPE_CHANNELS ); + } + else if ( st_ivas->ivas_format == ISM_FORMAT ) + { + nchan_out_buff = st_ivas->nchan_ism; + + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); + } + else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL ) + { + nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); + } + } + else if ( st_ivas->ivas_format == SBA_FORMAT ) + { + int16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); + nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; + + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); + } + else + { + nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); + } + nchan_out_buff = max( nchan_out_buff, nchan_internal ); + } + else if ( st_ivas->ivas_format == MASA_FORMAT ) + { + nchan_out_buff = CPE_CHANNELS; + + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); + } + else if ( output_config == IVAS_AUDIO_CONFIG_STEREO || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + nchan_out_buff = 2 * CPE_CHANNELS; + } + else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL ) + { + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); + } + } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + nchan_out_buff = st_ivas->nchan_ism + CPE_CHANNELS; + + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); + } + else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL ) + { + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); + } + } + else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + int16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); + nchan_out_buff = st_ivas->nchan_ism + st_ivas->nchan_transport; + + if ( st_ivas->hMCT != NULL ) + { + nchan_out_buff = ( ( nchan_out_buff + 1 ) >> 1 ) << 1; /* ensure odd number of channels in MCT */ + } + + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); + } + else if ( output_config != IVAS_AUDIO_CONFIG_EXTERNAL ) + { + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); + + if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS ) + { + nchan_out_buff = max( nchan_out_buff + st_ivas->nchan_ism, audioCfg2channels( output_config ) ); /* needed for ivas_sba_upmixer_renderer() */ + } + else + { + nchan_out_buff = max( nchan_out_buff + st_ivas->nchan_ism, audioCfg2channels( output_config ) ); /* needed for ivas_spar_dec_upmixer_sf() which is based on 'nchan_out' */ + } + } + else if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + nchan_out_buff = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism; /*take into account sba_ch_idx' in ivas_dec() */ + } + + if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + { + nchan_out_buff = max( nchan_out_buff, nchan_internal + st_ivas->nchan_ism ); + } + nchan_out_buff = min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); + } + else if ( st_ivas->ivas_format == MC_FORMAT ) + { + nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; + + if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); + } + else + { + nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); + } + } + + + return nchan_out_buff; +} +#else Word16 ivas_get_nchan_buffers_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 sba_analysis_order, /* i : SBA order evaluated in SBA decoder */ @@ -680,7 +824,7 @@ Word16 ivas_get_nchan_buffers_dec( return nchan_out_buff; } - +#endif /*-------------------------------------------------------------------* * ivas_output_buff_dec()