From 942d7bf39c20a81ea1f09afd4bcf61fc652ff279 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 20 Oct 2024 17:22:58 +0530 Subject: [PATCH] MASA and SBA path functions conversion, cleanup and MSAN error fixes [x] Fix for MSAN errors [x] T_CldfbVadState_fx clean up [x] ivas_encode_masaism_metadata: converted this function and all its sub-functions [x] calculate_hodirac_sector_parameters function conversion [x] Q-info for decoder files [x] Float code cleanup --- lib_com/ivas_prot.h | 82 ++-- lib_com/ivas_prot_fx.h | 13 + lib_com/ivas_spar_com.c | 3 +- lib_dec/ivas_masa_dec.c | 273 ++++++----- lib_dec/ivas_mc_param_dec.c | 290 ++++++------ lib_dec/ivas_mc_paramupmix_dec.c | 172 +++---- lib_dec/ivas_sba_dec.c | 2 +- lib_dec/ivas_stereo_mdct_stereo_dec.c | 293 ++++++------ lib_dec/ivas_stereo_switching_dec.c | 639 +++++++++++++------------- lib_dec/ivas_stereo_td_dec.c | 290 ++++++------ lib_enc/ivas_agc_enc.c | 22 +- lib_enc/ivas_enc.c | 238 ++++++---- lib_enc/ivas_init_enc.c | 163 ++++++- lib_enc/ivas_masa_enc.c | 336 +++++++++++++- lib_enc/ivas_mcmasa_enc.c | 2 +- lib_enc/ivas_mct_enc.c | 152 +++++- lib_enc/ivas_omasa_enc.c | 288 +++++++++++- lib_enc/ivas_pca_enc.c | 13 +- lib_enc/ivas_spar_encoder.c | 45 +- lib_enc/ivas_spar_md_enc.c | 73 ++- lib_enc/ivas_stat_enc.h | 45 +- lib_enc/ivas_stereo_switching_enc.c | 2 +- lib_enc/lib_enc.c | 2 +- lib_enc/peak_vq_enc_fx.c | 4 +- 24 files changed, 2271 insertions(+), 1171 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index cbd4b6ce9..f0181aa9e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -965,9 +965,9 @@ void smooth_dft2td_transition( ); void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs */ - const Word16 output_frame /* i : output frame lenght */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ + const Word16 output_frame /* i : output frame lenght Q0*/ ); /*! r: flag indicating a valid bitrate */ int16_t is_IVAS_bitrate( @@ -2759,7 +2759,7 @@ void stereo_td_init_dec( void stereo_td_init_dec_fx( STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode /* i : last element mode */ + const Word16 last_element_mode /* i : last element mode Q0*/ ); void tdm_configure_dec( @@ -2783,15 +2783,15 @@ void tdm_upmix_plain( ); void tdm_upmix_plain_fx( - Word32 Left_fx[], /* o : left channel */ - Word32 Right_fx[], /* o : right channel */ - const Word32 PCh_2_L_fx[], /* i : primary channel */ - const Word32 SCh_2_R_fx[], /* i : secondary channel */ - const Word32 LR_ratio_fx, /* i : mixing ratio */ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const Word16 start_index, /* i : start index */ - const Word16 end_index, /* i : end index */ - const Word16 plus_minus_flag /* i : plus/minus flag */ + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ ); void stereo_tdm_combine( @@ -2804,12 +2804,12 @@ void stereo_tdm_combine( ); void stereo_tdm_combine_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel */ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel*/ - const Word16 output_frame, /* i : Number of samples */ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ); #ifdef IVAS_FLOAT_FIXED Word16 tdm_lp_comparison_fx( @@ -3662,9 +3662,9 @@ void applyDmxMdctStereo( ); void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder */ - const Word16 output_frame /* i : output frame length */ + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ ); @@ -4104,7 +4104,7 @@ void stereo_switching_enc( #endif void stereo_switching_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ); void stereo_td2dft_update( @@ -4117,12 +4117,12 @@ void stereo_td2dft_update( ); void stereo_td2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number */ - Word32 output_fx[], /* i/o: synthesis @internal Fs */ - Word32 synth_fx[], /* i/o: synthesis @output Fs */ - Word32 hb_synth_fx[], /* i/o: hb synthesis */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number Q0*/ + Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ + const Word16 output_frame /* i : frame length Q0*/ ); void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -4131,9 +4131,9 @@ void stereo_mdct2dft_update( ); void stereo_mdct2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ - Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ ); /*! r: number of bits written */ #ifdef IVAS_FLOAT_FIXED @@ -5878,12 +5878,12 @@ void ivas_sba_mix_matrix_determiner( /* AGC */ /*! r: AGC enable flag */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_agc_enc_get_flag( const int16_t nchan_transport /* i : number of transport channels */ ); - -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_agc_enc_get_flag_fx( +#else +Word16 ivas_agc_enc_get_flag( const Word16 nchan_transport /* i : number of transport channels */ ); #endif @@ -7160,9 +7160,11 @@ void ivas_masa_estimate_energy( const int16_t nchan_transport /* i : number of MASA input/transport channels */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_masa_enc_config( Encoder_Struct* st_ivas /* i/o: IVAS encoder structure */ ); +#endif void ivas_masa_set_elements( const int32_t ivas_total_brate, /* i : codec total bitrate */ @@ -8073,9 +8075,11 @@ void ivas_omasa_enc_close( OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_omasa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#endif // !IVAS_FLOAT_FIXED ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -8465,10 +8469,10 @@ void dequantize_sns_fx( Decoder_State **sts ); void inverseMS_fx( - const Word16 L_frame, /* i : frame length */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ); #endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 72f26cd92..513f686a7 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3467,4 +3467,17 @@ void ivas_omasa_encode_masa_to_total_fx( const Word16 low_bitrate_mode, const Word16 nbands, const Word16 nblocks ); +ivas_error ivas_masa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +ivas_error ivas_omasa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_omasa_enc_close_fx( + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ +); +ivas_error ivas_omasa_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); #endif diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 9c1a30630..17bc88128 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -274,7 +274,7 @@ void ivas_spar_config_fx( } ELSE { - *nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_order ); + *nchan_transport = ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order ); move16(); } @@ -460,7 +460,6 @@ int16_t ivas_get_sba_num_TCs( return nchan_transport; } - #ifdef IVAS_FLOAT_FIXED Word16 ivas_get_sba_num_TCs_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f38ffb289..6903773ed 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -590,7 +590,7 @@ ivas_error ivas_masa_decode( ivas_error ivas_masa_decode_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ Decoder_State *st, /* i/o: decoder state structure with bitstream */ - Word16 *nb_bits_read /* o : number of bits read */ + Word16 *nb_bits_read /* o : number of bits read Q0*/ ) { UWord16 byteBuffer; @@ -651,7 +651,7 @@ ivas_error ivas_masa_decode_fx( move16(); /* masa_brate / FRAMES_PER_SEC */ - tmp = extract_l( Mpy_32_32( masa_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + tmp = extract_l( Mpy_32_32( masa_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 IF( EQ_32( masa_brate, IVAS_SID_5k2 ) ) { @@ -1102,7 +1102,7 @@ ivas_error ivas_masa_decode_fx( FOR( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) { st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_sub( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], - st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][meta_write_index][b] ); + st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][meta_write_index][b] ); // Q30 move32(); } } @@ -1114,7 +1114,7 @@ ivas_error ivas_masa_decode_fx( FOR( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) { - st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_max( 0, st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] ); + st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = L_max( 0, st_ivas->hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] ); // Q30 move32(); } } @@ -1992,11 +1992,11 @@ static void replicate_subframes_fx( { hQMetaData->q_direction[dir].band_data[band].spherical_index[sf] = hQMetaData->q_direction[dir].band_data[band].spherical_index[0]; move16(); - hQMetaData->q_direction[dir].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[dir].band_data[band].azimuth_fx[0]; + hQMetaData->q_direction[dir].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[dir].band_data[band].azimuth_fx[0]; // Q22 move32(); - hQMetaData->q_direction[dir].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[dir].band_data[band].elevation_fx[0]; + hQMetaData->q_direction[dir].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[dir].band_data[band].elevation_fx[0]; // Q22 move32(); - hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[0]; + hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[dir].band_data[band].energy_ratio_fx[0]; // Q30 move32(); if ( hQMetaData->q_direction[dir].coherence_band_data != NULL ) @@ -2097,11 +2097,11 @@ static void restore_lowbitrate_masa_fx( hQMetaData->q_direction[0].band_data[band].spherical_index[sf] = hQMetaData->q_direction[0].band_data[band].spherical_index[0]; move16(); - hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[band].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[band].azimuth_fx[0]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[band].elevation_fx[0]; + hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[band].elevation_fx[0]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[0]; // Q30 move32(); if ( hQMetaData->q_direction[0].coherence_band_data != NULL ) @@ -2129,11 +2129,11 @@ static void restore_lowbitrate_masa_fx( { hQMetaData->q_direction[0].band_data[band].spherical_index[sf] = hQMetaData->q_direction[0].band_data[0].spherical_index[sf]; move16(); - hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[sf]; + hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[sf]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[0].elevation_fx[sf]; + hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = hQMetaData->q_direction[0].band_data[0].elevation_fx[sf]; // Q22 move32(); - hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[sf]; + hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[sf]; // Q30 move32(); if ( hQMetaData->q_direction[0].coherence_band_data != NULL ) @@ -2345,13 +2345,13 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->ringBufferLoPointer = 0; move16(); hMasa->hMasaLfeSynth->ringBufferHiPointer = shr( bufferSize, 1 ); move16(); - hMasa->hMasaLfeSynth->lowpassSum_fx = 0; + hMasa->hMasaLfeSynth->lowpassSum_fx = 0; // Q11 move16(); hMasa->hMasaLfeSynth->ringBufferSize = bufferSize; move16(); @@ -2364,11 +2364,11 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->ringBufferLoPointer2 = 0; move16(); - hMasa->hMasaLfeSynth->lowpassSum2_fx = 0; + hMasa->hMasaLfeSynth->lowpassSum2_fx = 0; // Q11 move32(); hMasa->hMasaLfeSynth->ringBufferSize2 = bufferSize; move16(); @@ -2379,7 +2379,7 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncLp_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncLp_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->delayBuffer_syncLp_size = bufferSize; move16(); @@ -2389,22 +2389,22 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size = bufferSize; move16(); /* Interpolation between slots */ - hMasa->hMasaLfeSynth->lfeGainPrev_fx = 0; + hMasa->hMasaLfeSynth->lfeGainPrev_fx = 0; // Q15 move16(); - hMasa->hMasaLfeSynth->transportGainPrev_fx = MAX_WORD16; + hMasa->hMasaLfeSynth->transportGainPrev_fx = MAX_WORD16; // Q15 move16(); /* slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ - slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX ) */ ) ); + slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX ) in Q31*/ ) ); FOR( i = 0; i < slot_size; i++ ) { - hMasa->hMasaLfeSynth->interpolator_fx[i] = div_s( add( i, 1 ), slot_size ); + hMasa->hMasaLfeSynth->interpolator_fx[i] = div_s( add( i, 1 ), slot_size ); // Q15 move16(); } } @@ -2418,7 +2418,7 @@ static ivas_error init_lfe_synth_data_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); + set32_fx( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, 0, bufferSize ); // Q11 hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size = bufferSize; move16(); @@ -2634,7 +2634,7 @@ static Word16 decode_lfe_to_total_energy_ratio_fx( lfeBitsRead = add( lfeBitsRead, 3 ); lfeToTotalEnergyRatioIndices[1] = byteBuffer; /* Scalar index */ move16(); - log2LFEaverage_fx = usdequant_fx( lfeToTotalEnergyRatioIndices[1], MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11 ); + log2LFEaverage_fx = usdequant_fx( lfeToTotalEnergyRatioIndices[1], MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11 ); // Q12 /* 16.4 kbps sends only scalar gain, above it VQ is used */ IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) @@ -3061,7 +3061,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( // st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->element_brate = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); - st_ivas->hSCE[sce_id]->element_brate = L_shr( st_ivas->hSCE[sce_id]->element_brate, sub( 15, tmp_e ) ); + st_ivas->hSCE[sce_id]->element_brate = L_shr( st_ivas->hSCE[sce_id]->element_brate, sub( 15, tmp_e ) ); // Q0 move32(); move32(); @@ -3091,7 +3091,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( { // st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); - tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); + tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); // Q0 st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp32, CPE_CHANNELS ); move32(); @@ -3189,7 +3189,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( IF( st_ivas->hSpar ) { Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 ); - Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, Q_tmp - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); + Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, Q_tmp - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ); // st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q -> Q_tmp st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp; move16(); } @@ -3437,7 +3437,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( slot_fac_fx = BASOP_Util_Divide3232_Scale( 1, hSpar->subframe_nbslots[subframe], &q_slot_fac ); IF( q_slot_fac < 0 ) { - slot_fac_fx = shr( slot_fac_fx, -1 * q_slot_fac ); + slot_fac_fx = shr( slot_fac_fx, -1 * q_slot_fac ); // Q15 } FOR( slot_idx = 0; slot_idx < hSpar->subframe_nbslots[subframe]; slot_idx++ ) { @@ -3498,7 +3498,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( j = 0; j < FOA_CHANNELS; j++ ) { - mixer_mat_sf_bins_real_fx[bin][i][j] = mixer_mat_sf_bands_real_fx[band][i][j]; // 31+q_slot_fac + mixer_mat_sf_bins_real_fx[bin][i][j] = mixer_mat_sf_bands_real_fx[band][i][j]; // 31 move32(); } } @@ -3518,14 +3518,14 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - instEne_fx = (Word64) L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) * L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ); - instEne_fx = W_add( instEne_fx, (Word64) L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) * L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) ); - transportSignalEnergies_64[ch][bin] = W_add( transportSignalEnergies_64[ch][bin], instEne_fx ); + instEne_fx = W_mult0_32_32( L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ), L_shr_sat( inRe_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) ); // Q(2 * common_q) + instEne_fx = W_add( instEne_fx, W_mult0_32_32( (Word64) L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ), L_shr_sat( inIm_fx[ch][slot][bin], sub( q_cldfb[ch][slot], common_q ) ) ) ); // Q(2 * common_q) + transportSignalEnergies_64[ch][bin] = W_add( transportSignalEnergies_64[ch][bin], instEne_fx ); // Q(2 * common_q) move64(); move64(); } - transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inRe_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inRe_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); - transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inIm_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inIm_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); + transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inRe_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inRe_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); // Q(2 * common_q) + transportSignalCrossCorrelation_64[bin] = W_add( transportSignalCrossCorrelation_64[bin], W_mult0_32_32( L_shr_sat( inIm_fx[0][slot][bin], sub( q_cldfb[0][slot], common_q ) ), L_shr_sat( inIm_fx[1][slot][bin], sub( q_cldfb[0][slot], common_q ) ) ) ); // Q(2 * common_q) move64(); move64(); } @@ -3536,12 +3536,35 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_max = GT_64( transportSignalEnergies_max, transportSignalEnergies_64[ch][bin] ) ? transportSignalEnergies_max : transportSignalEnergies_64[ch][bin]; + // transportSignalEnergies_max = GT_64( transportSignalEnergies_max, transportSignalEnergies_64[ch][bin] ) ? transportSignalEnergies_max : transportSignalEnergies_64[ch][bin]; + + if ( LE_64( transportSignalEnergies_max, transportSignalEnergies_64[ch][bin] ) ) + { + transportSignalEnergies_max = transportSignalEnergies_64[ch][bin]; // Q(2 * common_q) + move64(); + } + } + + // transportSignalCrossCorrelation_max = GT_64( transportSignalCrossCorrelation_max, transportSignalCrossCorrelation_64[bin] ) ? transportSignalCrossCorrelation_max : transportSignalCrossCorrelation_64[bin]; + + if ( LE_64( transportSignalCrossCorrelation_max, transportSignalCrossCorrelation_64[bin] ) ) + { + transportSignalCrossCorrelation_max = transportSignalCrossCorrelation_64[bin]; // Q(2 * common_q) + move64(); } - transportSignalCrossCorrelation_max = GT_64( transportSignalCrossCorrelation_max, transportSignalCrossCorrelation_64[bin] ) ? transportSignalCrossCorrelation_max : transportSignalCrossCorrelation_64[bin]; } - max_common_val = GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ? transportSignalEnergies_max : transportSignalCrossCorrelation_max; + // max_common_val = GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ? transportSignalEnergies_max : transportSignalCrossCorrelation_max; + + IF( GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ) + { + max_common_val = transportSignalEnergies_max; // Q(2 * common_q) + } + ELSE + { + max_common_val = transportSignalCrossCorrelation_max; // Q(2 * common_q) + } + move64(); IF( max_common_val != 0 ) { @@ -3552,10 +3575,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_32[ch][bin] = W_extract_l( transportSignalEnergies_64[ch][bin] ); + transportSignalEnergies_32[ch][bin] = W_extract_l( transportSignalEnergies_64[ch][bin] ); // Q(q_max_common) move32(); } - transportSignalCrossCorrelation_32[bin] = W_extract_l( transportSignalCrossCorrelation_64[bin] ); + transportSignalCrossCorrelation_32[bin] = W_extract_l( transportSignalCrossCorrelation_64[bin] ); // Q(q_max_common) move32(); } q_max_common = shl( common_q, 1 ); @@ -3566,10 +3589,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_32[ch][bin] = W_extract_l( W_shr( transportSignalEnergies_64[ch][bin], sub( 32, headroom_left_max_common ) ) ); + transportSignalEnergies_32[ch][bin] = W_extract_l( W_shr( transportSignalEnergies_64[ch][bin], sub( 32, headroom_left_max_common ) ) ); // Q(q_max_common) move32(); } - transportSignalCrossCorrelation_32[bin] = W_extract_l( W_shr( transportSignalCrossCorrelation_64[bin], sub( 32, headroom_left_max_common ) ) ); + transportSignalCrossCorrelation_32[bin] = W_extract_l( W_shr( transportSignalCrossCorrelation_64[bin], sub( 32, headroom_left_max_common ) ) ); // Q(q_max_common) move32(); } q_max_common = sub( shl( common_q, 1 ), sub( 32, headroom_left_max_common ) ); @@ -3581,10 +3604,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - transportSignalEnergies_32[ch][bin] = 0; + transportSignalEnergies_32[ch][bin] = 0; // Q(q_max_common) move32(); } - transportSignalCrossCorrelation_32[bin] = 0; + transportSignalCrossCorrelation_32[bin] = 0; // Q(q_max_common) move32(); } q_max_common = 31; @@ -3605,7 +3628,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( /* Set the energy of the first transport signal */ IF( EQ_16( nchan_transport, 1 ) ) { - inCovarianceMtx_fx[0][0] = ONE_IN_Q31; /* In case of 1TC, fixed value can be used */ + inCovarianceMtx_fx[0][0] = ONE_IN_Q31; /* In case of 1TC, fixed value can be used, Q(q_inCovarianceMtx)*/ move32(); q_inCovarianceMtx = 31; /* In case of 1TC, fixed value can be used */ move16(); @@ -3642,19 +3665,19 @@ void ivas_spar_param_to_masa_param_mapping_fx( compute_foa_cov_matrix_fx( foaCovarianceMtx_fx, inCovarianceMtx_fx, mixer_mat_sf_bins_real_fx[bin] ); - Iy_fx = foaCovarianceMtx_fx[0][1]; /* Intensity in Y direction */ + Iy_fx = foaCovarianceMtx_fx[0][1]; /* Intensity in Y direction */ // Q(q_inCovarianceMtx) + 2 * Q(31) - 62 move32(); - Iz_fx = foaCovarianceMtx_fx[0][2]; /* Intensity in Z direction */ + Iz_fx = foaCovarianceMtx_fx[0][2]; /* Intensity in Z direction */ // Q(q_inCovarianceMtx) + 2 * Q(31) - 62 move32(); - Ix_fx = foaCovarianceMtx_fx[0][3]; /* Intensity in X direction */ + Ix_fx = foaCovarianceMtx_fx[0][3]; /* Intensity in X direction */ // Q(q_inCovarianceMtx) + 2 * Q(31) - 62 move32(); - Word64 I1 = W_mult0_32_32( Ix_fx, Ix_fx ); - Word64 I2 = W_mult0_32_32( Iy_fx, Iy_fx ); - Word64 I3 = W_mult0_32_32( Iz_fx, Iz_fx ); - Word64 I_res = W_add( W_add( I1, I2 ), I3 ); + Word64 I1 = W_mult0_32_32( Ix_fx, Ix_fx ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) + Word64 I2 = W_mult0_32_32( Iy_fx, Iy_fx ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) + Word64 I3 = W_mult0_32_32( Iz_fx, Iz_fx ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) + Word64 I_res = W_add( W_add( I1, I2 ), I3 ); // 2 * (Q(q_inCovarianceMtx) + 2 * Q(31) - 62) - Word64 E_fx_64 = W_add( W_add( W_add( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ); + Word64 E_fx_64 = W_add( W_add( W_add( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ); // Q(q_inCovarianceMtx) E_fx = L_shr_sat( L_add_sat( L_add_sat( L_add_sat( foaCovarianceMtx_fx[0][0], foaCovarianceMtx_fx[1][1] ), foaCovarianceMtx_fx[2][2] ), foaCovarianceMtx_fx[3][3] ), 1 ); E_fx_64 = W_shr( E_fx_64, 1 ); @@ -3662,7 +3685,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( Word16 q_I_res; IF( LT_16( headroom_left_I_res, 32 ) ) { - I_res = W_shr( I_res, sub( 32, headroom_left_I_res ) ); + I_res = W_shr( I_res, sub( 32, headroom_left_I_res ) ); // q_I_res q_I_res = sub( 31, sub( shl( q_inCovarianceMtx, 1 ), sub( 32, headroom_left_I_res ) ) ); } ELSE @@ -3678,11 +3701,11 @@ void ivas_spar_param_to_masa_param_mapping_fx( } azi_q = 0; move16(); - azi_fx = BASOP_util_atan2( Iy_fx, Ix_fx, azi_q ); /* Azimuth */ + azi_fx = BASOP_util_atan2( Iy_fx, Ix_fx, azi_q ); /* Azimuth Q13*/ - Word64 I_ele_x = W_mult0_32_32( Ix_fx, Ix_fx ); - Word64 I_ele_y = W_mult0_32_32( Iy_fx, Iy_fx ); - Word64 I_ele = W_add( I_ele_x, I_ele_y ); + Word64 I_ele_x = W_mult0_32_32( Ix_fx, Ix_fx ); // Q(ele_q) + Word64 I_ele_y = W_mult0_32_32( Iy_fx, Iy_fx ); // Q(ele_q) + Word64 I_ele = W_add( I_ele_x, I_ele_y ); // Q(ele_q) Word16 headroom_left_I_ele = W_norm( I_ele ); IF( LT_16( headroom_left_I_ele, 32 ) ) { @@ -3696,11 +3719,11 @@ void ivas_spar_param_to_masa_param_mapping_fx( I_ele = Sqrt32( W_extract_l( I_ele ), &ele_q ); IF( ele_q < 0 ) { - I_ele = W_shr( I_ele, negate( ele_q ) ); + I_ele = W_shr( I_ele, negate( ele_q ) ); // Q0 ele_q = 0; move16(); } - ele_fx = BASOP_util_atan2( Iz_fx, W_extract_l( I_ele ), sub( sub( 31, q_inCovarianceMtx ), ele_q ) ); + ele_fx = BASOP_util_atan2( Iz_fx, W_extract_l( I_ele ), sub( sub( 31, q_inCovarianceMtx ), ele_q ) ); // Q13 num_q = sub( 31, q_I_res ); denom_q = q_inCovarianceMtx; @@ -3718,43 +3741,43 @@ void ivas_spar_param_to_masa_param_mapping_fx( move32(); ratio_float_fx = BASOP_Util_Divide3232_Scale( I_fx, E_fx, &res_q ); res_q = sub( res_q, sub( num_q, denom_q ) ); - ratio_fx = L_shl_sat( ratio_float_fx, add( Q15, res_q ) ); + ratio_fx = L_shl_sat( ratio_float_fx, add( Q15, res_q ) ); // Q(15 + res_q) - ratio_fx = L_max( 0, L_min( ratio_fx, ONE_IN_Q30 ) ); + ratio_fx = L_max( 0, L_min( ratio_fx, ONE_IN_Q30 ) ); // Q30 - azi_val = W_mult0_32_32( azi_fx, ONE_BY_PI_OVER_180_Q25 ); + azi_val = W_mult0_32_32( azi_fx, ONE_BY_PI_OVER_180_Q25 ); // Q13 + Q25 IF( azi_val < 0 ) { - azi_val = W_shr( W_neg( azi_val ), 13 + 25 ); + azi_val = W_shr( W_neg( azi_val ), 13 + 25 ); // Q0 azi_val = W_neg( azi_val ); } ELSE { - azi_val = W_shr( azi_val, 13 + 25 ); + azi_val = W_shr( azi_val, 13 + 25 ); // Q0 } - ele_val = W_mult0_32_32( ele_fx, ONE_BY_PI_OVER_180_Q25 ); + ele_val = W_mult0_32_32( ele_fx, ONE_BY_PI_OVER_180_Q25 ); // Q13 + q25 IF( ele_val < 0 ) { - ele_val = W_shr( W_neg( ele_val ), 13 + 25 ); - ele_val = W_neg( ele_val ); + ele_val = W_shr( W_neg( ele_val ), 13 + 25 ); // Q0 + ele_val = W_neg( ele_val ); // Q0 } ELSE { - ele_val = W_shr( ele_val, 13 + 25 ); + ele_val = W_shr( ele_val, 13 + 25 ); // Q0 } - hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (Word16) azi_val; + hSpatParamRendCom->azimuth[dirac_write_idx][bin] = extract_l( W_extract_l( azi_val ) ); // Q0 move16(); - hSpatParamRendCom->elevation[dirac_write_idx][bin] = (Word16) ele_val; + hSpatParamRendCom->elevation[dirac_write_idx][bin] = extract_l( W_extract_l( ele_val ) ); // Q0 move16(); - hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = ratio_fx; + hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = ratio_fx; // Q30 move32(); - hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_sub( ONE_IN_Q30, ratio_fx ); + hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_sub( ONE_IN_Q30, ratio_fx ); // Q30 move32(); - hSpatParamRendCom->spreadCoherence_fx[dirac_write_idx][bin] = 0; + hSpatParamRendCom->spreadCoherence_fx[dirac_write_idx][bin] = 0; // Q15 move16(); - hSpatParamRendCom->surroundingCoherence_fx[dirac_write_idx][bin] = 0; + hSpatParamRendCom->surroundingCoherence_fx[dirac_write_idx][bin] = 0; // q15 move16(); /* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */ @@ -3762,15 +3785,15 @@ void ivas_spar_param_to_masa_param_mapping_fx( { IF( EQ_16( nchan_transport, 1 ) ) { - diffuseGainY_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][1][1] ); - diffuseGainX_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][3][2] ); - diffuseGainZ_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][2][3] ); + diffuseGainY_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][1][1] ); // Q31 + diffuseGainX_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][3][2] ); // Q31 + diffuseGainZ_fx = L_abs( mixer_mat_sf_bins_real_fx[bin][2][3] ); // Q31 } ELSE IF( EQ_16( nchan_transport, 2 ) ) { - diffuseGainY_fx = L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][1][1], transportSignalEnergies_32[1][bin] ) ); - diffuseGainX_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][2], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][1], transportSignalEnergies_32[1][bin] ) ) ); - diffuseGainZ_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][3], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][1], transportSignalEnergies_32[1][bin] ) ) ); + diffuseGainY_fx = L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][1][1], transportSignalEnergies_32[1][bin] ) ); // Q(q_max_common) + diffuseGainX_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][2], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][3][1], transportSignalEnergies_32[1][bin] ) ) ); // Q(q_max_common) + diffuseGainZ_fx = L_add_sat( L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][3], transportSignalEnergies_32[0][bin] ) ), L_abs( Mpy_32_32( mixer_mat_sf_bins_real_fx[bin][2][1], transportSignalEnergies_32[1][bin] ) ) ); // Q(q_max_common) } ELSE { @@ -3785,7 +3808,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( IF( diffuseGainSum_fx == 0 ) { - hDiffuseDist->diffuseRatioX_fx[bin] = 715827904; + hDiffuseDist->diffuseRatioX_fx[bin] = 715827904; //(1.0f / 3.0f) in Q31 move32(); hDiffuseDist->diffuseRatioY_fx[bin] = 715827904; move32(); @@ -3796,44 +3819,44 @@ void ivas_spar_param_to_masa_param_mapping_fx( { Word16 temp_q = 0; move16(); - Word16 intermediate_results; - intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainX_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + Word16 intermediate_results; // temp_q + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainX_fx, L_add_sat( diffuseGainSum_fx, EPSILON_FX_SMALL ), &temp_q ); // saturating value to less than 1 IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, negate( temp_q ) ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); // Q15 } ELSE { - intermediate_results = shl_sat( intermediate_results, temp_q ); + intermediate_results = shl_sat( intermediate_results, temp_q ); // Q15 } - hDiffuseDist->diffuseRatioX_fx[bin] = L_deposit_h( intermediate_results ); + hDiffuseDist->diffuseRatioX_fx[bin] = L_deposit_h( intermediate_results ); // Q31 move32(); - intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainY_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainY_fx, L_add_sat( diffuseGainSum_fx, EPSILON_FX_SMALL ), &temp_q ); // saturating value to less than 1 IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, negate( temp_q ) ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); // Q15 } ELSE { - intermediate_results = shl_sat( intermediate_results, temp_q ); + intermediate_results = shl_sat( intermediate_results, temp_q ); // Q15 } - hDiffuseDist->diffuseRatioY_fx[bin] = L_deposit_h( intermediate_results ); + hDiffuseDist->diffuseRatioY_fx[bin] = L_deposit_h( intermediate_results ); // Q31 move32(); - intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainZ_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); + intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainZ_fx, L_add_sat( diffuseGainSum_fx, EPSILON_FX_SMALL ), &temp_q ); // saturating value to less than 1 IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, negate( temp_q ) ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); // Q15 } ELSE { - intermediate_results = shl_sat( intermediate_results, temp_q ); + intermediate_results = shl_sat( intermediate_results, temp_q ); // Q15 } - hDiffuseDist->diffuseRatioZ_fx[bin] = L_deposit_h( intermediate_results ); + hDiffuseDist->diffuseRatioZ_fx[bin] = L_deposit_h( intermediate_results ); // Q31 move32(); } } @@ -4068,9 +4091,9 @@ void ivas_spar_param_to_masa_param_mapping( /* Estimate FOA properties: foaCov = mixMtx * inCov * mixMtx' */ #ifdef IVAS_FLOAT_FIXED static void compute_foa_cov_matrix_fx( - Word32 foaCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix */ - Word32 inCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix */ - Word32 mixMtx_fx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix */ + Word32 foaCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* o : Estimated FOA covariance matrix Qx*/ + Word32 inCov_fx[FOA_CHANNELS][FOA_CHANNELS], /* i : Input covariance matrix Qx*/ + Word32 mixMtx_fx[FOA_CHANNELS][FOA_CHANNELS] /* i : Mixing matrix Q31*/ ) { Word32 tmpMtx_fx[FOA_CHANNELS][FOA_CHANNELS]; @@ -4084,7 +4107,7 @@ static void compute_foa_cov_matrix_fx( move32(); FOR( k = 0; k < FOA_CHANNELS; k++ ) { - tmpMtx_fx[i][j] = L_add_sat( tmpMtx_fx[i][j], Mpy_32_32( mixMtx_fx[i][k], inCov_fx[k][j] ) ); + tmpMtx_fx[i][j] = L_add_sat( tmpMtx_fx[i][j], Mpy_32_32( mixMtx_fx[i][k], inCov_fx[k][j] ) ); // Qx move32(); } } @@ -4099,7 +4122,7 @@ static void compute_foa_cov_matrix_fx( move32(); FOR( k = 0; k < FOA_CHANNELS; k++ ) { - foaCov_fx[i][j] = L_add_sat( foaCov_fx[i][j], Mpy_32_32( tmpMtx_fx[i][k], mixMtx_fx[j][k] ) ); + foaCov_fx[i][j] = L_add_sat( foaCov_fx[i][j], Mpy_32_32( tmpMtx_fx[i][k], mixMtx_fx[j][k] ) ); // Qx move32(); } } @@ -4354,9 +4377,9 @@ static void create_masa_ext_out_meta_fx( { FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { - UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); + UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); - extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; + extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; // Q8 move16(); } } @@ -4415,9 +4438,9 @@ static void create_masa_ext_out_meta_fx( move16(); FOR( dir = 0; dir < numDirections; dir++ ) { - UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); + UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); - extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); + extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); // Q8 move16(); } } @@ -4505,9 +4528,9 @@ static void decode_index_slice( #else static void decode_index_slice_fx( Word16 index, /* i : index to decode */ - Word16 *ratio_idx_ism, /* o : decodec array of integers */ + Word16 *ratio_idx_ism, /* o : decodec array of integers Q0*/ const Word16 nchan_ism, /* i : number of elements in array (objects) */ - const Word16 K /* i : sum of array elements */ + const Word16 K /* i : sum of array elements Q0*/ ) { Word16 i, j, sum, elem; @@ -4555,7 +4578,7 @@ static void decode_index_slice_fx( { elem = idiv1616( j, base[i] ); } - ratio_idx_ism[sub( sub( nchan_ism, i ), 2 )] = elem; + ratio_idx_ism[nchan_ism - i - 2] = elem; move16(); sum = add( sum, elem ); j = sub( j, i_mult( elem, base[i] ) ); @@ -4845,14 +4868,14 @@ static void read_ism_ratio_index( } #else static void read_ism_ratio_index_fx( - Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM read ratio indexes */ + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM read ratio indexes Q0*/ const Word16 nchan_ism, /* i : number of objects */ const Word16 numCodingBands, /* i : number of subbands */ const Word16 sf, /* i : index of subframe */ - Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : previous subframe ISM ratio indexes */ + Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : previous subframe ISM ratio indexes Q0*/ UWord16 *bit_stream, /* i : bitstream */ Word16 *next_bit_pos, /* i/o: position in bitstream */ - const Word32 *masa_to_total_energy_ratio_fx, /* i : masa to total ratios */ + const Word32 *masa_to_total_energy_ratio_fx, /* i : masa to total ratios Q30*/ const Word16 idx_sep_obj, /* i : index of separated index, -1 if none */ Word16 *num_zeros /* i/o: number of zero values in first subframe for separated object */ ) @@ -4969,7 +4992,7 @@ static void read_ism_ratio_index_fx( } ratio_ism_idx[b][i] = add( ratio_ism_idx[b][i], ratio_ism_idx_ref[i] ); move16(); - ratio_ism_idx[b][sub( nchan_ism, 1 )] = sub( ratio_ism_idx[b][sub( nchan_ism, 1 )], ratio_ism_idx[b][i] ); + ratio_ism_idx[b][nchan_ism - 1] = sub( ratio_ism_idx[b][nchan_ism - 1], ratio_ism_idx[b][i] ); move16(); } Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); @@ -5048,7 +5071,7 @@ static void read_ism_ratio_index_fx( { IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) { - FOR( i = 0; i < sub( nchan_ism, add( 1, shift_one ) ); i++ ) + FOR( i = 0; i < nchan_ism - ( 1 + shift_one ); i++ ) { buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); IF( ( buf % 2 ) == 0 ) @@ -5248,8 +5271,8 @@ static void decode_ism_ratios( static void decode_ism_ratios_fx( UWord16 *bit_stream, /* i : bitstream */ Word16 *next_bit_pos, /* i/o: position in bitstream */ - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : masa_to_total energy ratios */ - Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : masa_to_total energy ratios Q30*/ + Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios Q30*/ const Word16 n_ism, /* i : number of objects */ const Word16 nbands, /* i : number of subbands */ const Word16 numSf, /* i : number of subframes */ @@ -5292,7 +5315,7 @@ static void decode_ism_ratios_fx( { IF( LT_32( masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) { - tmp32_fx = ratio_ism[sf][band][n_ism - 1]; + tmp32_fx = ratio_ism[sf][band][n_ism - 1]; // Q30 move32(); ratio_ism[sf][band][n_ism - 1] = ratio_ism[sf][band][0]; move32(); @@ -5490,14 +5513,14 @@ static Word16 ivas_decode_masaism_metadata_fx( const Word16 dirac_md_buffer_length ) { Word16 sf, band, dir, nbands, nblocks, obj, i; - Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; // Q30 Word16 *band_mapping; Word16 b; Word16 bits_ism[MAX_NUM_OBJECTS], index; UWord16 idx_el, idx_az; - Word32 azimuth, elevation; + Word32 azimuth, elevation; // Q22 Word16 nb_bits_read; - Word32 delta_phi; + Word32 delta_phi; // Q22 Word16 meta_write_index; nb_bits_read = *next_bit_pos; @@ -5539,9 +5562,9 @@ static Word16 ivas_decode_masaism_metadata_fx( /* read if same as previous */ IF( bit_stream[( *next_bit_pos )--] ) { - azimuth = hMasaIsmData->q_azimuth_old_fx[obj]; + azimuth = hMasaIsmData->q_azimuth_old_fx[obj]; // Q22 move32(); - elevation = hMasaIsmData->q_elevation_old_fx[obj]; + elevation = hMasaIsmData->q_elevation_old_fx[obj]; // Q22 move32(); } ELSE @@ -5599,12 +5622,12 @@ static Word16 ivas_decode_masaism_metadata_fx( { meta_write_index = add( dirac_bs_md_write_idx, sf ) % dirac_md_buffer_length; - Word16 int_azi = rint_fx( L_shr( azimuth, Q22 - 16 ) ); - Word16 int_ele = rint_fx( L_shr( elevation, Q22 - 16 ) ); + Word16 int_azi = rint_fx( L_shr( azimuth, Q22 - 16 ) ); // Q0, extra -16 is added as int_azi is W16 and azimuth is W32 + Word16 int_ele = rint_fx( L_shr( elevation, Q22 - 16 ) ); // Q0 - hMasaIsmData->azimuth_ism[obj][meta_write_index] = int_azi; + hMasaIsmData->azimuth_ism[obj][meta_write_index] = int_azi; // Q0 move16(); - hMasaIsmData->elevation_ism[obj][meta_write_index] = int_ele; + hMasaIsmData->elevation_ism[obj][meta_write_index] = int_ele; // Q0 move16(); } } @@ -5665,7 +5688,7 @@ static Word16 rint_fx( /* returns in Q0 */ Word32 num /* num in Q0 */ ) { - Word32 frac_part = L_abs( num ) & 0x0000FFFF; + Word32 frac_part = L_and( L_abs( num ), 0x0000FFFF ); // Q15 Word16 int_part = extract_h( L_abs( num ) ); Word16 res = int_part; move16(); diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index e2d983154..abf30acad 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -265,8 +265,8 @@ ivas_error ivas_param_mc_dec_open_fx( { st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk; move32(); - st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; - st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; + st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; // Q22 + st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; // Q22 } } ELSE @@ -324,9 +324,9 @@ ivas_error ivas_param_mc_dec_open_fx( // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; Word16 temp_e; Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0 temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); + temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0 hParamMC->slot_size = temp; move16(); set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); @@ -355,8 +355,8 @@ ivas_error ivas_param_mc_dec_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); - set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); + set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); // Q8 + set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); // Q15 param_mc_set_num_synth_bands( output_Fs, hParamMC ); @@ -414,7 +414,7 @@ ivas_error ivas_param_mc_dec_open_fx( FOR( k = 0; k < nchan_out_transport; k++ ) { - Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[L_mult0( k, nchan_out_cov )], nchan_out_cov ); /*Q30*/ + Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/ } /* convert ParamMC parameter bands to SFB */ @@ -454,7 +454,7 @@ ivas_error ivas_param_mc_dec_open_fx( { proto_mtx_norm_fx = ONE_IN_Q26; /*Q26*/ move32(); - FOR( k = 0; k < imult1616( nchan_transport, nchan_out_cov ); k++ ) + FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/ } @@ -465,7 +465,7 @@ ivas_error ivas_param_mc_dec_open_fx( { FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[add( imult1616( k, nchan_out_cov ), i )], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ move32(); } } @@ -507,7 +507,7 @@ ivas_error ivas_param_mc_dec_open_fx( hParamMC->h_freq_domain_decorr_ap_params = NULL; hParamMC->h_freq_domain_decorr_ap_state = NULL; - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0 IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ), @@ -1034,7 +1034,7 @@ static void ivas_param_mc_get_param_band_mapping( Word16 upper = target_band_grouping[target_band_idx + 1]; Word16 lower = target_band_grouping[target_band_idx]; Word16 source_band_in_target_band_cnt = 0; - Word16 norm_fac_fx = 32767; + Word16 norm_fac_fx = 32767; // 1.Q15 source_band_cnt_total = 0; move16(); move16(); @@ -1221,7 +1221,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /*-----------------------------------------------------------------* * set input parameters *-----------------------------------------------------------------*/ - hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); + hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); // Q0 move16(); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; move16(); @@ -1267,8 +1267,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( test(); IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) ) { - Word16 *ild_q_old_fx = hParamMC->icld_q_fx; - Word16 *icc_q_old_fx = hParamMC->icc_q_fx; + Word16 *ild_q_old_fx = hParamMC->icld_q_fx; // Q8 + Word16 *icc_q_old_fx = hParamMC->icc_q_fx; // Q15 IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) { @@ -1287,8 +1287,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { Word16 new_param_band_idx, param_idx, source_param_idx; Word16 num_param_lfe; - Word16 *p_icc_new_fx = hParamMC->icc_q_fx; - Word16 *p_ild_new_fx = hParamMC->icld_q_fx; + Word16 *p_icc_new_fx = hParamMC->icc_q_fx; // Q15 + Word16 *p_ild_new_fx = hParamMC->icld_q_fx; // Q8 Word16 p_ild_new_e = 23; move16(); Word16 p_ild_new_tmp; @@ -1322,11 +1322,11 @@ ivas_error ivas_param_mc_dec_reconfig_fx( move16(); FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { - p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); + p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); // 31 - p_ild_new_e - 16 *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); move16(); } - *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 ), 15 ) ); + *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 /*3.Q13*/ ), 15 ) ); // Q8 move16(); p_ild_new_fx++; } @@ -1411,19 +1411,19 @@ ivas_error ivas_param_mc_dec_reconfig_fx( test(); IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); // Q30 -> Q26 matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx /*Q26*/ ); - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); // Q26 -> Q30 IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - proto_mtx_norm_fx = ONE_IN_Q26; + proto_mtx_norm_fx = ONE_IN_Q26; // Q26 move32(); - FOR( k = 0; k < imult1616( nchan_transport, nchan_out_cov ); k++ ) + FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ ) { - proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); + proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); // Q26 } proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/ @@ -1432,7 +1432,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); // Q26 -> Q30 move32(); } } @@ -1497,7 +1497,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( hParamMC->h_freq_domain_decorr_ap_state = NULL; Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0 IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ), @@ -1571,14 +1571,14 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { /* Cx */ - v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); + v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); // Q(31 - cov_state_old.cx_old_e) + v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx]) /* Cy */ - v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); + v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - cov_state_old.cy_old_e) + v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx]) /* mixing matrix*/ - v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); + v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); // Q(31 - mixing_matrix_old_exp) + v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx]) } } FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) @@ -1586,8 +1586,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { /* residual mixing matrix*/ - v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); - v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); + v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - mixing_matrix_res_old_exp) + v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx]) } } } @@ -1618,12 +1618,12 @@ ivas_error ivas_param_mc_dec_reconfig_fx( IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_RealBuffer_tc_fx ); - hParamMC->Cldfb_RealBuffer_tc_fx = NULL; + hParamMC->Cldfb_RealBuffer_tc_fx = NULL; // Q12 } IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL ) { free( hParamMC->Cldfb_ImagBuffer_tc_fx ); - hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; + hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; // Q12 } n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; @@ -2257,13 +2257,13 @@ void ivas_param_mc_dec_close_fx( IF( hParamMC->icc_q_fx != NULL ) { free( hParamMC->icc_q_fx ); - hParamMC->icc_q_fx = NULL; + hParamMC->icc_q_fx = NULL; // Q15 } IF( hParamMC->icld_q_fx != NULL ) { free( hParamMC->icld_q_fx ); - hParamMC->icld_q_fx = NULL; + hParamMC->icld_q_fx = NULL; // Q8 } /* diffuse prototype info */ IF( hParamMC->diff_proto_info ) @@ -2963,10 +2963,10 @@ void ivas_param_mc_dec_digest_tc_fx( hParamMC = st_ivas->hParamMC; assert( hParamMC ); Word32 *pCx, *pCx_imag; - Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; - Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_e) + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_e) + Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_next_band_e) + Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e) Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 cx_e; @@ -3077,8 +3077,8 @@ void ivas_param_mc_dec_digest_tc_fx( move16(); cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout ); - Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); - Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); + Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); + Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); } hParamMC->Cldfb_ImagBuffer_tc_e = qout; @@ -3096,9 +3096,9 @@ void ivas_param_mc_dec_digest_tc_fx( } IF( is_next_band ) { - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, - &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, cx_next_band_fx, &cx_next_band_e, @@ -3110,9 +3110,9 @@ void ivas_param_mc_dec_digest_tc_fx( } ELSE { - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, - &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, cx_fx, &cx_e, @@ -3151,9 +3151,9 @@ void ivas_param_mc_dec_digest_tc_fx( tmp_cx_imag_e = cx_imag_e; } - FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) + FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) { - real_part_fx = pCx[i]; + real_part_fx = pCx[i]; // Q(31 - cx_buff_e) imag_part_fx = pCx_imag[i]; move32(); move32(); @@ -3649,7 +3649,7 @@ void ivas_param_mc_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[], /* o : rendered time signal */ + Word32 *output_f_fx[], /* o : rendered time signal Q11*/ Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] ) { PARAM_MC_DEC_HANDLE hParamMC; @@ -3667,10 +3667,10 @@ void ivas_param_mc_dec_render_fx( Word32 *p_output_f_fx[MAX_OUTPUT_CHANNELS]; FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - p_output_f_fx[i] = output_f_fx[i]; + p_output_f_fx[i] = output_f_fx[i]; // Q11 } /*Decorrelator*/ - Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; + Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; // Q31 /* format converter */ Word16 channel_active[MAX_OUTPUT_CHANNELS]; @@ -3860,15 +3860,15 @@ void ivas_param_mc_dec_render_fx( /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */ /* memory FOR the decorrelated signal */ - ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); + ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); // Returns Cldfb buffers in Q11(tmp_q) FOR( k = 0; k < nchan_out_cov; k++ ) { FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ ) { - Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); + Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6 move32(); - Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); + Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6 move32(); } } @@ -3878,8 +3878,8 @@ void ivas_param_mc_dec_render_fx( * output synthesis *-----------------------------------------------------------------*/ ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( hParamMC->slots_rendered, nchan_transport ), hParamMC->num_freq_bands )], - &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( hParamMC->slots_rendered, nchan_transport ), hParamMC->num_freq_bands )], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ), + &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], + &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ), nchan_transport, nchan_out_cov, hParamMC ); test(); @@ -3897,8 +3897,8 @@ void ivas_param_mc_dec_render_fx( { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); + Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); // Q1 + Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); // Q1 } } ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hParamMC->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nband_synth, GAIN_LFE_FX ); @@ -3906,8 +3906,8 @@ void ivas_param_mc_dec_render_fx( { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); + Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); // Q6 } } } @@ -3994,8 +3994,8 @@ void ivas_param_mc_dec_render_fx( { FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { - Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); - Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); + Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6 + Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6 } } } @@ -4004,8 +4004,8 @@ void ivas_param_mc_dec_render_fx( { FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ ) { - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6 } } /* update combined orientation access index */ @@ -4031,26 +4031,26 @@ void ivas_param_mc_dec_render_fx( { IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; - ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; // Q6 + ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; // Q6 } ELSE { - RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; - ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6 + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6 } } Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); scale_sig32( output_f_fx[ch], len, 5 - 11 ); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][L_mult0( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands )] ), + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); - scale_sig32( output_f_fx[ch], len, 11 - 5 ); + scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11 } ELSE { - set32_fx( &( output_f_fx[ch][L_mult0( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands )] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); + set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); } } slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] ); @@ -4657,13 +4657,13 @@ static void ivas_param_mc_dec_copy_diffuse_proto( FOR( k = 0; k < nY; k++ ) { - p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); + p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11 FOR( l = 0; l < num_freq_bands_diff; l++ ) { - Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11 move32(); - Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11 move32(); } } @@ -4752,9 +4752,9 @@ static int16_t ivas_param_mc_bin2dec( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_param_mc_uniform_decoder_fx( - Word16 *seq, /* o : decoded sequence of float values */ + Word16 *seq, /* o : decoded sequence of float values hParamCodingInfo -> Q-quant*/ const Word16 sz_seq, /* i : number of values to decode */ - const Word16 *alphabet, /* i : codebook */ + const Word16 *alphabet, /* i : codebook hParamCodingInfo -> Q-quant*/ const Word16 N, /* i : number of bits per coded index */ UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */ ) @@ -4940,7 +4940,7 @@ static void ivas_param_mc_dec_compute_interpolator_fx( IF( bAttackPresent ) { - FOR( idx = 0; idx < shl( attackPos, 1 ); idx++ ) + FOR( idx = 0; idx < attackPos * 2; idx++ ) { interpolator[idx] = 0; move16(); @@ -5047,11 +5047,11 @@ static void remove_lfe_from_cy_fx( ptrCy = cy; ptrCy_out = cy_woLFE; - FOR( lfe_idx1 = 0; lfe_idx1 < add( num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ ) { FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR( lfe_idx2 = 0; lfe_idx2 < add( num_lfe, 1 ); lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ ) { FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { @@ -5325,12 +5325,12 @@ static void ivas_param_mc_get_mixing_matrices( static void ivas_param_mc_get_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup, - Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */ + Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands Q(31 - Cx_in_e)*/ Word16 Cx_in_e, const Word16 param_band_idx, /* i : parameter band index */ - Word32 *mixing_matrix_fx[], + Word32 *mixing_matrix_fx[], // Q(31 - mixing_matrix_e) Word16 *mixing_matrix_e, - Word32 *mixing_matrix_res_fx[], + Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e) Word16 *mixing_matrix_res_e, const Word16 nY_intern, /* i : number of channels in the transported format */ const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ @@ -5352,33 +5352,33 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e) Word16 Cr_e; - Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; + Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e) Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS]; - Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e) Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0; - Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e) Word16 Cproto_e; - Word32 *proto_matrix_ptr_fx; - Word32 *Cx_state_fx; + Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e) + Word32 *Cx_state_fx; // Q(31 - Cx_state_e) Word32 *Cx_old_state_fx; - Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e) Word32 *Cy_old_state_fx; Word16 Cx_state_e; Word16 Cy_state_e; - Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e) Word16 mixing_matrix_res_local_e; Word32 L_tmp; Word16 tmp_e, tmp; Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e; move16(); - Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; + Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e) - Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e) - Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; + Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e) Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e; Word32 *ptrMM_fx; @@ -5418,7 +5418,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1]; move16(); } - lfe_indices[add( hSynthesisOutputSetup->num_lfe, 1 )] = nY_cov; + lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov; move16(); proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0]; proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0]; @@ -5429,9 +5429,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ ); move32(); @@ -5489,9 +5489,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ ) { - IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )], Cproto_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 ) { - Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )] = 0; + Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0; move32(); } } @@ -5539,7 +5539,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e; move16(); - FOR( i = 0; i < imult1616( nX, nX ); i++ ) + FOR( i = 0; i < nX * nX; i++ ) { if ( Cx_old_state_fx[i] != 0 ) { @@ -5555,7 +5555,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( new_e = 0; move16(); - FOR( i = 0; i < imult1616( nY_cov, nY_cov ); i++ ) + FOR( i = 0; i < nY_cov * nY_cov; i++ ) { if ( Cy_old_state_fx[i] != 0 ) { @@ -5614,13 +5614,13 @@ static void ivas_param_mc_get_mixing_matrices_fx( ptrMM_fx = mixing_matrix_res_local_fx; ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx]; - FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR( ch_idx1 = add( lfe_indices[lfe_idx1], 1 ); ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) + FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR( lfe_idx2 = 0; lfe_idx2 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ ) { - FOR( ch_idx2 = add( lfe_indices[lfe_idx2], 1 ); ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); move32(); @@ -5689,9 +5689,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( ptrMM_out_fx = mixing_matrix_fx[param_band_idx]; FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) { - FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); move32(); @@ -6286,7 +6286,7 @@ static void param_mc_update_mixing_matrices_fx( brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; + brange[1] = hParamMC->band_grouping[param_band_idx + 1]; move16(); Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) ); @@ -6503,15 +6503,15 @@ static void ivas_param_mc_dequantize_cov_fx( Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; - Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; + Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e) Word16 Nrqq_e[MAX_OUTPUT_CHANNELS]; - Word32 a_fx[MAX_OUTPUT_CHANNELS]; + Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e) Word16 a_e[MAX_OUTPUT_CHANNELS]; Word16 k; Word16 l; - Word32 *Cyp_fx; + Word32 *Cyp_fx; // Q(31 - Cyp_e) Word16 *Cyp_e; - Word32 ap_fx; + Word32 ap_fx; // Q(31 - ap_e) Word16 ap_e; #ifndef FIX_901_PARAMMC_DEAD_CODE Word16 param_frame_idx; @@ -6536,7 +6536,7 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( k = 0; k < nY_int; k++ ) { - Word32 ref_ener_fx = 0; + Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e) move32(); Word16 ref_ener_e = 0; move16(); @@ -6547,7 +6547,7 @@ static void ivas_param_mc_dequantize_cov_fx( { ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt]; move16(); - ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[add( ref_channel_idx, imult1616( ref_channel_idx, nX ) )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e ); + ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ( ref_channel_idx * nX )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e ); move32(); } @@ -6566,12 +6566,12 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( k = 0; k < nY_int; k++ ) { // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON ); - tmp_e = Cp_buf_e[add( k, imult1616( nY_int, k ) )]; + tmp_e = Cp_buf_e[k + ( nY_int * k )]; move16(); - IF( Cproto_fx[add( k, imult1616( nY_int, k ) )] != 0 ) + IF( Cproto_fx[k + ( nY_int * k )] != 0 ) { - L_tmp = ISqrt32( Cproto_fx[add( k, imult1616( nY_int, k ) )], &tmp_e ); + L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e ); } ELSE { @@ -6587,9 +6587,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_int; l++ ) { - Cy_state_int_fx[add( imult1616( k, nY_int ), l )] = Mpy_32_32( Cproto_fx[add( imult1616( k, nY_int ), l )], a_fx[k] ); + Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] ); move32(); - Cy_state_int_e[add( imult1616( k, nY_int ), l )] = add( Cp_buf_e[add( imult1616( k, nY_int ), l )], a_e[k] ); + Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] ); move16(); } } @@ -6630,13 +6630,13 @@ static void ivas_param_mc_dequantize_cov_fx( Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0]] = tmp; move16(); #else - Cy_state_int_fx[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] ) )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); - Cy_state_int_e[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] ) )] = tmp; + Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = tmp; move16(); - Cy_state_int_fx[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] ) )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); - Cy_state_int_e[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] ) )] = tmp; + Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = tmp; move16(); #endif } @@ -6646,13 +6646,13 @@ static void ivas_param_mc_dequantize_cov_fx( { FOR( k = 0; k < nY_int; k++ ) { - Cy_state_int_fx[add( k, imult1616( 3, nY_int ) )] = ONE_IN_Q31; + Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31; move32(); - Cy_state_int_e[add( k, imult1616( 3, nY_int ) )] = 0; + Cy_state_int_e[k + ( 3 * nY_int )] = 0; move16(); - Cy_state_int_fx[add( 3, imult1616( k, nY_int ) )] = ONE_IN_Q31; + Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31; move32(); - Cy_state_int_e[add( 3, imult1616( k, nY_int ) )] = 0; + Cy_state_int_e[3 + ( k * nY_int )] = 0; move16(); } Nrqq_fx[3] = 0; @@ -6672,9 +6672,9 @@ static void ivas_param_mc_dequantize_cov_fx( /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */ FOR( l = 0; l < nY_int; l++ ) { - Cy_state_int_fx[add( imult1616( k, nY_int ), l )] = Mpy_32_32( Cy_state_int_fx[add( imult1616( k, nY_int ), l )], a_fx[k] ); + Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] ); move32(); - Cy_state_int_e[add( imult1616( k, nY_int ), l )] = add( Cy_state_int_e[add( imult1616( k, nY_int ), l )], a_e[k] ); + Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] ); move16(); } } @@ -6703,9 +6703,9 @@ static void ivas_param_mc_dequantize_cov_fx( IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) ) { /* Cy = dmx*Cy*dmx' */ - Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e) Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; + Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e) Word16 target_ch_ener_e[MAX_CICP_CHANNELS]; Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS]; @@ -6728,8 +6728,8 @@ static void ivas_param_mc_dequantize_cov_fx( { FOR( l = 0; l < nY_int; l++ ) { - L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[add( k, imult1616( l, nY_cov ) )], Nrqq_fx[l] ); - tmp_e = add( ls_conv_dmx_matrix_e[add( k, imult1616( l, nY_cov ) )], Nrqq_e[l] ); + L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] ); + tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] ); L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e ); target_ch_ener_fx[k] = L_tmp; move32(); @@ -6737,12 +6737,12 @@ static void ivas_param_mc_dequantize_cov_fx( move16(); } - dmx_ch_ener_fx[k] = Cy_state_fx[add( k, imult1616( nY_cov, k ) )]; + dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )]; move32(); IF( dmx_ch_ener_fx[k] < 0 ) { - Cy_state_fx[add( k, imult1616( nY_cov, k ) )] = L_negate( Cy_state_fx[add( k, imult1616( nY_cov, k ) )] ); + Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] ); move32(); dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] ); move32(); @@ -6757,7 +6757,7 @@ static void ivas_param_mc_dequantize_cov_fx( } ELSE { - BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[add( k, imult1616( nY_cov, k ) )], &tmp, &tmp_e ); + BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + ( nY_cov * k )], &tmp, &tmp_e ); tmp = Sqrt16( tmp, &tmp_e ); target_ch_ener_fx[k] = L_deposit_h( tmp ); move32(); @@ -6767,9 +6767,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_cov; l++ ) { - Cy_state_fx[add( imult1616( k, nY_cov ), l )] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[add( imult1616( k, nY_cov ), l )] ); + Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] ); move32(); - Cy_buf_e[add( imult1616( k, nY_cov ), l )] = add( target_ch_ener_e[k], Cy_buf_e[add( imult1616( k, nY_cov ), l )] ); + Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] ); move16(); } @@ -6799,13 +6799,13 @@ static void ivas_param_mc_dequantize_cov_fx( /*normalize output matrix to a common exponent*/ tmp = 0; - FOR( k = 0; k < imult1616( nY_int, nY_int ); k++ ) + FOR( k = 0; k < nY_int * nY_int; k++ ) { Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] ); move32(); tmp = s_max( tmp, Cy_buf_e[k] ); } - FOR( k = 0; k < imult1616( nY_int, nY_int ); k++ ) + FOR( k = 0; k < nY_int * nY_int; k++ ) { L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) ); Cy_state_fx[k] = L_tmp; @@ -7205,7 +7205,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( const Word16 num_lfe_bands, /* i : number of parameter bands with coded LFE */ const Word16 band_step, /* i : parameter band step */ const Word16 num_param_bands, /* i : number of parameter bands to decode */ - Word16 *value_buffer /* o : output buffer for decoded parameter values */ + Word16 *value_buffer /* o : output buffer for decoded parameter values hParamCodingInfo -> Q-quant*/ ) { Word16 range_coding; @@ -7272,7 +7272,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( /* dequantize */ FOR( j = 0; j < sz_seq; j++ ) { - dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; + dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant move16(); } } @@ -7290,7 +7290,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( { FOR( i = 0; i < num_param_bands; ++i ) { - dequant_ordered_fx[add( j, imult1616( i, map_size ) )] = dequant_seq_fx[k]; + dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant move16(); k = add( k, 1 ); } @@ -7300,7 +7300,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( { FOR( j = 0; j < n_lfe_idx; j++ ) { - dequant_ordered_fx[add( add( sub( map_size, n_lfe_idx ), j ), imult1616( i, map_size ) )] = dequant_seq_fx[k]; + dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant move16(); k = add( k, 1 ); } @@ -7314,7 +7314,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( test(); IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) ) { - Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); + Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant j++; } IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded ) diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 7cbac3f81..b0f8d25fe 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -118,8 +118,8 @@ void ivas_mc_paramupmix_dec_read_BS( { FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { - hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; - hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; + hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; // Q28 + hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; // Q28 move32(); move32(); } @@ -137,9 +137,9 @@ void ivas_mc_paramupmix_dec_read_BS( nb_bits_read_orig = 0; move16(); last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */ - FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) + FOR( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { - bstr_meta[i] = st_ivas->bit_stream[sub( last_bit_pos, i )]; + bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i]; move16(); } st0->bit_stream = bstr_meta; @@ -219,8 +219,8 @@ void ivas_mc_paramupmix_dec_render( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *input_fx[], /* i : core-coder transport channels */ - Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ + Word32 *input_fx[], /* i : core-coder transport channels Qx*/ + Word32 *output_fx[] /* i/o: synthesized core-coder transport channels Qx*/ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -274,7 +274,7 @@ void ivas_mc_paramupmix_dec_render( ivas_mc_paramupmix_dec_sf( st_ivas, output_local_fx ); - FOR( ch = 0; ch < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) + FOR( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) { output_local_fx[ch] += n_samples_sf; } @@ -495,7 +495,7 @@ static void paramupmix_td_decorr_process_jbm_fx( { Word16 j, k; Word16 offset; - Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; + Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; // Q30 offset = idiv1616( output_frame, 10 ); @@ -515,7 +515,7 @@ static void paramupmix_td_decorr_process_jbm_fx( pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], in_duck_gain[j] ); move16(); } - q_format[k] = sub( q_format[k], Q1 ); + q_format[k] = sub( q_format[k], Q1 ); // q_format-- move16(); } @@ -530,7 +530,7 @@ static void paramupmix_td_decorr_process_jbm_fx( pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], out_duck_gain[j] ); move32(); } - q_format[k] = sub( q_format[k], Q1 ); + q_format[k] = sub( q_format[k], Q1 ); // q_format-- move16(); } } @@ -569,8 +569,8 @@ static void ivas_param_upmix_dec_decorr_subframes( FOR( ch = 0; ch < nchan_internal; ch++ ) { - pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, 8 )]; - p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, 4 )]; + pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 8]; // Q11 + p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 4]; // Q11 } WHILE( nSamplesLeftForTD ) @@ -590,7 +590,7 @@ static void ivas_param_upmix_dec_decorr_subframes( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); + Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); // Setting Q to changed q in q_format } } FOR( ch = 0; ch < nchan_internal; ch++ ) @@ -613,11 +613,13 @@ static void ivas_param_upmix_dec_decorr_subframes( static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, - Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ - Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ - Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word16 *param_interpol_fx, + Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + /* in/out */ // Q6 + Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6 + Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + /* in/out */ // Q6 + Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6 + Word16 *param_interpol_fx, // Q15 const Word16 ch, const Word16 slots_rendered ) { @@ -626,69 +628,69 @@ static void ps_pred_process_sf( Word32 alpha_smp_fx, beta_smp_fx; Word32 *alpha1_fx, *alpha2_fx; Word32 *beta1_fx, *beta2_fx; - Word32 *alpha_prev_fx = hMCParamUpmix->alpha_prev_fx[ch]; - Word32 *beta_prev_fx = hMCParamUpmix->beta_prev_fx[ch]; - Word32 *alpha_sf_fx = hMCParamUpmix->alpha_sf_fx[ch]; - Word32 *beta_sf_fx = hMCParamUpmix->beta_sf_fx[ch]; + Word32 *alpha_prev_fx = hMCParamUpmix->alpha_prev_fx[ch]; // Q28 + Word32 *beta_prev_fx = hMCParamUpmix->beta_prev_fx[ch]; // Q28 + Word32 *alpha_sf_fx = hMCParamUpmix->alpha_sf_fx[ch]; // Q28 + Word32 *beta_sf_fx = hMCParamUpmix->beta_sf_fx[ch]; // Q28 Word32 dalpha_fx, dbeta_fx; Word16 ifac_fx; Word32 alpha_start_fx[IVAS_MAX_NUM_BANDS], beta_start_fx[IVAS_MAX_NUM_BANDS]; Word32 res_a, res_b; - Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); - Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); + Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); // Q28 + Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); // Q28 FOR( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ ) { ipar = qmf_to_par_band[iqmf]; move16(); - alpha1_fx = alpha_prev_fx; + alpha1_fx = alpha_prev_fx; // Q28 move16(); - beta1_fx = beta_prev_fx; + beta1_fx = beta_prev_fx; // Q28 move16(); ismp = 0; move16(); alpha2_fx = hMCParamUpmix->alphas_fx[ch]; beta2_fx = hMCParamUpmix->betas_fx[ch]; - alpha_smp_fx = alpha_start_fx[ipar]; + alpha_smp_fx = alpha_start_fx[ipar]; // Q28 move32(); - beta_smp_fx = beta_start_fx[ipar]; + beta_smp_fx = beta_start_fx[ipar]; // Q28 move32(); FOR( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ ) { IF( ( slots_rendered == 0 ) && ( iismp == 0 ) ) { - ifac_fx = param_interpol_fx[iismp]; + ifac_fx = param_interpol_fx[iismp]; // Q15 move16(); } ELSE { - ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[sub( iismp, 1 )] ); + ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[iismp - 1] ); // Q15 } - dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); + dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); // Q28 dbeta_fx = Mpy_32_16_1( L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx ); alpha_smp_fx = L_add( alpha_smp_fx, dalpha_fx ); beta_smp_fx = L_add( dbeta_fx, beta_smp_fx ); - vmre_fx = qmf_mod_re_fx[ismp][iqmf]; + vmre_fx = qmf_mod_re_fx[ismp][iqmf]; // Q6 move32(); - vmim_fx = qmf_mod_im_fx[ismp][iqmf]; + vmim_fx = qmf_mod_im_fx[ismp][iqmf]; // Q6 move32(); - vsre_fx = qmf_side_re_fx[ismp][iqmf]; + vsre_fx = qmf_side_re_fx[ismp][iqmf]; // Q6 move32(); - vsim_fx = qmf_side_im_fx[ismp][iqmf]; + vsim_fx = qmf_side_im_fx[ismp][iqmf]; // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); - qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); + res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6 + qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); + res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6 qmf_side_im_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); move32(); @@ -706,14 +708,14 @@ static void ps_pred_process_sf( static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */ + Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels Q11*/ ) { Word16 i, ch, slot_idx, k; Word32 *pPcm_temp_fx[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/ /*CLDFB*/ - Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; - Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; + Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6 + Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6 Word16 noparamupmix_delay, n_samples_rendered; MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; @@ -734,8 +736,8 @@ static void ivas_mc_paramupmix_dec_sf( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - pPcm_temp_fx[2 * i] = output_fx[i + 4]; /* un-decorrelated */ - pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated */ + pPcm_temp_fx[2 * i] = output_fx[i + 4]; /* un-decorrelated Q11*/ + pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated Q11*/ } /* CLDFB Analysis*/ @@ -746,7 +748,7 @@ static void ivas_mc_paramupmix_dec_sf( { Word16 q_cldfb = 11; move16(); - cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); } } @@ -754,10 +756,10 @@ static void ivas_mc_paramupmix_dec_sf( { ps_pred_process_sf( hMCParamUpmix, st_ivas->hTcBuffer, - Cldfb_RealBuffer_fx[shl( ch, 1 )], /* in/out */ - Cldfb_ImagBuffer_fx[shl( ch, 1 )], - Cldfb_RealBuffer_fx[add( shl( ch, 1 ), 1 )], /* in/out decorr */ - Cldfb_ImagBuffer_fx[add( shl( ch, 1 ), 1 )], + Cldfb_RealBuffer_fx[2 * ch], /* in/out */ + Cldfb_ImagBuffer_fx[2 * ch], + Cldfb_RealBuffer_fx[2 * ch + 1], /* in/out decorr */ + Cldfb_ImagBuffer_fx[2 * ch + 1], &hMCParamUpmix->param_interpolator_fx[st_ivas->hTcBuffer->slots_rendered], ch, st_ivas->hTcBuffer->slots_rendered ); @@ -767,19 +769,19 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { - Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k]; - Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k]; - Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; - Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; + Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k]; // Q6 + Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k]; // Q6 + Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6 + Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6 move32(); move32(); move32(); move32(); - Cldfb_RealBuffer_fx[shl( ch, 1 )][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[shl( ch, 1 )][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); - Cldfb_RealBuffer_fx[add( shl( ch, 1 ), 1 )][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[add( shl( ch, 1 ), 1 )][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); move32(); move32(); move32(); @@ -814,7 +816,7 @@ static void ivas_mc_paramupmix_dec_sf( cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], - maxBand, st_ivas->cldfbAnaDec[add( MC_PARAMUPMIX_COMBINATIONS * 2, idx_in )], &q_cldfb ); + maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in], &q_cldfb ); } idx_in = add( idx_in, 1 ); } @@ -826,10 +828,10 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) { - Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 + Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 + Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 + Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6 } idx_in = add( idx_in, 2 ); } @@ -858,8 +860,8 @@ static void ivas_mc_paramupmix_dec_sf( { FOR( Word16 idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++ ) { - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); // Q6 } } /* Implement CLDFB synthesis */ @@ -870,20 +872,20 @@ static void ivas_mc_paramupmix_dec_sf( FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ ) { - RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; - ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; + RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; // Q6 + ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; // Q6 } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); // Q11 -> Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] ); - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), L_mult0( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q5 + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q5 -> Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - Scale_sig32( output_fx[ch], imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6 ); + Scale_sig32( output_fx[ch], imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6 ); // Q5 -> Q11 } } ELSE @@ -901,27 +903,27 @@ static void ivas_mc_paramupmix_dec_sf( /* CLDFB synthesis */ FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) { - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q11 -> Q5 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; move16(); FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { Word32 *ptr_im_fx[1], *ptr_re_fx[1]; - ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; - ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; + ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; // Q6 + ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; // Q6 cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] ); } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6 -> Q11 st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; move16(); } // Done to keep entire buffer in q11 FOR( ch = 4; ch < 12; ch++ ) { - Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); + Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); // Q11 } /* adjust delay of other channels */ noparamupmix_delay = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS ); @@ -931,7 +933,7 @@ static void ivas_mc_paramupmix_dec_sf( FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Word32 tmp_buf_fx[L_SUBFRAME5MS_48k]; - Copy32( &output_fx[ch][sub( n_samples_rendered, noparamupmix_delay )], tmp_buf_fx, noparamupmix_delay ); + Copy32( &output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay ); Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], sub( n_samples_rendered, noparamupmix_delay ) ); Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay ); Copy32( tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay ); @@ -945,7 +947,7 @@ static void ivas_mc_paramupmix_dec_sf( Copy32( &output_fx[ch][0], tmp_buf_fx, n_samples_rendered ); Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered ); Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], sub( noparamupmix_delay, n_samples_rendered ) ); - Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][sub( noparamupmix_delay, n_samples_rendered )], n_samples_rendered ); + Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered ); } } } @@ -1040,7 +1042,7 @@ static void huffman_decode( FOR( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[sub( iv, 1 )] ), offset ); + vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[iv - 1] ), offset ); move32(); } @@ -1053,11 +1055,11 @@ static void dequant_alpha( Word32 *v ) { Word16 iv; - const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; + const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; // Q28 FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - v[iv] = quant_table->data[vq[iv]]; + v[iv] = quant_table->data[vq[iv]]; // Q28 move32(); } @@ -1075,8 +1077,8 @@ static void dequant_beta( FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) { - quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; - beta[iv] = quant_table->data[bq[iv]]; + quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; // Q28 + beta[iv] = quant_table->data[bq[iv]]; // Q28 move32(); } @@ -1095,12 +1097,12 @@ static void get_ec_data( IF( EQ_32( parType, ALPHA ) ) { - dequant_alpha( parQ, ab ); + dequant_alpha( parQ, ab ); // Qab = Q28 Copy32( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS ); } ELSE { - dequant_beta( alphaQEnv, parQ, ab ); + dequant_beta( alphaQEnv, parQ, ab ); // Qab = Q28 } return; diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 0c636f741..71c6eeb9e 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -924,7 +924,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( test(); test(); test(); - IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) ) + IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) ) { ivas_spar_dec_close_fx( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index d0fefa50c..b83432db3 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -346,12 +346,12 @@ void stereo_decoder_tcx( *-------------------------------------------------------------------*/ void parse_stereo_from_bitstream( - STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo decoder structure */ - Decoder_State **sts, /* i/o: decoder state structure */ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0)*/ - const Word16 isSBAStereoMode, /* i : flag core coding for SBA */ - Decoder_State *st0, /* i/o: decoder state structure for Bstr*/ - Word16 ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask */ + STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo decoder structure */ + Decoder_State **sts, /* i/o: decoder state structure */ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + const Word16 isSBAStereoMode, /* i : flag core coding for SBA Q0*/ + Decoder_State *st0, /* i/o: decoder state structure for Bstr */ + Word16 ms_mask[NB_DIV][MAX_SFB] /* o : bandwise MS mask Q0*/ ) { Word16 i, k, nSubframes, mdct_stereo_mode; @@ -363,12 +363,12 @@ void parse_stereo_from_bitstream( test(); IF( ( EQ_16( sts[0]->core, TCX_10_CORE ) || ( NE_16( sts[0]->core, sts[1]->core ) ) ) ) { - nSubframes = NB_DIV; + nSubframes = NB_DIV; /* Q0 */ move16(); } ELSE { - nSubframes = 1; + nSubframes = 1; /* Q0 */ move16(); } move16(); @@ -390,8 +390,8 @@ void parse_stereo_from_bitstream( { Word16 I; - hStereoMdct->itd_mode = extract_l( get_next_indice_fx( st0, STEREO_DFT_ITD_MODE_NBITS ) ); - /*(*nb_bits) += STEREO_DFT_ITD_MODE_NBITS;*/ /*ITD mode flag: 1bit*/ + hStereoMdct->itd_mode = extract_l( get_next_indice_fx( st0, STEREO_DFT_ITD_MODE_NBITS ) ); /* Q0 */ + /*(*nb_bits) += STEREO_DFT_ITD_MODE_NBITS;*/ /*ITD mode flag: 1bit*/ hStereoMdct->itd_fx = 0; move32(); @@ -404,23 +404,23 @@ void parse_stereo_from_bitstream( FOR( k = 0; k < nSubframes; k++ ) { - mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); + mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); /* Q0 */ IF( mdct_stereo_mode ) { - mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); + mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); /* Q0 */ } SWITCH( mdct_stereo_mode ) { case 0: - hStereoMdct->mdct_stereo_mode[k] = SMDCT_DUAL_MONO; + hStereoMdct->mdct_stereo_mode[k] = SMDCT_DUAL_MONO; /* Q0 */ move16(); BREAK; case 1: - hStereoMdct->mdct_stereo_mode[k] = SMDCT_MS_FULL; + hStereoMdct->mdct_stereo_mode[k] = SMDCT_MS_FULL; /* Q0 */ move16(); BREAK; case 2: - hStereoMdct->mdct_stereo_mode[k] = SMDCT_BW_MS; + hStereoMdct->mdct_stereo_mode[k] = SMDCT_BW_MS; /* Q0 */ move16(); BREAK; default: @@ -432,13 +432,13 @@ void parse_stereo_from_bitstream( test(); 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 ) ); + hStereoMdct->global_ild[k] = extract_l( get_next_indice_fx( st0, SMDCT_GLOBAL_ILD_BITS ) ); /* Q0 */ move16(); assert( ( GT_16( hStereoMdct->global_ild[k], 0 ) ) && ( LT_16( hStereoMdct->global_ild[k], SMDCT_ILD_RANGE ) ) ); } ELSE { - hStereoMdct->global_ild[1] = hStereoMdct->global_ild[0]; + hStereoMdct->global_ild[1] = hStereoMdct->global_ild[0]; /* Q0 */ move16(); } } @@ -457,7 +457,7 @@ void parse_stereo_from_bitstream( { FOR( i = 0; i < sfbConf->nBandsStereoCore; i++ ) { - ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); + ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); /* Q0 */ move16(); } } @@ -467,21 +467,21 @@ void parse_stereo_from_bitstream( mdct_stereo_mode = extract_l( get_next_indice_fx( st0, 1 ) ); IF( mdct_stereo_mode ) { - mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); + mdct_stereo_mode = add( 1, extract_l( get_next_indice_fx( st0, 1 ) ) ); /* Q0 */ } SWITCH( mdct_stereo_mode ) { case 0: - hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; + hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; /* Q0 */ move16(); BREAK; case 1: - hStereoMdct->IGFStereoMode[k] = SMDCT_MS_FULL; + hStereoMdct->IGFStereoMode[k] = SMDCT_MS_FULL; /* Q0 */ move16(); BREAK; case 2: - hStereoMdct->IGFStereoMode[k] = SMDCT_BW_MS; + hStereoMdct->IGFStereoMode[k] = SMDCT_BW_MS; /* Q0 */ move16(); BREAK; default: @@ -502,14 +502,14 @@ void parse_stereo_from_bitstream( { FOR( i = sfbConf->nBandsStereoCore; i < sfbConf->sfbCnt; i++ ) { - ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); + ms_mask[k][i] = extract_l( get_next_indice_fx( st0, 1 ) ); /* Q0 */ move16(); } } } ELSE { - hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; + hStereoMdct->IGFStereoMode[k] = SMDCT_DUAL_MONO; /* Q0 */ move16(); } } @@ -517,9 +517,9 @@ void parse_stereo_from_bitstream( IF( !mct_on ) { - hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels */ + hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; /* Equal bits to both channels Q0*/ move16(); - hStereoMdct->split_ratio = extract_l( get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ) ); + hStereoMdct->split_ratio = extract_l( get_next_indice_fx( st0, SMDCT_NBBITS_SPLIT_RATIO ) ); /* Q0 */ assert( GT_16( hStereoMdct->split_ratio, 0 ) ); } @@ -535,11 +535,11 @@ void parse_stereo_from_bitstream( * Band-wise M/S stereo processing *-------------------------------------------------------------------*/ static void inverseBwMS_fx( - const Word16 startLine, /* i : start line of sfb */ - const Word16 stopLine, /* i : stop line of sfb */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 startLine, /* i : start line of sfb Q0*/ + const Word16 stopLine, /* i : stop line of sfb Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { Word16 j; @@ -549,9 +549,9 @@ static void inverseBwMS_fx( { tmpValue = x0[j]; move32(); - x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); + x0[j] = Mpy_32_32( L_add( x0[j], x1[j] ), norm_fac ); /* Qx */ move32(); - x1[j] = Mpy_32_32( L_sub_sat( tmpValue, x1[j] ), norm_fac ); + x1[j] = Mpy_32_32( L_sub_sat( tmpValue, x1[j] ), norm_fac ); /* Qx */ move32(); } @@ -565,10 +565,10 @@ static void inverseBwMS_fx( * M/S stereo processing *-------------------------------------------------------------------*/ void inverseMS_fx( - const Word16 L_frame, /* i : frame length */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ ) { inverseBwMS_fx( 0, L_frame, x0, x1, norm_fac ); @@ -584,20 +584,20 @@ void inverseMS_fx( *-------------------------------------------------------------------*/ void stereo_decoder_tcx_fx( STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: MDCT stereo decoder structure */ - Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - Word32 *spec_r_0[NB_DIV], /* i/o: spectrum right channel */ - Word32 *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] */ - Word32 *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] */ - const Word16 mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono */ - const Word16 core_l, /* i : core for left channel (TCX20/TCX10) */ - const Word16 core_r, /* i : core for right channel (TCX20/TCX10) */ - const Word16 igf, /* i : flag for IGF activity */ - const Word16 L_frameTCX_l, /* i : TCX frame length of left channel */ - const Word16 L_frameTCX_r, /* i : TCX frame length of right channel */ - const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ - const Word16 last_core_l, /* i : last core for left channel */ - const Word16 last_core_r, /* i : last core for right channel */ - const Word16 tmp_plc_upmix, /* i : indicates temp upmix for PLC decision */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask Q0*/ + Word32 *spec_r_0[NB_DIV], /* i/o: spectrum right channel Qx*/ + Word32 *spec_l[], /* i/o: spectrum left channel [NB_DIV][N] Qx*/ + Word32 *spec_r[], /* i/o: spectrum right channel [NB_DIV][N] Qx*/ + const Word16 mdct_stereo_mode[], /* i : stereo mode (FB/band wise MS, dual mono Q0*/ + const Word16 core_l, /* i : core for left channel (TCX20/TCX10) Q0*/ + const Word16 core_r, /* i : core for right channel (TCX20/TCX10) Q0*/ + const Word16 igf, /* i : flag for IGF activity Q0*/ + const Word16 L_frameTCX_l, /* i : TCX frame length of left channel Q0*/ + const Word16 L_frameTCX_r, /* i : TCX frame length of right channel Q0*/ + const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ + const Word16 last_core_l, /* i : last core for left channel Q0*/ + const Word16 last_core_r, /* i : last core for right channel Q0*/ + const Word16 tmp_plc_upmix, /* i : indicates temp upmix for PLC decision Q0*/ Word16 *q_x_ch2, Word16 *q_x_ch1 ) { @@ -612,7 +612,7 @@ void stereo_decoder_tcx_fx( test(); if ( ( LE_16( core_l, TCX_20_CORE ) && LE_16( core_r, TCX_20_CORE ) ) || tmp_plc_upmix ) { - nSubframes = 1; + nSubframes = 1; /* Q0 */ move16(); } @@ -640,7 +640,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -660,7 +660,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -681,7 +681,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -701,7 +701,7 @@ void stereo_decoder_tcx_fx( { IF( EQ_32( spec_r_0[k][i], 0 ) ) { - spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); + spec_r[k][i] = Mpy_32_32( spec_r[k][i], NF_RED_FAC_FIXED ); /* Qx */ move32(); } } @@ -725,12 +725,12 @@ void stereo_decoder_tcx_fx( /* set flag to reverse dmx computation in case of right-side panning, only relevant for mono output */ IF( GT_32( hStereoMdct->smooth_ratio_fx, ONE_POINT_3_FIXED ) ) { - hStereoMdct->reverse_dmx = 1; + hStereoMdct->reverse_dmx = 1; /* Q0 */ move16(); } ELSE IF( LT_32( hStereoMdct->smooth_ratio_fx, POINT_9_FIXED ) ) { - hStereoMdct->reverse_dmx = 0; + hStereoMdct->reverse_dmx = 0; /* Q0 */ move16(); } @@ -763,19 +763,19 @@ void stereo_decoder_tcx_fx( IF( ( GT_32( nrgRatio, ONE_IN_Q26 ) ) && ( LT_16( k, tmp1 ) ) ) { shift = norm_l( nrgRatio ); - nrgRatio = L_shl( nrgRatio, shift ); - v_multc_fixed( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r ); - Scale_sig32( spec_r[k], L_frameTCX_r, sub( 5, shift ) ); + nrgRatio = L_shl( nrgRatio, shift ); /* Q26 + shift */ + v_multc_fixed( spec_r[k], nrgRatio, spec_r[k], L_frameTCX_r ); /* spec_r will be in Qx + shift - Q5 */ + Scale_sig32( spec_r[k], L_frameTCX_r, sub( 5, shift ) ); /* Qx */ *q_x_ch2 = *q_x_ch2; move16(); } 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 ); + inv_nrgRatio = L_deposit_h( tmp ); /* Q31 - 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 ) ); + v_multc_fixed( spec_l[k], inv_nrgRatio, spec_l[k], L_frameTCX_l ); /* spec_r will be in Qx - tmp_e */ + Scale_sig32( spec_l[k], L_frameTCX_l, sub( 5, shift ) ); /* Qx */ *q_x_ch1 = *q_x_ch1; move16(); } @@ -844,11 +844,11 @@ void inverseMS( #ifdef IVAS_FLOAT_FIXED void initMdctStereoDecData_fx( - STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ - const Word16 igf, /* i : flag indicating IGF activity */ - const H_IGF_GRID igfGrid, /* i : IGF grid configuration */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 bwidth /* i : audio bandwidth */ + STEREO_MDCT_DEC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ + const H_IGF_GRID igfGrid, /* i : IGF grid configuration Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 tcx_coded_lines; @@ -873,17 +873,17 @@ void initMdctStereoDecData_fx( } ELSE { - hStereoMdct->stbParamsTCX20.sfbIgfStart = -1; + hStereoMdct->stbParamsTCX20.sfbIgfStart = -1; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX10.sfbIgfStart = -1; + hStereoMdct->stbParamsTCX10.sfbIgfStart = -1; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX20afterACELP.sfbIgfStart = -1; + hStereoMdct->stbParamsTCX20afterACELP.sfbIgfStart = -1; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX10.nBandsStereoCore = hStereoMdct->stbParamsTCX10.sfbCnt; + hStereoMdct->stbParamsTCX10.nBandsStereoCore = hStereoMdct->stbParamsTCX10.sfbCnt; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX20.nBandsStereoCore = hStereoMdct->stbParamsTCX20.sfbCnt; + hStereoMdct->stbParamsTCX20.nBandsStereoCore = hStereoMdct->stbParamsTCX20.sfbCnt; /* Q0 */ move16(); - hStereoMdct->stbParamsTCX20afterACELP.nBandsStereoCore = hStereoMdct->stbParamsTCX20afterACELP.sfbCnt; + hStereoMdct->stbParamsTCX20afterACELP.nBandsStereoCore = hStereoMdct->stbParamsTCX20afterACELP.sfbCnt; /* Q0 */ move16(); } @@ -971,7 +971,7 @@ ivas_error initMdctStereoDtxData_fx( test(); IF( EQ_16( ch, 1 ) && st->cng_sba_flag ) { - st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); + st->hFdCngDec->hFdCngCom->seed = add( st->hFdCngDec->hFdCngCom->seed, 3 ); /* Q0 */ move16(); } } @@ -1068,8 +1068,8 @@ ivas_error initMdctStereoDtxData( #ifdef IVAS_FLOAT_FIXED void synchonize_channels_mdct_sid_fx( - Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ - const Word16 n /* i : channel number */ + Decoder_State *sts[CPE_CHANNELS], /* i/o: decoder state structure */ + const Word16 n /* i : channel number Q0*/ ) { Decoder_State *st; @@ -1162,7 +1162,13 @@ void synchonize_channels_mdct_sid( // helper function static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ); -static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *buff_b, Word16 legth ) +static void update_exp( + Word16 *a_exp, + Word16 *b_exp, + Word16 *buff_a, /* exp(a_exp) */ + Word16 *buff_b, /* exp(b_exp) */ + Word16 legth /* Q0 */ +) { Word16 diff = 0; move16(); @@ -1171,7 +1177,7 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu diff = sub( *a_exp, *b_exp ); FOR( Word16 j = 0; j < legth; j++ ) { - buff_b[j] = shr( buff_b[j], diff ); + buff_b[j] = shr( buff_b[j], diff ); /* exp(a_exp) */ move16(); } *b_exp = *a_exp; @@ -1183,7 +1189,7 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu FOR( Word16 j = 0; j < legth; j++ ) { - buff_a[j] = shr( buff_a[j], diff ); + buff_a[j] = shr( buff_a[j], diff ); /* exp(b_exp)*/ move16(); } *a_exp = *b_exp; @@ -1191,7 +1197,10 @@ static void update_exp( Word16 *a_exp, Word16 *b_exp, Word16 *buff_a, Word16 *bu } return; } -static Word16 norm_arr( Word16 *arr, Word32 size ) +static Word16 norm_arr( + Word16 *arr, + Word32 size /* Q0 */ +) { Word16 q = 15; move16(); @@ -1203,11 +1212,11 @@ static Word16 norm_arr( Word16 *arr, Word32 size ) return q; } void updateBuffersForDmxMdctStereo_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ - const Word16 output_frame, /* i : output frame length */ - Word32 output0_fx[], - Word32 output1_fx[], - Word16 synth_fx[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 output0_fx[], /* Qx */ + Word32 output1_fx[], /* Qx */ + Word16 synth_fx[CPE_CHANNELS][L_FRAME48k] /* i/o: decoder synthesis qsynth*/ ) { Word16 delay_buf_out_len, tcxltp_mem_in_len, delta, i; @@ -1236,7 +1245,7 @@ void updateBuffersForDmxMdctStereo_fx( 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 ); + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); /* exp(exp_sidNoiseEst0) */ move16(); } exp_sidNoiseEst1 = exp_sidNoiseEst0; @@ -1247,7 +1256,7 @@ void updateBuffersForDmxMdctStereo_fx( 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 ); + sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j] = L_shr( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[j], diff_sidNoiseEst ); /* exp( exp_sidNoiseEst1) */ move16(); } exp_sidNoiseEst0 = exp_sidNoiseEst1; @@ -1262,7 +1271,7 @@ void updateBuffersForDmxMdctStereo_fx( 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++ ) + FOR( Word16 p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ ) { 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 @@ -1291,8 +1300,8 @@ void updateBuffersForDmxMdctStereo_fx( move16(); } - delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); - tcxltp_mem_in_len = NS2SA_FX2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); + delay_buf_out_len = i_mult( delta, HQ_DELAY_COMP ); /* Q0 */ + tcxltp_mem_in_len = NS2SA_FX2( sts[0]->output_Fs, TCXLTP_DELAY_NS ); /* Q0 */ move16(); assert( delay_buf_out_len > tcxltp_mem_in_len ); @@ -1303,11 +1312,11 @@ void updateBuffersForDmxMdctStereo_fx( 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 ); + Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); // Q0 + Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_in_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, -11 ); // Q0 - 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 ); + Copy_Scale_sig_32_16( &sts[0]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); // Q0 + Copy_Scale_sig_32_16( &sts[1]->hTcxLtpDec->tcxltp_mem_out_32[0], &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], L_FRAME48k, -11 ); // Q0 sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = sub( 15, norm_arr( sts[0]->hTcxLtpDec->tcxltp_mem_in, TCXLTP_MAX_DELAY ) ); move16(); @@ -1320,11 +1329,11 @@ void updateBuffersForDmxMdctStereo_fx( move16(); - Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ); - Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_in ) ); + Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in) + Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_in[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_in ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in) - Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ); - Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_out ) ); + Scale_sig( &sts[0]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_out) + Scale_sig( &sts[1]->hTcxLtpDec->tcxltp_mem_out[0], TCXLTP_MAX_DELAY, sub( 15, sts[1]->hTcxLtpDec->exp_tcxltp_mem_out ) ); // (15 - sts[0]->hTcxLtpDec->exp_tcxltp_mem_in) update_exp( &sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_in, @@ -1339,46 +1348,46 @@ void updateBuffersForDmxMdctStereo_fx( FOR( i = 0; i < tcxltp_mem_in_len; i++ ) { 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 + sts[0]->hTcxLtpDec->tcxltp_mem_in[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp ); // 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 + sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); /* Q0 */ + sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // Q0 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 + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); // exp_old_out + 1 + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out + 1 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 + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); // exp_tcxltp_mem_out + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcxltp_mem_out + 1 move16(); } FOR( ; i < delay_buf_out_len; i++ ) { - 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 + sum_delay_buf = add( sts[0]->delay_buf_out_fx[i], sts[1]->delay_buf_out_fx[i] ); // Q0 + sts[0]->delay_buf_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_delay_buf ); // Q0 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 ); + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); /* exp_old_out + 1 */ + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); /* exp_old_out + 1 */ 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 + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); // exp_tcxltp_mem_out + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcxltp_mem_out + 1 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 + sum_old_out = add( shr( sts[0]->hHQ_core->old_out_fx[i], 1 ), shr( sts[1]->hHQ_core->old_out_fx[i], 1 ) ); // exp_old_out + 1 + sts[0]->hHQ_core->old_out_fx[i] = mult( INV_SQRT2_FX_Q15, sum_old_out ); // exp_old_out + 1 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 + sum_tcx_ltp_out = add( shr( sts[0]->hTcxLtpDec->tcxltp_mem_out[i], 1 ), shr( sts[1]->hTcxLtpDec->tcxltp_mem_out[i], 1 ) ); // exp_tcxltp_mem_out + 1 + sts[0]->hTcxLtpDec->tcxltp_mem_out[i] = mult( INV_SQRT2_FX_Q15, sum_tcx_ltp_out ); // exp_tcxltp_mem_out + 1 move16(); } sts[0]->hTcxLtpDec->exp_tcxltp_mem_in = add( sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, 1 ); @@ -1388,8 +1397,8 @@ void updateBuffersForDmxMdctStereo_fx( 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 ) ) ); + 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 ) ) ); // Q11 + 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 ) ) ); // Q11 } return; @@ -1533,20 +1542,20 @@ void applyDmxMdctStereo( } #else void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output */ - const Word16 output_frame /* i : output frame length */ + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: core decoder output q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ ) { Word16 crossfade_len, i; Word16 dmx_len; Word32 fade_fx, step_fx; - step_fx = ONE_IN_Q31; + step_fx = ONE_IN_Q31; /* Q31 */ move32(); - fade_fx = ONE_IN_Q31; + fade_fx = ONE_IN_Q31; /* Q31 */ move32(); - dmx_len = output_frame; + dmx_len = output_frame; /* Q0 */ move16(); test(); @@ -1558,15 +1567,15 @@ void applyDmxMdctStereo_fx( SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: - step_fx = 22369622; + step_fx = 22369622; /* 0.0104 in Q31 */ move32(); BREAK; case 32000: - step_fx = 33554432; + step_fx = 33554432; /* 0.0156 in Q31 */ move32(); BREAK; case 16000: - step_fx = 67108864; + step_fx = 67108864; /* 0.0312 in Q31 */ move32(); BREAK; default: @@ -1577,43 +1586,43 @@ void applyDmxMdctStereo_fx( /* for first inactive CNG frame after active decoding we have to do a fade-OUT FROM the passive DMX */ ELSE IF( LE_32( hCPE->element_brate, IVAS_SID_5k2 ) && GT_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - crossfade_len = shr( output_frame, 2 ); + crossfade_len = shr( output_frame, 2 ); /* Q0 */ SWITCH( output_frame ) { case 960: - step_fx = -8947849; + step_fx = -8947849; /* -0.0041 in Q31 */ move32(); BREAK; case 640: - step_fx = -13421773; + step_fx = -13421773; /* -0.00625 in Q31 */ move32(); BREAK; case 320: - step_fx = -26843546; + step_fx = -26843546; /* -0.0125 in Q31 */ move32(); BREAK; } fade_fx = 0; move32(); - dmx_len = crossfade_len; + dmx_len = crossfade_len; /* Q0 */ move16(); } 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 ); + crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); SWITCH( hCPE->hCoreCoder[0]->output_Fs ) { case 48000: - step_fx = 35791396; + step_fx = 35791396; /* 0.0166 in Q31 */ move32(); BREAK; case 32000: - step_fx = 53687092; + step_fx = 53687092; /* 0.025 in Q31 */ move32(); BREAK; case 16000: - step_fx = 107374184; + step_fx = 107374184; /* 0.05 in Q31 */ move32(); BREAK; default: @@ -1630,17 +1639,17 @@ void applyDmxMdctStereo_fx( /* apply crossfade */ FOR( i = 0; i < crossfade_len; i++ ) { - Word32 temp_1 = Mpy_32_32( output_fx[0][i], fade_fx ); - Word32 temp_2 = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), Mpy_32_32( INV_SQRT2_FX, L_sub_sat( ONE_IN_Q31, fade_fx ) ) ); - output_fx[0][i] = L_add( temp_1, temp_2 ); + Word32 temp_1 = Mpy_32_32( output_fx[0][i], fade_fx ); /* q_out */ + Word32 temp_2 = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), Mpy_32_32( INV_SQRT2_FX, L_sub_sat( ONE_IN_Q31, fade_fx ) ) ); /* q_out */ + output_fx[0][i] = L_add( temp_1, temp_2 ); /* q_out */ move32(); - fade_fx = L_sub_sat( fade_fx, step_fx ); + fade_fx = L_sub_sat( fade_fx, step_fx ); /* Q31 */ } /* apply passive downmix on all-active-frame part */ FOR( ; i < dmx_len; i++ ) { - output_fx[0][i] = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), INV_SQRT2_FX ); + output_fx[0][i] = Mpy_32_32( L_add_sat( output_fx[0][i], output_fx[1][i] ), INV_SQRT2_FX ); /* q_out */ move32(); } diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 3accfa8b6..5f15ccba8 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -559,31 +559,31 @@ static void cpy_tcx_ltp_data( } #else static void cpy_tcx_ltp_data_fx( - TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ - TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ - const Word32 output_Fs /* i : output sampling rate */ + TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ + TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ + const Word32 output_Fs /* i : output sampling rate Q0*/ ) { Word16 sz; - hTcxLtpDecNew->tcxltp_pitch_int_post_prev = hTcxLtpDecOld->tcxltp_pitch_int_post_prev; + hTcxLtpDecNew->tcxltp_pitch_int_post_prev = hTcxLtpDecOld->tcxltp_pitch_int_post_prev; /* Q0 */ move16(); - hTcxLtpDecNew->tcxltp_pitch_fr_post_prev = hTcxLtpDecOld->tcxltp_pitch_fr_post_prev; + hTcxLtpDecNew->tcxltp_pitch_fr_post_prev = hTcxLtpDecOld->tcxltp_pitch_fr_post_prev; /* Q0 */ move16(); - hTcxLtpDecNew->tcxltp_gain_post_prev = hTcxLtpDecOld->tcxltp_gain_post_prev; + hTcxLtpDecNew->tcxltp_gain_post_prev = hTcxLtpDecOld->tcxltp_gain_post_prev; /* Qx */ move16(); - hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; + hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; /* Q0 */ 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 */ ) ); - 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 ); - hTcxLtpDecNew->exp_tcxltp_mem_in = hTcxLtpDecOld->exp_tcxltp_mem_in; + sz = extract_l( Mpy_32_32_r( TCXLTP_MAX_DELAY * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); /* Q0 */ + Copy( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ + Copy32( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); /* exp(exp_tcxltp_mem_in) */ + hTcxLtpDecNew->exp_tcxltp_mem_in = hTcxLtpDecOld->exp_tcxltp_mem_in; /* exp(exp_tcxltp_mem_in) */ move16(); /* (int16_t) ( ( L_FRAME48k * output_Fs ) / 48000 ) */ - sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); - 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 ); - hTcxLtpDecNew->exp_tcxltp_mem_out = hTcxLtpDecOld->exp_tcxltp_mem_out; + sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); /* Q0 */ + Copy( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later /* exp(exp_tcxltp_mem_in) */ + Copy32( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); /* exp(exp_tcxltp_mem_in) */ + hTcxLtpDecNew->exp_tcxltp_mem_out = hTcxLtpDecOld->exp_tcxltp_mem_out; /* exp(exp_tcxltp_mem_in) */ move16(); return; @@ -1256,13 +1256,13 @@ ivas_error stereo_memory_dec( } #else ivas_error stereo_memory_dec_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ - const Word16 nb_bits_metadata, /* i : number of metadata bits */ - const Word32 output_Fs, /* i : output sampling rate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const MC_MODE mc_mode, /* i : MC mode */ - const Word16 nchan_transport /* i : number of transport channels*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + const Word16 nb_bits_metadata, /* i : number of metadata bits Q0*/ + const Word32 output_Fs, /* i : output sampling rate Q0*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { DEC_CORE_HANDLE st; @@ -1276,9 +1276,9 @@ ivas_error stereo_memory_dec_fx( assert( GE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && "Switching from SCE to CPE is not a valid configuration!" ); - hCPE->hCoreCoder[0]->element_mode = hCPE->element_mode; + hCPE->hCoreCoder[0]->element_mode = hCPE->element_mode; /* Q0 */ move16(); - hCPE->hCoreCoder[1]->element_mode = hCPE->element_mode; + hCPE->hCoreCoder[1]->element_mode = hCPE->element_mode; /* Q0 */ move16(); /*--------------------------------------------------------------* @@ -1290,7 +1290,7 @@ ivas_error stereo_memory_dec_fx( 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_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); + delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); /* redressing of the DFT OLA part */ @@ -1298,8 +1298,8 @@ ivas_error stereo_memory_dec_fx( { FOR( i = delay_comp_DFT; i < hCPE->hStereoDft->dft32ms_ovl; i++ ) { - 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 ) ); + div_m = BASOP_Util_Divide3216_Scale( hCPE->output_mem_fx[n][i - delay_comp_DFT], hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( hCPE->hStereoDft->dft32ms_ovl - 1 + delay_comp_DFT - i )], &div_e ); + hCPE->output_mem_fx[n][i - delay_comp_DFT] = L_shl( div_m, add( div_e, 16 ) ); /* div_e + Q16 */ 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) ))]; } @@ -1307,18 +1307,18 @@ ivas_error stereo_memory_dec_fx( IF( hCPE->hCoreCoder[0]->last_core != ACELP_CORE ) { - 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 ) ); + 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 ) ); /* Q11 */ } } 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, 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->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 ) ) ); /* exp(exp_old_out) */ + 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 ) ) ); /* exp(exp_old_out) */ - 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 ); + 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 ); /* q_old_outLB_fx */ + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); /* exp(exp_old_out) */ } /*--------------------------------------------------------------* @@ -1362,7 +1362,7 @@ ivas_error stereo_memory_dec_fx( } /* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */ - 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 ) ); + 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 ) ); /* Q11 */ /* allocate ICBWE structure */ IF( hCPE->hStereoICBWE == NULL ) @@ -1466,11 +1466,11 @@ ivas_error stereo_memory_dec_fx( { /* re-use an existing buffer for MDCT->TD stereo switching */ Word16 nZeros, len; - nZeros = extract_l( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); + nZeros = extract_l( NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ) ); /* Q0 */ move16(); - len = NS2SA_FX2( st->output_Fs, 3000000 ); + len = NS2SA_FX2( st->output_Fs, 3000000 ); /* Q0 */ move16(); - Copy32( 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 ); /* exp(exp_old_out) */ } /* deallocated HQ-core for second channel */ @@ -1588,7 +1588,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - Copy32( 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 ); /* Q11 */ } IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) @@ -1631,7 +1631,7 @@ ivas_error stereo_memory_dec_fx( FOR( i = 0; i < CPE_CHANNELS; i++ ) { st = hCPE->hCoreCoder[i]; - st->element_mode = hCPE->element_mode; + st->element_mode = hCPE->element_mode; /* Q0 */ move16(); /* deallocate core-decoder substructures */ @@ -1672,7 +1672,7 @@ ivas_error stereo_memory_dec_fx( if ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() */ + st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() Q0*/ move16(); } @@ -1696,7 +1696,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - Copy32( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); + Copy32( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); /* Q11 */ 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)) } #ifdef FIX_844_Q_SYN_INIT @@ -1705,8 +1705,8 @@ ivas_error stereo_memory_dec_fx( #endif set16_fx( st->hTcxDec->FBTCXdelayBuf, 0, 111 ); set32_fx( st->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); - st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ); - st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); + st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA_FX2( st->output_Fs, PH_ECU_MEM_NS ); /* q_synth_history_fx */ + st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA_FX2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); /* q_synth_history_fx */ /* allocate and initialize MDCT stereo structure */ IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) @@ -1715,7 +1715,7 @@ ivas_error stereo_memory_dec_fx( } IF( EQ_16( ivas_format, STEREO_FORMAT ) && hCPE->element_brate <= MAX_MDCT_ITD_BRATE ) { - hCPE->hStereoMdct->use_itd = 1; + hCPE->hStereoMdct->use_itd = 1; /* Q0 */ move16(); } ELSE @@ -1725,7 +1725,7 @@ ivas_error stereo_memory_dec_fx( } hCPE->hStereoMdct->reverse_dmx = 0; move16(); - hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; /* Q26 */ move32(); } } @@ -1741,14 +1741,14 @@ ivas_error stereo_memory_dec_fx( st = hCPE->hCoreCoder[1]; IF( hCPE->brate_surplus < 0 ) { - tmp16 = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + tmp16 = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); /* Q0 */ } ELSE { - tmp16 = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + tmp16 = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ } - 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 ), tmp16 ), ( 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 ), tmp16 ), ( TDM_SECONDARY_SIGNALLING + TDM_RATIO_BITS + TDM_LP_REUSE_BITS + TDM_LR_CONTENT_BITS ) ) ), TDM_LR_CONTENT_BITS ); /* Q0 */ move16(); IF( hCPE->hStereoTD->tdm_LRTD_flag != 0 ) @@ -2381,11 +2381,11 @@ void synchro_synthesis( } #else void synchro_synthesis_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : Number of samples */ - const Word16 sba_dirac_stereo_flag, /* i : signal stereo output FOR SBA DirAC */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: output synthesis signal Q11*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output FOR SBA DirAC Q0*/ Word16 output_fx_q ) { Word16 n, delay_comp_TD, delay_comp_DFT; @@ -2406,7 +2406,7 @@ void synchro_synthesis_fx( Word16 nChannels; sts = hCPE->hCoreCoder; - output_Fs = sts[0]->output_Fs; + output_Fs = sts[0]->output_Fs; /* Q0 */ use_cldfb_for_last_dft = 0; move16(); @@ -2419,7 +2419,7 @@ void synchro_synthesis_fx( 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; + use_cldfb_for_last_dft = 1; /* Q0 */ move16(); } @@ -2435,12 +2435,12 @@ void synchro_synthesis_fx( 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 */ + dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo Q0*/ move16(); } 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*/ + dft_mono_brate_switch = 1; /* switch to residual coding mode Q0*/ move16(); } } @@ -2457,14 +2457,14 @@ void synchro_synthesis_fx( } /* set delays */ - delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); + delay_comp_DFT = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - delay_comp_TD = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + delay_comp_TD = NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); /* Q0 */ move16(); - delay_diff = sub( delay_comp_TD, delay_comp_DFT ); + delay_diff = sub( delay_comp_TD, delay_comp_DFT ); /* Q0 */ - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); - delay_cldfb = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); /* Q0 */ + delay_cldfb = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); /* initialize pointers */ @@ -2473,7 +2473,7 @@ void synchro_synthesis_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - p_output_mem_fx[n] = hCPE->output_mem_fx[n]; + p_output_mem_fx[n] = hCPE->output_mem_fx[n]; /* Q11 */ } } @@ -2489,13 +2489,13 @@ void synchro_synthesis_fx( { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][sub( i, delay_comp_DFT )]; + sts[0]->prev_synth_buffer32_fx[i] = p_output_mem_fx[0][i - delay_comp_DFT]; /* Q11 */ move32(); } FOR( i = delay_comp_TD; i < add( delay_comp_TD, delay_cldfb ); i++ ) { - tmp_out_fx[0][sub( i, delay_comp_TD )] = p_output_mem_fx[0][sub( i, delay_comp_DFT )]; + tmp_out_fx[0][i - delay_comp_TD] = p_output_mem_fx[0][i - delay_comp_DFT]; /* Q11 */ move32(); } } @@ -2505,8 +2505,8 @@ void synchro_synthesis_fx( { FOR( Word32 ind = 0; ind < delay_comp_DFT; 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 ); + Word32 temp = L_add( sts[0]->prev_synth_buffer32_fx[ind], sts[1]->prev_synth_buffer32_fx[ind] ); /* Q11 */ + sts[0]->prev_synth_buffer32_fx[ind] = Mpy_32_32( temp, INV_SQRT2_FX ); /* Q11 */ move32(); } } @@ -2514,7 +2514,7 @@ void synchro_synthesis_fx( IF( use_cldfb_for_last_dft ) { /* delay CLDFB-based mono output (<= 24.4 kbps) to be aligned with DFT-based mono output (32 kbps), needed to avoid discontinuities with TCX-LTP. */ - Copy32( sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); + Copy32( sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); /* Q11 */ delay_signal_fx( output_fx[0], output_frame, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); } @@ -2542,7 +2542,7 @@ void synchro_synthesis_fx( } IF( use_cldfb_for_last_dft ) { - Copy32( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); + Copy32( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32, sts[0]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); /* Q11 */ } /* handling of TD->DFT switching */ @@ -2559,15 +2559,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - inv_fade_len_fx = 71582792; + inv_fade_len_fx = 71582792; /* Q31 */ move32(); BREAK; case 32000: - inv_fade_len_fx = 35791396; + inv_fade_len_fx = 35791396; /* Q31 */ move32(); BREAK; case 48000: - inv_fade_len_fx = 23860930; + inv_fade_len_fx = 23860930; /* Q31 */ move32(); BREAK; default: @@ -2577,12 +2577,12 @@ void synchro_synthesis_fx( /* cross-fading between TD synchro memory and the DFT output */ IF( sba_dirac_stereo_flag ) { - pPrev_synth_fx = hCPE->prev_synth_fx[n]; + pPrev_synth_fx = hCPE->prev_synth_fx[n]; /* Q11 */ move32(); } ELSE { - pPrev_synth_fx = sts[n]->prev_synth_buffer32_fx; + pPrev_synth_fx = sts[n]->prev_synth_buffer32_fx; /* Q11 */ move32(); } @@ -2590,12 +2590,12 @@ void synchro_synthesis_fx( { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - 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; + Word64 res1 = W_mult0_32_32( pPrev_synth_fx[i], ( sub( delay_comp_TD, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( output_fx[n][i], ( sub( i, delay_comp_DFT ) ) ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - 6 */ + res = res * inv_fade_len_fx; /* Q11 + 31 - 6 */ move64(); - output_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); // change 6 to less number to get better precision } @@ -2611,21 +2611,21 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - inv_fade_len_1_fx = 71582792; + inv_fade_len_1_fx = 71582792; /* Q31 */ move32(); - inv_fade_len_2_fx = 107374184; + inv_fade_len_2_fx = 107374184; /* Q31 */ move32(); BREAK; case 32000: - inv_fade_len_1_fx = 35791396; + inv_fade_len_1_fx = 35791396; /* Q31 */ move32(); - inv_fade_len_2_fx = 53687092; + inv_fade_len_2_fx = 53687092; /* Q31 */ move32(); BREAK; case 48000: - inv_fade_len_1_fx = 23860930; + inv_fade_len_1_fx = 23860930; /* Q31 */ move32(); - inv_fade_len_2_fx = 35791396; + inv_fade_len_2_fx = 35791396; /* Q31 */ move32(); BREAK; default: @@ -2633,23 +2633,23 @@ void synchro_synthesis_fx( } FOR( i = 0; i < delay_diff; i++ ) { - 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; + Word64 res1 = W_mult0_32_32( output_fx[0][i + delay_comp_DFT], ( sub( delay_diff, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( p_output_mem_fx[0][i], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - 6 */ + res = res * inv_fade_len_1_fx; /* Q11 + 31 - 6 */ move64(); - output_fx[0][add( i, delay_comp_DFT )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[0][i + delay_comp_DFT] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } FOR( i = 0; i < delay_cldfb; i++ ) { - 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; + Word64 res1 = W_mult0_32_32( tmp_out_fx[0][i], ( sub( delay_cldfb, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( output_fx[0][i + delay_comp_TD], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - 6 */ + res = res * inv_fade_len_2_fx; /* Q11 + 31 - 6 */ move64(); - output_fx[0][add( i, delay_comp_TD )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[0][i + delay_comp_TD] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } } @@ -2678,13 +2678,13 @@ void synchro_synthesis_fx( { FOR( i = delay_comp_DFT; i < delay_comp_TD; i++ ) { - sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][sub( i, delay_comp_DFT )]; + sts[n]->prev_synth_buffer32_fx[i] = p_output_mem_fx[n][i - delay_comp_DFT]; /* Q11 */ move32(); } FOR( i = delay_comp_TD; i < add( delay_comp_TD, delay_cldfb ); i++ ) { - tmp_out_fx[n][sub( i, delay_comp_TD )] = p_output_mem_fx[n][sub( i, delay_comp_DFT )]; + tmp_out_fx[n][i - delay_comp_TD] = p_output_mem_fx[n][i - delay_comp_DFT]; /* Q11 */ move32(); } } @@ -2695,9 +2695,9 @@ void synchro_synthesis_fx( 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 ); - Copy32( p_output_mem_fx[0], p_output_mem_fx[1], delay_diff ); + Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); /* Q11 */ + Copy32( tmp_out_fx[0], tmp_out_fx[1], delay_cldfb ); /* Q11 */ + Copy32( p_output_mem_fx[0], p_output_mem_fx[1], delay_diff ); /* Q11 */ } /*----------------------------------------------------------------* @@ -2721,7 +2721,7 @@ 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[sub( i, delay_diff )]; + tmp_out_TD_fx[n][i] = sts[n]->delay_buf_out32_fx[i - delay_diff]; /* Q11 */ move32(); } } @@ -2734,7 +2734,7 @@ void synchro_synthesis_fx( } ELSE { - Copy32( tmp_out_TD_fx[0], tmp_out_TD2_fx[0], dft32ms_ovl ); + Copy32( tmp_out_TD_fx[0], tmp_out_TD2_fx[0], dft32ms_ovl ); /* Q11 */ } FOR( n = 0; n < hCPE->nchan_out; n++ ) @@ -2744,15 +2744,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - tmpF_fx = 71582792; + tmpF_fx = 71582792; /* 0.033 in Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* 0.016 in Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 23860930; + tmpF_fx = 23860930; /* 0.011 in Q31 */ move32(); BREAK; default: @@ -2762,12 +2762,12 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { - 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; + Word64 res1 = W_mult0_32_32( output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i], ( sub( delay_diff, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( tmp_out_TD2_fx[n][i], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - Q6 */ + res = res * tmpF_fx; /* Q11 + Q31 - Q6 */ move64(); - p_output_mem_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); + p_output_mem_fx[n][i] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ } } ELSE /* TCX core */ @@ -2775,7 +2775,7 @@ void synchro_synthesis_fx( /* reconstruct the 3.125 - 1.25 ms OLA part */ FOR( i = 0; i < delay_diff; i++ ) { - p_output_mem_fx[n][i] = output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i]; + p_output_mem_fx[n][i] = output_fx[n][output_frame - dft32ms_ovl + delay_cldfb + i]; /* Q11 */ move32(); } } @@ -2783,7 +2783,7 @@ void synchro_synthesis_fx( /* reconstruct the last 1.25 ms part of OLA window */ FOR( i = delay_diff; i < dft32ms_ovl; i++ ) { - p_output_mem_fx[n][i] = tmp_out_TD2_fx[n][i]; + p_output_mem_fx[n][i] = tmp_out_TD2_fx[n][i]; /* Q11 */ move32(); } } @@ -2801,20 +2801,20 @@ void synchro_synthesis_fx( { Word32 step_fx = 0; move32(); - tmpF_fx = ONE_IN_Q31; + tmpF_fx = ONE_IN_Q31; /* Q31 */ move32(); SWITCH( output_Fs ) { case 16000: - step_fx = 33554432; + step_fx = 33554432; /* 0.0156 in Q31 */ move32(); BREAK; case 32000: - step_fx = 16777216; + step_fx = 16777216; /* 0.0078 in Q31 */ move32(); BREAK; case 48000: - step_fx = 11184811; + step_fx = 11184811; /* 0.0052 in Q31 */ move32(); BREAK; default: @@ -2823,9 +2823,9 @@ void synchro_synthesis_fx( /* FOR the first switching frame from DFT to TD, downmix memory too */ 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 ); + sts[0]->prev_synth_buffer32_fx[n] = Mpy_32_32( sts[0]->prev_synth_buffer32_fx[n], tmpF_fx ); /* Q11 */ move32(); - tmpF_fx = L_sub_sat( tmpF_fx, step_fx ); + tmpF_fx = L_sub_sat( tmpF_fx, step_fx ); /* Q31 */ } } @@ -2834,30 +2834,30 @@ void synchro_synthesis_fx( 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 ); + Copy32( sts[0]->prev_synth_buffer32_fx, sts[1]->prev_synth_buffer32_fx, delay_comp_TD ); /* Q11 */ } // nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out; IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - nChannels = 2; + nChannels = 2; /* Q0 */ move16(); } ELSE { - nChannels = hCPE->nchan_out; + nChannels = hCPE->nchan_out; /* Q0 */ move16(); } FOR( n = 0; n < nChannels; n++ ) { 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 ); + Copy32( sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); /* Q11 */ + delay_signal_fx( output_fx[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, delay_diff ); /* Q11 */ ivas_post_proc_fx( NULL, hCPE, n, output_fx[n], output_fx, output_frame, 0, output_fx_q ); delay_signal_fx( output_fx[n], output_frame, sts[n]->prev_synth_buffer32_fx, delay_comp_DFT ); - Copy32( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); + Copy32( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, sts[n]->prev_synth_buffer32_fx + delay_comp_DFT, delay_diff ); /* Q11 */ } ELSE { @@ -2877,15 +2877,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - tmpF_fx = 107374184; + tmpF_fx = 107374184; /* 0.05 in Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 53687092; + tmpF_fx = 53687092; /* 0.025 in Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* 0.016 in Q31 */ move32(); BREAK; default: @@ -2893,7 +2893,7 @@ void synchro_synthesis_fx( } FOR( i = 0; i < 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 ) ) ) ); + 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 ) ) ) ); /* Q11 */ move32(); } } @@ -2907,15 +2907,15 @@ void synchro_synthesis_fx( SWITCH( output_Fs ) { case 16000: - tmpF_fx = 71582792; + tmpF_fx = 71582792; /* Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 23860930; + tmpF_fx = 23860930; /* Q31 */ move32(); BREAK; default: @@ -2924,27 +2924,27 @@ void synchro_synthesis_fx( FOR( i = 0; i < delay_diff; i++ ) { - 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; + Word64 res1 = W_mult0_32_32( output_fx[n][i + delay_comp_DFT], ( sub( delay_diff, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( p_output_mem_fx[n][i], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - Q6 */ + res = res * tmpF_fx; /* Q11 + Q31 - Q6 */ move64(); - output_fx[n][add( i, delay_comp_DFT )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[n][i + delay_comp_DFT] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } } SWITCH( output_Fs ) { case 16000: - tmpF_fx = 107374184; + tmpF_fx = 107374184; /* Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 53687092; + tmpF_fx = 53687092; /* Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* Q31 */ move32(); BREAK; default: @@ -2952,12 +2952,12 @@ void synchro_synthesis_fx( } FOR( i = 0; i < delay_cldfb; i++ ) { - 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; + Word64 res1 = W_mult0_32_32( tmp_out_fx[n][i], ( sub( delay_cldfb, i ) ) ); /* Q11 */ + Word64 res2 = W_mult0_32_32( output_fx[n][i + delay_comp_TD], i ); /* Q11 */ + Word64 res = W_add( W_shr( res1, 6 ), W_shr( res2, 6 ) ); /* Q11 - Q6 */ + res = res * tmpF_fx; /* Q11 + Q31 - Q6 */ move64(); - output_fx[n][add( i, delay_comp_TD )] = W_extract_l( W_shr( res, 31 - 6 ) ); + output_fx[n][i + delay_comp_TD] = W_extract_l( W_shr( res, 31 - 6 ) ); /* Q11 */ move32(); } } @@ -3010,8 +3010,8 @@ Word32 side_gain_table[32 + 1] = { -ONE_IN_Q31, -2040109440, -1932735232, -18253 322122496, 429496832, 536870912, 644245248, 751619328, 858993408, 966367744, 1073741824, 1181116160, 1288490240 }; void stereo_switching_dec( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) { Word16 i, n; @@ -3028,11 +3028,11 @@ void stereo_switching_dec( /* prevent CPE mode switching in the first received frame */ IF( sts[0]->ini_frame == 0 ) { - hCPE->last_element_mode = hCPE->element_mode; + hCPE->last_element_mode = hCPE->element_mode; /* Q0 */ move16(); - hCPE->stereo_switching_counter = 10; + hCPE->stereo_switching_counter = 10; /* Q0 */ move16(); - hCPE->NbFrameMod = 7; + hCPE->NbFrameMod = 7; /* Q0 */ move16(); hCPE->lt_es_em_fx = 0; move16(); @@ -3040,8 +3040,8 @@ void stereo_switching_dec( IF( EQ_16( hCPE->element_mode, hCPE->last_element_mode ) ) { - hCPE->stereo_switching_counter = add( hCPE->stereo_switching_counter, 1 ); - hCPE->stereo_switching_counter = s_min( 10, hCPE->stereo_switching_counter ); + hCPE->stereo_switching_counter = add( hCPE->stereo_switching_counter, 1 ); /* Q0 */ + hCPE->stereo_switching_counter = s_min( 10, hCPE->stereo_switching_counter ); /* Q0 */ } ELSE { @@ -3054,7 +3054,7 @@ void stereo_switching_dec( 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 = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ set32_fx( hCPE->output_mem_fx[0], 0, dft32ms_ovl ); } test(); @@ -3062,13 +3062,13 @@ void stereo_switching_dec( 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 = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { 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 ); + Copy32( hCPE->input_mem_fx[n], hCPE->output_mem_fx[n], dft32ms_ovl ); /* Q11 */ } test(); @@ -3078,7 +3078,7 @@ void stereo_switching_dec( { 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[i_mult( STEREO_DFT32MS_STEP, ( sub( sub( dft32ms_ovl, 1 ), 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 )] ); /* q_output_mem_fx */ move32(); } } @@ -3086,32 +3086,32 @@ void stereo_switching_dec( { IF( EQ_32( hCPE->hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ) ) { - tmpF_fx = ONE_IN_Q27; + tmpF_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_b = extract_l( L_shr( hCPE->hStereoTCA->prevTargetGain_fx, 16 ) ); + Word16 temp_b = extract_l( L_shr( hCPE->hStereoTCA->prevTargetGain_fx, 16 ) ); /* Q13 */ Word16 temp_b_q = 2; move16(); tmpF_fx = Inv16( temp_b, &temp_b_q ); - tmpF_fx = L_shl( tmpF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); + tmpF_fx = L_shl( tmpF_fx, sub( sub( 31, 4 ), sub( 15, temp_b_q ) ) ); /* Q27 */ } FOR( i = 0; i < dft32ms_ovl; 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 ); + Word32 temp_result = Mpy_32_16_1( tmpF_fx, hCPE->hStereoDft->win32ms_fx[STEREO_DFT32MS_STEP * ( dft32ms_ovl - 1 - i )] ); /* Q27 */ + hCPE->output_mem_fx[n][i] = L_shl_sat( Mpy_32_32( hCPE->output_mem_fx[n][i], temp_result ), 4 ); /* q_output_mem_fx */ } FOR( i = 0; i < delay_comp_TD; i++ ) { Word64 temp_result; - 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 ) ); + temp_result = W_mult0_32_32( hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i], tmpF_fx ); /* q_prev_synth + Q27 */ + hCPE->hCoreCoder[1]->prev_synth_buffer32_fx[i] = W_sat_l( W_shr( temp_result, 27 ) ); /* q_prev_synth */ 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 ); + hCPE->hStereoTCA->memChanR_fx[i] = L_shl_sat( Mpy_32_32( hCPE->hStereoTCA->memChanR_fx[i], tmpF_fx ), 4 ); /* q_mem_chanR */ move32(); } } @@ -3122,15 +3122,15 @@ void stereo_switching_dec( /* create passive downmix of MDCT Stereo memories FOR DFT input memory */ 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 ); + Word32 result_int = L_add_sat( hCPE->input_mem_LB_fx[0][ind], hCPE->input_mem_LB_fx[1][ind] ); /* Q11 */ + hCPE->input_mem_LB_fx[0][ind] = L_shr( result_int, 1 ); /* Q11 */ move32(); } 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 ); + Word32 result_int = L_add_sat( hCPE->input_mem_fx[0][ind], hCPE->input_mem_fx[1][ind] ); /* Q11 */ + hCPE->input_mem_fx[0][ind] = L_shr( result_int, 1 ); /* Q11 */ move32(); } @@ -3138,8 +3138,8 @@ void stereo_switching_dec( { 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 ); + Word32 result_int = L_add_sat( hCPE->output_mem_fx[0][ind], hCPE->output_mem_fx[1][ind] ); /* q_output_mem_fx */ + hCPE->output_mem_fx[0][ind] = Mpy_32_32( result_int, INV_SQRT_2_Q31 ); /* q_output_mem_fx */ move32(); } } @@ -3152,7 +3152,7 @@ void stereo_switching_dec( move32(); if ( hCPE->hStereoTCA != NULL ) { - tmpF_fx = side_gain_table[hCPE->hStereoTCA->indx_ica_gD]; + tmpF_fx = side_gain_table[hCPE->hStereoTCA->indx_ica_gD]; /* Q31 */ move32(); } set32_fx( hCPE->hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX, tmpF_fx, STEREO_DFT_BAND_MAX ); @@ -3170,7 +3170,7 @@ void stereo_switching_dec( 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; + hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Q0 */ move16(); hCPE->hStereoTD->tdm_last_SM_flag = 0; move16(); @@ -3180,7 +3180,7 @@ void stereo_switching_dec( /* First frame after DFT frame AND the content is uncorrelated or xtalk -> the primary channel is forced to left */ if ( EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) ) { - hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + hCPE->hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; /* Q0 */ move16(); } } @@ -3214,7 +3214,7 @@ void stereo_switching_dec( set16_fx( sts[0]->mem_syn3_fx, 0, M ); set16_fx( sts[0]->mem_syn_r, 0, L_SYN_MEM ); - sts[1]->last_L_frame = sts[0]->last_L_frame; + sts[1]->last_L_frame = sts[0]->last_L_frame; /* Q0 */ move16(); @@ -3225,13 +3225,13 @@ void stereo_switching_dec( sts[1]->last_extl = -1; move16(); - sts[1]->prev_bfi = sts[0]->prev_bfi; + sts[1]->prev_bfi = sts[0]->prev_bfi; /* Q0 */ move16(); // 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 = L_deposit_h( 2 * L_SUBFR ); + sts[1]->old_fpitchFB = L_deposit_h( 2 * L_SUBFR ); /* 15Q16 */ move32(); /* reset CLDFB memories */ @@ -3254,13 +3254,13 @@ void stereo_switching_dec( set16_fx( sts[1]->mem_syn3_fx, 0, M ); set16_fx( sts[1]->mem_syn_r, 0, L_SYN_MEM ); - sts[1]->last_L_frame = sts[0]->last_L_frame; + sts[1]->last_L_frame = sts[0]->last_L_frame; /* Q0 */ move16(); #ifndef FIX_918_WRONG_SCALING_ON_MODE_SWITCHING 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 ) ); #else /* Should not force sts[1]->Q_exc on the data of st[0], instead it better to just reuse the current scaling of st[0]*/ - Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); + Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); /* Q_exc */ sts[1]->Q_exc = sts[0]->Q_exc; move16(); sts[1]->Q_exc_cng = sts[0]->Q_exc_cng; @@ -3292,27 +3292,27 @@ void stereo_switching_dec( move16(); #endif - Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); - Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); + Copy( sts[0]->lsf_old_fx, sts[1]->lsf_old_fx, M ); /* Q2.56 */ + Copy( sts[0]->lsp_old_fx, sts[1]->lsp_old_fx, M ); /* Q15 */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { - sts[1]->last_core = sts[0]->last_core; + sts[1]->last_core = sts[0]->last_core; /* Q0 */ move16(); - sts[1]->last_coder_type = sts[0]->last_coder_type; + sts[1]->last_coder_type = sts[0]->last_coder_type; /* Q0 */ move16(); // 32bit buffer - Copy32( sts[0]->hHQ_core->oldOut_fx, sts[1]->hHQ_core->oldOut_fx, L_FRAME48k ); - Copy32( sts[0]->delay_buf_out32_fx, sts[1]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); - Copy32( sts[0]->hTcxDec->old_syn_Overl_32, sts[1]->hTcxDec->old_syn_Overl_32, 256 ); + Copy32( sts[0]->hHQ_core->oldOut_fx, sts[1]->hHQ_core->oldOut_fx, L_FRAME48k ); /* exp(exp_old_out) */ + Copy32( sts[0]->delay_buf_out32_fx, sts[1]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* Q11 */ + Copy32( sts[0]->hTcxDec->old_syn_Overl_32, sts[1]->hTcxDec->old_syn_Overl_32, 256 ); /* Q_old_syn_Overl*/ // 16 bit buffer - Copy( sts[0]->hHQ_core->old_out_fx, sts[1]->hHQ_core->old_out_fx, L_FRAME48k ); + Copy( sts[0]->hHQ_core->old_out_fx, sts[1]->hHQ_core->old_out_fx, L_FRAME48k ); /* exp(exp_old_out) */ sts[1]->hHQ_core->Q_old_wtda = sts[0]->hHQ_core->Q_old_wtda; move16(); - Copy( sts[0]->delay_buf_out_fx, sts[1]->delay_buf_out_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); - Copy( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); + Copy( sts[0]->delay_buf_out_fx, sts[1]->delay_buf_out_fx, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* Q0 */ + Copy( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); /* Q_old_syn_Overl*/ } } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) @@ -3324,23 +3324,23 @@ void stereo_switching_dec( /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ 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; + sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; /* Q0 */ move16(); - sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; + sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); - sts[1]->fscale = sts[0]->fscale; + sts[1]->fscale = sts[0]->fscale; /* Q0 */ move16(); - sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; + sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; /* Q0 */ move16(); - sts[1]->pit_res_max = sts[0]->pit_res_max; + sts[1]->pit_res_max = sts[0]->pit_res_max; /* Q0 */ move16(); - sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; + sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; /* Q0 */ move16(); - sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; + sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; /* Q0 */ move16(); - sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; + sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; /* Q14 */ move16(); - sts[1]->hTcxDec->conceal_eof_gain32 = sts[0]->hTcxDec->conceal_eof_gain32; + sts[1]->hTcxDec->conceal_eof_gain32 = sts[0]->hTcxDec->conceal_eof_gain32; /* sts[0]->hTcxDec->conceal_eof_gain_e */ move32(); sts[1]->hTcxDec->conceal_eof_gain_e = sts[0]->hTcxDec->conceal_eof_gain_e; move16(); @@ -3685,12 +3685,12 @@ void stereo_td2dft_update( } #else void stereo_td2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number */ - Word32 output_fx[], /* i/o: synthesis @internal Fs */ - Word32 synth_fx[], /* i/o: synthesis @output Fs */ - Word32 hb_synth_fx[], /* i/o: hb synthesis */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number Q0*/ + Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ + const Word16 output_frame /* i : frame length Q0*/ ) { Word16 ovl, ovl_TCX, dft32ms_ovl, hq_delay_comp; @@ -3705,11 +3705,11 @@ void stereo_td2dft_update_fx( /* initialization */ sts = hCPE->hCoreCoder; - ovl = NS2SA_FX2( i_mult( sts[n]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + ovl = NS2SA_FX2( i_mult( sts[n]->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); /* Q0 */ move16(); - dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) + dft32ms_ovl = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_DFT32MS_OVL_MAX ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ move16(); - hq_delay_comp = NS2SA_FX2( sts[0]->output_Fs, DELAY_CLDFB_NS ); + hq_delay_comp = NS2SA_FX2( sts[0]->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ move16(); test(); @@ -3721,12 +3721,12 @@ void stereo_td2dft_update_fx( IF( n == 0 ) { /* update DFT analysis overlap memory @internal_fs: core synthesis */ - Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); /* Q11 */ /* update DFT analysis overlap memory @internal_fs: BPF */ IF( sts[n]->p_bpf_noise_buf_32 ) { - Copy32( sts[n]->p_bpf_noise_buf_32 + sub( 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 ); /* Q11 */ } @@ -3735,33 +3735,33 @@ void stereo_td2dft_update_fx( test(); IF( NE_16( sts[n]->extl, -1 ) || ( sts[n]->bws_cnt > 0 && sts[n]->core == ACELP_CORE ) ) { - Copy32( hb_synth_fx + sub( 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 ); /* Q11 */ } } ELSE { /* update DFT analysis overlap memory @internal_fs: core synthesis, secondary channel */ - Copy32( output_fx + sub( 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 ); /* Q11 */ } } ELSE /* TCX core */ { /* LB-TCX synthesis */ - Copy32( output_fx + sub( 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 ); /* Q11 */ /* BPF */ IF( n == 0 && sts[n]->p_bpf_noise_buf_32 ) { - Copy32( sts[n]->p_bpf_noise_buf_32 + sub( 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 ); /* Q11 */ } /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ IF( sts[n]->hTcxDec != NULL ) { - ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); /* Q0 */ 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 ); + Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], sub( ovl_TCX, hq_delay_comp ) ); /* Q11 */ + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); /* Q11 */ } } } @@ -3776,21 +3776,21 @@ void stereo_td2dft_update_fx( /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ IF( sts[n]->hTcxDec != NULL ) { - ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + ovl_TCX = NS2SA_FX2( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); /* Q0 */ 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 ); + 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 ) ); /* Q11 */ + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + sub( ovl_TCX, hq_delay_comp ), hq_delay_comp ); /* Q11 */ } IF( EQ_16( n, 1 ) ) { - nsLB = NS2SA_FX2( L_mult0( sts[n]->L_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); + nsLB = NS2SA_FX2( L_mult0( sts[n]->L_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); /* Q0 */ move16(); - ns = NS2SA_FX2( sts[n]->output_Fs, N_ZERO_MDCT_NS ); + ns = NS2SA_FX2( sts[n]->output_Fs, N_ZERO_MDCT_NS ); /* Q0 */ 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 ) ); + 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 ) ); /* Q0 */ move16(); - old_out_len = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); + old_out_len = extract_l( Mpy_32_32( imult3216( sts[0]->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); /* Q0 */ move16(); /* update buffers used for fading when switching to DFT Stereo */ @@ -3802,17 +3802,17 @@ void stereo_td2dft_update_fx( 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 ); + hCPE->old_outLB_mdct_fx[i] = L_shr( hCPE->old_outLB_mdct_fx[i], 1 ); /* Q11 */ 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 ); + 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 ); /* exp(exp_old_out) */ #ifndef MSAN_FIX for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) #else 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 ); + hCPE->old_out_mdct_fx[i] = L_shr( hCPE->old_out_mdct_fx[i], 1 ); /* q_old_out_mdct */ move32(); } } @@ -3828,7 +3828,7 @@ void stereo_td2dft_update_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && sts[n]->hTcxDec == NULL ) { - Copy32( output_fx + shr( sts[n]->L_frame, 1 ), hCPE->hStereoTD->TCX_old_syn_Overl_fx, shr( sts[n]->L_frame, 1 ) ); + Copy32( output_fx + shr( sts[n]->L_frame, 1 ), hCPE->hStereoTD->TCX_old_syn_Overl_fx, shr( sts[n]->L_frame, 1 ) ); /* Q11*/ } return; @@ -3878,8 +3878,8 @@ void stereo_mdct2dft_update( #else void stereo_mdct2dft_update_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ - Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ ) { Word16 i; @@ -3894,20 +3894,20 @@ void stereo_mdct2dft_update_fx( st = hCPE->hCoreCoder[0]; - 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) + fade_len = extract_l( Mpy_32_32( imult3216( st->output_Fs, STEREO_MDCT2DFT_FADE_LEN_48k ), 44740 ) ); // 1/48000 = 44740 (Q31) /* Q0 */ + 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) /* Q0 */ SWITCH( st->output_Fs ) { case 16000: - tmpF_fx = 53687092; + tmpF_fx = 53687092; /* Q31 */ move32(); BREAK; case 32000: - tmpF_fx = 26843546; + tmpF_fx = 26843546; /* Q31 */ move32(); BREAK; case 48000: - tmpF_fx = 17895698; + tmpF_fx = 17895698; /* Q31 */ move32(); BREAK; } @@ -3916,49 +3916,49 @@ void stereo_mdct2dft_update_fx( Word32 descen_gain; IF( EQ_16( i, 0 ) ) { - descen_gain = ONE_IN_Q31; + descen_gain = ONE_IN_Q31; /* Q31 */ move32(); } ELSE { - descen_gain = W_extract_l( W_mult0_32_32( ( sub( fade_len, i ) ), tmpF_fx ) ); + descen_gain = W_extract_l( W_mult0_32_32( ( sub( fade_len, i ) ), tmpF_fx ) ); /* Q31 */ } - Word32 temp_a = Mpy_32_32( hCPE->old_out_mdct_fx[i], descen_gain ); - 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 ); + Word32 temp_a = Mpy_32_32( hCPE->old_out_mdct_fx[i], descen_gain ); /* Q11 */ + Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); /* Q31 */ + Word32 temp_b = Mpy_32_32( synth0_fx[i], ascend_gain ); /* Q11 */ + synth0_fx[i] = L_add_sat( temp_a, temp_b ); /* Q11 */ move32(); } SWITCH( st->L_frame ) { case 80: - tmpF_fx = 71582792; + tmpF_fx = 71582792; /* Q31 */ move32(); BREAK; case 160: - tmpF_fx = 35791396; + tmpF_fx = 35791396; /* Q31 */ move32(); BREAK; case 256: - tmpF_fx = 22369622; + tmpF_fx = 22369622; /* Q31 */ move32(); BREAK; case 320: - tmpF_fx = 17895698; + tmpF_fx = 17895698; /* Q31 */ move32(); BREAK; case 512: - tmpF_fx = 11184811; + tmpF_fx = 11184811; /* Q31 */ move32(); BREAK; case 640: - tmpF_fx = 8947849; + tmpF_fx = 8947849; /* Q31 */ move32(); BREAK; case 960: - tmpF_fx = 5965232; + tmpF_fx = 5965232; /* Q31 */ move32(); BREAK; default: @@ -3969,17 +3969,17 @@ void stereo_mdct2dft_update_fx( Word32 descen_gain; IF( i == 0 ) { - descen_gain = ONE_IN_Q31; + descen_gain = ONE_IN_Q31; /* Q31 */ move32(); } ELSE { - descen_gain = W_extract_l( W_mult0_32_32( sub( fade_len_LB, i ), tmpF_fx ) ); + descen_gain = W_extract_l( W_mult0_32_32( sub( fade_len_LB, i ), tmpF_fx ) ); /* Q31 */ } - Word32 temp_a = Mpy_32_32( hCPE->old_outLB_mdct_fx[i], descen_gain ); - 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 ); + Word32 temp_a = Mpy_32_32( hCPE->old_outLB_mdct_fx[i], descen_gain ); /* Q11 */ + Word32 ascend_gain = W_extract_l( W_mult0_32_32( i, tmpF_fx ) ); /* Q31 */ + Word32 temp_b = Mpy_32_32( output0_fx[i], ascend_gain ); /* Q11 */ + output0_fx[i] = L_add_sat( temp_a, temp_b ); /* Q11 */ } return; @@ -4025,11 +4025,12 @@ static float ncross_corr_self( } #else static Word32 ncross_corr_self_fx( - Word32 *signal_fx, - const Word16 x, - const Word16 y, - const Word16 corr_len, - const Word16 subsampling ) + Word32 *signal_fx, /* Q11*/ + const Word16 x, /* Q0 */ + const Word16 y, /* Q0 */ + const Word16 corr_len, /* Q0 */ + const Word16 subsampling /* Q0 */ +) { Word64 c_c_fx; Word32 c_c_fx_return; @@ -4048,20 +4049,20 @@ static Word32 ncross_corr_self_fx( move64(); energy_y_fx = 0; move64(); - signal_a_fx = &signal_fx[x]; - signal_b_fx = &signal_fx[y]; + signal_a_fx = &signal_fx[x]; /* Q11 */ + signal_b_fx = &signal_fx[y]; /* Q11 */ FOR( j = 0; j < corr_len; j += subsampling ) { - 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] ) ) ); + c_c_fx = W_add( c_c_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_b_fx[j] ) ) ); /* 2 * Q11 */ + energy_x_fx = W_add( energy_x_fx, W_mult0_32_32( ( signal_a_fx[j] ), ( signal_a_fx[j] ) ) ); /* 2 * Q11 */ + energy_y_fx = W_add( energy_y_fx, W_mult0_32_32( ( signal_b_fx[j] ), ( signal_b_fx[j] ) ) ); /* 2 * Q11 */ } headroom_left_x = W_norm( energy_x_fx ); headroom_left_y = W_norm( energy_y_fx ); IF( LT_16( headroom_left_x, 32 ) ) { - energy_x_fx = W_shr( energy_x_fx, sub( 32, headroom_left_x ) ); + energy_x_fx = W_shr( energy_x_fx, sub( 32, headroom_left_x ) ); /* 2 * Q11 - (32 -headroom_left_x) */ x_q = sub( 31, ( sub( ( 2 * OUTPUT_Q ), sub( 32, headroom_left_x ) ) ) ); } ELSE @@ -4070,7 +4071,7 @@ static Word32 ncross_corr_self_fx( } IF( LT_16( headroom_left_y, 32 ) ) { - energy_y_fx = W_shr( energy_y_fx, sub( 32, headroom_left_y ) ); + energy_y_fx = W_shr( energy_y_fx, sub( 32, headroom_left_y ) ); /* 2 * Q11 - (32 -headroom_left_y) */ y_q = sub( 31, ( sub( ( 2 * OUTPUT_Q ), ( sub( 32, headroom_left_y ) ) ) ) ); } ELSE @@ -4086,7 +4087,7 @@ static Word32 ncross_corr_self_fx( temp_x = Sqrt32( W_extract_l( energy_x_fx ), &x_q ); IF( x_q < 0 ) { - temp_x = L_shr( temp_x, i_mult( -1, x_q ) ); + temp_x = L_shr( temp_x, i_mult( -1, x_q ) ); /* Q0 */ x_q = 0; move16(); } @@ -4094,41 +4095,41 @@ static Word32 ncross_corr_self_fx( temp_y = Sqrt32( W_extract_l( energy_y_fx ), &y_q ); IF( y_q < 0 ) { - temp_y = L_shr( temp_y, i_mult( -1, y_q ) ); + temp_y = L_shr( temp_y, i_mult( -1, y_q ) ); /* Q0 */ y_q = 0; move16(); } - energy_xy_fx = Mpy_32_32( temp_x, temp_y ); + energy_xy_fx = Mpy_32_32( temp_x, temp_y ); /* x_q + y_q - 31 */ res_q = add( y_q, x_q ); 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; - c_c_fx = W_shl( c_c_fx, 31 - ( 2 * OUTPUT_Q ) ); + c_c_fx = W_shl( c_c_fx, 31 - ( 2 * OUTPUT_Q ) ); /* Q31 */ } ELSE { 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 = Mpy_32_32( temp_x_inv, temp_y_inv ); + energy_xy_fx = Mpy_32_32( temp_x_inv, temp_y_inv ); /* exp(x_inv_q + y_inv_q) */ 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; move16(); IF( LT_16( headroom_left_c_c, 32 ) ) { - c_c_fx = W_shr( c_c_fx, extract_l( sub( 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 - (32 - headroom_left_c_c) */ c_c_fx_q = sub( c_c_fx_q, sub( 32, headroom_left_c_c ) ); } - c_c_fx = W_deposit32_l( Mpy_32_32( W_extract_l( c_c_fx ), W_extract_l( energy_xy_fx ) ) ); + 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 + (31 - res_q) - 31 */ 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 = W_extract_l( W_shl_sat_l( c_c_fx, extract_l( sub( 31, c_c_fx_q ) ) ) ); /* Q31 */ } - c_c_fx_return = W_extract_l( c_c_fx ); + c_c_fx_return = W_extract_l( c_c_fx ); /* Q31 */ move32(); return c_c_fx_return; } @@ -4290,9 +4291,9 @@ void smooth_dft2td_transition( } #else void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs */ - const Word16 output_frame /* i : output frame lenght */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ + const Word16 output_frame /* i : output frame lenght Q0*/ ) { @@ -4318,106 +4319,106 @@ void smooth_dft2td_transition_fx( IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && ( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) && ( EQ_16( sts[0]->clas_dec, VOICED_CLAS ) && LT_16( sts[0]->coder_type, TRANSITION ) && GT_16( sts[0]->coder_type, UNVOICED ) && GT_16( sts[0]->last_coder_type, UNVOICED ) && GT_16( sts[1]->coder_type, UNVOICED ) ) ) ) { /* length of OVA */ - ilen = shr( output_frame, 1 ); + ilen = shr( output_frame, 1 ); /* Q0 */ /* correlation length */ - corr_len = idiv1616( output_frame, 20 ); + corr_len = idiv1616( output_frame, 20 ); /* Q0 */ subsampl = 4; FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) { /* 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 = imult3216( check, shl( 1, add( 26 - 15, q ) ) ); + Word32 check = BASOP_Util_Divide3232_Scale( output_frame, sts[ch]->L_frame, &q ); /* q */ + fac_fs_fx = imult3216( check, shl( 1, add( 26 - 15, q ) ) ); /* Q11 */ /* Find minimum and maximum pitch*/ - 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 ); + ipit_min = add( minimum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); /* Q0 */ + ipit_max = add( maximum_32_fx( sts[ch]->old_pitch_buf_fx + 4, 4, &flen_fx ), 4 ); /* Q0 */ + 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 ); /* Q0 */ + 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 ); /* Q0 */ IF( GT_16( add( ipit_max, corr_len ), ilen ) ) /*ensure the search is performed on the available memory*/ { CONTINUE; } - lsearch = add( sub( ipit_max, ipit_min ), corr_len ); - lsearch = s_min( lsearch, shr( output_frame, 2 ) ); + lsearch = add( sub( ipit_max, ipit_min ), corr_len ); /* Q0 */ + lsearch = s_min( lsearch, shr( output_frame, 2 ) ); /* Q0 */ /* ptr init for search of the best correlation in the past frame */ - ptE_fx = hCPE->prev_synth_chs_fx[ch] + sub( output_frame, add( ipit_max, corr_len ) ); + ptE_fx = hCPE->prev_synth_chs_fx[ch] + sub( output_frame, add( ipit_max, corr_len ) ); /* Q11 */ idiff = 0; move16(); - fmaxcorr_fx = -ONE_IN_Q31; + fmaxcorr_fx = -ONE_IN_Q31; /* Q31 */ move32(); FOR( i = 0; i < lsearch; i++ ) { - ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); + ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); /* Q31 */ IF( GT_32( ftmp_corr_fx, fmaxcorr_fx ) ) { - idiff = i; + idiff = i; /* Q0 */ move16(); } - fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); + fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); /* Q11 */ } - ipit = sub( ipit_max, idiff ); + ipit = sub( ipit_max, idiff ); /* Q0 */ - ptO_fx = tmp_out_fx + output_frame; + ptO_fx = tmp_out_fx + output_frame; /* Q11 */ /* If the correlation is too low, don't use the prediction */ IF( LT_32( fmaxcorr_fx, DFT2TD_CORR_THRESH_FX ) ) { - Copy32( &output_fx[ch][0], ptO_fx, ilen ); + Copy32( &output_fx[ch][0], ptO_fx, ilen ); /* Q11 */ } ELSE { - Copy32( hCPE->prev_synth_chs_fx[ch], tmp_out_fx, output_frame ); - pt1_fx = tmp_out_fx + output_frame - ipit; + Copy32( hCPE->prev_synth_chs_fx[ch], tmp_out_fx, output_frame ); /* Q11 */ + pt1_fx = tmp_out_fx + output_frame - ipit; /* Q11 */ FOR( i = 0; i < ilen; i++ ) { - ptO_fx[i] = pt1_fx[i]; + ptO_fx[i] = pt1_fx[i]; /* Q11 */ move32(); } } /* Set buffer for the reserved buffer of the current frame */ - ptO2_fx = tmp_out2_fx + sub( output_frame, ilen ); + ptO2_fx = tmp_out2_fx + sub( output_frame, ilen ); /* Q11 */ 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][sub( output_frame, ( 1 + i ) )]; + tmp_out2_fx[i] = output_fx[ch][output_frame - 1 - i]; /* Q11 */ move32(); } /* ptr init for search of the best correlation of the current frame */ - ptE_fx = ptO2_fx - ( ipit_max + corr_len ); + ptE_fx = ptO2_fx - ( ipit_max + corr_len ); /* Q11 */ idiff = 0; move16(); - fmaxcorr_fx = -ONE_IN_Q31; + fmaxcorr_fx = -ONE_IN_Q31; /* Q31 */ move32(); FOR( i = 0; i < lsearch; i++ ) { - ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); + ftmp_corr_fx = ncross_corr_self_fx( ptE_fx, i, ipit_max, corr_len, subsampl ); /* Q31 */ IF( GT_32( ftmp_corr_fx, fmaxcorr_fx ) ) { - idiff = i; + idiff = i; /* Q0 */ move16(); } - fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); + fmaxcorr_fx = L_max( fmaxcorr_fx, ftmp_corr_fx ); /* Q31 */ } - ipit = sub( ipit_max, idiff ); + ipit = sub( ipit_max, idiff ); /* Q0 */ /* 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 + sub( output_frame, add( ilen, ipit ) ); + pt1_fx = tmp_out2_fx + sub( output_frame, add( ilen, ipit ) ); /* Q11 */ FOR( i = 0; i < ilen; i++ ) { - ptO2_fx[i] = pt1_fx[i]; + ptO2_fx[i] = pt1_fx[i]; /* Q11 */ move32(); } } @@ -4426,15 +4427,15 @@ void smooth_dft2td_transition_fx( SWITCH( ilen ) { case 160: - flen_fx = 13421772; + flen_fx = 13421772; /* Q31 */ move32(); BREAK; case 320: - flen_fx = 6710886; + flen_fx = 6710886; /* Q31 */ move32(); BREAK; case 480: - flen_fx = 4473924; + flen_fx = 4473924; /* Q31 */ move32(); BREAK; default: @@ -4443,26 +4444,26 @@ void smooth_dft2td_transition_fx( } FOR( i = 0; i < 4; i++ ) { - 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 ); + 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 ); /* Q11 */ 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 ) ); + Word64 temp_b = W_mult0_32_32( tmp_out2_fx[output_frame - 1 - i], i ); /* Q11 */ + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); /* Q11 */ move32(); } - FOR( ; i < sub( ilen, 4 ); i++ ) + FOR( ; i < ilen - 4; i++ ) { - 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 ) ); + Word64 temp_a = W_mult0_32_32( ptO_fx[i], sub( ilen, i ) ); /* Q11 */ + Word64 temp_b = W_mult0_32_32( tmp_out2_fx[output_frame - 1 - i], i ); /* Q11 */ + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); /* Q11 */ move32(); } j = 0; move16(); FOR( ; i < ilen; i++ ) { - Word64 temp_a = (Word64) ptO_fx[i] * ( ilen - i ); - 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 ) ); + Word64 temp_a = W_mult0_32_32( ptO_fx[i], sub( ilen, i ) ); /* Q11 */ + Word64 temp_b = W_shr( ( W_add( W_mult0_32_32( sub( 4, j ), tmp_out2_fx[output_frame - 1 - i] ), W_mult0_32_32( j, output_fx[ch][i] ) ) * i ), 2 ); /* Q11 */ + output_fx[ch][i] = W_extract_l( W_shr( ( W_add( temp_a, temp_b ) * flen_fx ), 31 ) ); /* Q11 */ move32(); j = add( j, 1 ); } @@ -4473,7 +4474,7 @@ void smooth_dft2td_transition_fx( /* Updates */ FOR( ch = 0; ch < hCPE->nchan_out; ch++ ) { - Copy32( output_fx[ch], hCPE->prev_synth_chs_fx[ch], output_frame ); + Copy32( output_fx[ch], hCPE->prev_synth_chs_fx[ch], output_frame ); /* Q11 */ } } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 55b793bda..966f0d650 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -83,28 +83,28 @@ void stereo_td_init_dec( #ifdef IVAS_FLOAT_FIXED void stereo_td_init_dec_fx( - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const int16_t last_element_mode /* i : last element mode */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode /* i : last element mode Q0*/ ) { hStereoTD->tdm_SM_flag = 0; move16(); hStereoTD->tdm_last_SM_flag = 0; move16(); - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Q0 */ 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 + hStereoTD->prevSP_ratio_fx = ONE_IN_Q14; //.5 /* Q15 */ 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 + hStereoTD->c_LR_LT_fx = ONE_IN_Q30; //.5 /* Q31 */ move32(); hStereoTD->flag_skip_DMX = 0; @@ -112,9 +112,9 @@ void stereo_td_init_dec_fx( IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { - hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; /* Q0 */ move16(); - hStereoTD->tdm_LRTD_flag = 1; + hStereoTD->tdm_LRTD_flag = 1; /* Q0 */ move16(); } @@ -138,11 +138,11 @@ Word32 power_table[32 + 1] = { 2137321728 }; // Q29 void tdm_configure_dec_fx( - const Word16 ivas_format, /* i : IVAS format */ - const Word16 ism_mode, /* i : ISM mode in combined format */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word16 *tdm_ratio_idx, /* o : ratio index */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ + const Word16 ivas_format, /* i : IVAS format Q0*/ + const Word16 ism_mode, /* i : ISM mode in combined format Q0*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 *tdm_ratio_idx, /* o : ratio index Q0*/ + const Word16 nb_bits_metadata /* i : number of metadata bits Q0*/ ) { STEREO_TD_DEC_DATA_HANDLE hStereoTD; @@ -156,72 +156,72 @@ void tdm_configure_dec_fx( hStereoTD = hCPE->hStereoTD; sts = hCPE->hCoreCoder; - element_brate_adapt = L_add( hCPE->element_brate, hCPE->brate_surplus ); + element_brate_adapt = L_add( hCPE->element_brate, hCPE->brate_surplus ); /* Q0 */ IF( hCPE->brate_surplus < 0 ) { - temp = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + temp = extract_l( L_negate( Mpy_32_32( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); /* Q0 */ } ELSE { - temp = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + temp = extract_l( Mpy_32_32( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ } - bstr_last_pos = add( sub( div_l( hCPE->element_brate, FRAMES_PER_SEC / 2 ), nb_bits_metadata ), temp ); + bstr_last_pos = add( sub( div_l( hCPE->element_brate, FRAMES_PER_SEC / 2 ), nb_bits_metadata ), temp ); /* Q0 */ /*----------------------------------------------------------------* * Decode CoreCoder signaling *----------------------------------------------------------------*/ /* temporarily decode PCh signaling */ - bits_offset = sts[0]->next_bit_pos; + bits_offset = sts[0]->next_bit_pos; /* Q0 */ move16(); - core = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 1 ); - bits_offset = add( bits_offset, 1 ); + core = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 1 ); /* Q0 */ + bits_offset = add( bits_offset, 1 ); /* Q0 */ IF( core == ACELP_CORE && LT_32( hCPE->element_brate, IVAS_24k4 ) ) { - mod_ct = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 3 ); + mod_ct = get_indice_st( sts[0], hCPE->element_brate, bits_offset, 3 ); /* Q0 */ /* Only transition mode is important to decoder, otherwise mod_ct is set to AUDIO only to easy debugging IF needed */ if ( NE_16( mod_ct, TRANSITION ) ) { - mod_ct = AUDIO; + mod_ct = AUDIO; /* Q0 */ move16(); } } ELSE /* core != ACELP_CORE */ { - mod_ct = AUDIO; /* coder_type == VOICED || coder_type == GENERIC */ + mod_ct = AUDIO; /* coder_type == VOICED || coder_type == GENERIC */ /* Q0 */ 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, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); + sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, sub( bstr_last_pos, TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); /* Q0 */ 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 = s_and( sts[1]->coder_type, 0x1 ); - sts[1]->coder_type = shr( sts[1]->coder_type, 1 ); + tdm_tmp_SM_LRTD_flag = s_and( sts[1]->coder_type, 0x1 ); /* Q0 */ + sts[1]->coder_type = shr( sts[1]->coder_type, 1 ); /* Q0 */ move16(); hStereoTD->tdm_Pitch_reuse_flag = 0; move16(); IF( EQ_16( sts[1]->coder_type, 2 ) ) { - sts[1]->coder_type = GENERIC; + sts[1]->coder_type = GENERIC; /* Q0 */ move16(); } ELSE IF( EQ_16( sts[1]->coder_type, 3 ) ) { - sts[1]->coder_type = AUDIO; + sts[1]->coder_type = AUDIO; /* Q0 */ move16(); IF( LE_32( hCPE->element_brate, IVAS_24k4 ) ) { - hStereoTD->tdm_Pitch_reuse_flag = 1; + hStereoTD->tdm_Pitch_reuse_flag = 1; /* Q0 */ move16(); - sts[1]->coder_type = GENERIC; + sts[1]->coder_type = GENERIC; /* Q0 */ move16(); } } @@ -231,7 +231,7 @@ void tdm_configure_dec_fx( *----------------------------------------------------------------*/ /* Get the correlation ratio */ - *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, ( sub( 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 ); /* Q0 */ move16(); hStereoTD->tdm_use_IAWB_Ave_lpc = 0; @@ -239,43 +239,43 @@ void tdm_configure_dec_fx( 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, sub( 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 ); /* Q0 */ move16(); - hStereoTD->tdm_lp_reuse_flag = 1; + hStereoTD->tdm_lp_reuse_flag = 1; /* Q0 */ move16(); } ELSE { /* Get the flag on the LPC reusage */ - 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 ); + 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 ); /* Q0 */ move16(); } - sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() */ + sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() Q0*/ move16(); - sts[1]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; + sts[1]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* Q0 */ move16(); - tdm_inst_ratio_idx = *tdm_ratio_idx; + tdm_inst_ratio_idx = *tdm_ratio_idx; /* Q0 */ move16(); /* update past tdm_SM_flag */ - hStereoTD->tdm_prev_last_SM_flag = hStereoTD->tdm_last_SM_flag; + hStereoTD->tdm_prev_last_SM_flag = hStereoTD->tdm_last_SM_flag; /* Q0 */ move16(); - hStereoTD->tdm_last_SM_flag = hStereoTD->tdm_SM_flag; + hStereoTD->tdm_last_SM_flag = hStereoTD->tdm_SM_flag; /* Q0 */ move16(); - idx_LRTD_pri_side = -1; + idx_LRTD_pri_side = -1; /* Q0 */ move16(); IF( EQ_16( hStereoTD->tdm_LRTD_flag, 1 ) ) { - idx_LRTD_pri_side = tdm_tmp_SM_LRTD_flag; + idx_LRTD_pri_side = tdm_tmp_SM_LRTD_flag; /* Q0 */ move16(); hStereoTD->tdm_SM_flag = 0; move16(); IF( tdm_inst_ratio_idx == TDM_NQ ) { - hStereoTD->flag_skip_DMX = 1; + hStereoTD->flag_skip_DMX = 1; /* Q0 */ move16(); } ELSE @@ -284,17 +284,17 @@ void tdm_configure_dec_fx( move16(); } /* Set primary channel */ - *tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; + *tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; /* Q0 */ move16(); if ( EQ_16( idx_LRTD_pri_side, 1 ) ) { - *tdm_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + *tdm_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; /* Q0 */ move16(); } } ELSE { - hStereoTD->tdm_SM_flag = tdm_tmp_SM_LRTD_flag; + hStereoTD->tdm_SM_flag = tdm_tmp_SM_LRTD_flag; /* Q0 */ move16(); if ( EQ_16( hCPE->nchan_out, 1 ) ) { @@ -308,7 +308,7 @@ void tdm_configure_dec_fx( 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; + hStereoTD->tdm_lp_reuse_flag = hStereoTD->tdm_use_IAWB_Ave_lpc; /* Q0 */ move16(); hStereoTD->tdm_use_IAWB_Ave_lpc = 0; move16(); @@ -326,43 +326,43 @@ void tdm_configure_dec_fx( { 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]; + hCPE->hStereoDftDmx->targetGain_fx = power_table[tmpS]; /* Q29 */ move32(); } ELSE { IF( hStereoTD->tdm_LRTD_flag == 0 ) { - 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 ); + 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 ); /* Q0 */ 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 ); + 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 ); /* Q0 */ 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 ); + 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 ); /* Q0 */ move16(); } ELSE { - hCPE->hStereoTCA->refChanIndx = L_CH_INDX; + hCPE->hStereoTCA->refChanIndx = L_CH_INDX; /* Q0 */ move16(); - hCPE->hStereoTCA->indx_ica_NCShift = 0; + hCPE->hStereoTCA->indx_ica_NCShift = 0; /* Q0 */ move16(); - hCPE->hStereoTCA->indx_ica_gD = 20; + hCPE->hStereoTCA->indx_ica_gD = 20; /* Q0 */ move16(); } - hCPE->hStereoTCA->targetGain_fx = power_table[hCPE->hStereoTCA->indx_ica_gD]; + hCPE->hStereoTCA->targetGain_fx = power_table[hCPE->hStereoTCA->indx_ica_gD]; /* Q29 */ move32(); } /* set the BW of the secondary channel */ 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; + sts[1]->bwidth = sts[0]->bwidth; /* Q0 */ move16(); } ELSE { /* limit BW of the secondary channel in LRTD mode to WB for low bitrates */ - sts[1]->bwidth = WB; + sts[1]->bwidth = WB; /* Q0 */ move16(); } @@ -608,15 +608,15 @@ void tdm_upmix_plain( return; } void tdm_upmix_plain_fx( - Word32 Left_fx[], /* o : left channel */ - Word32 Right_fx[], /* o : right channel */ - const Word32 PCh_2_L_fx[], /* i : primary channel */ - const Word32 SCh_2_R_fx[], /* i : secondary channel */ - const Word32 LR_ratio_fx, /* i : mixing ratio */ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const Word16 start_index, /* i : start index */ - const Word16 end_index, /* i : end index */ - const Word16 plus_minus_flag /* i : plus/minus flag */ + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ ) { Word16 i; @@ -625,11 +625,11 @@ void tdm_upmix_plain_fx( { 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 ); + 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] ); /* Qx */ + Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); /* Qx + 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 ); + 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] ); /* Qx */ + Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */ move32(); } } @@ -637,11 +637,11 @@ void tdm_upmix_plain_fx( { FOR( i = start_index; i < end_index; i++ ) { - 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 ); + 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] ); /* Qx */ + Left_fx[i] = L_shl_sat( Mpy_32_32( temp_left, inv_den_LR_ratio_fx ), 1 ); /* Qx + 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 ); + 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] ); /* Qx */ + Right_fx[i] = L_shl_sat( Mpy_32_32( temp_right, inv_den_LR_ratio_fx ), 1 ); /* Qx + 1 */ move32(); } } @@ -727,7 +727,7 @@ static void tdm_upmix_fade( } #endif - +// Q31 Word32 inv_time[960 + 1] = { 0, 2147483647, 1073741824, 715827904, 536870912, 429496736, 357913952, 306783392, 268435456, 238609296, 214748368, 195225792, 178956976, 165191056, 153391696, 143165584, @@ -853,102 +853,102 @@ Word32 inv_time[960 + 1] = { }; #ifdef IVAS_FLOAT_FIXED static void tdm_upmix_fade_fx( - Word32 Left_fx[], /* o : left channel */ - Word32 Right_fx[], /* o : right channel */ - const Word32 PCh_2_L_fx[], /* i : primary channel */ - const Word32 SCh_2_R_fx[], /* i : secondary channel */ - const Word32 LR_ratio_mem_fx, /* i : last mixing ratio */ - const Word32 inv_den_LR_ratio_mem_fx, /* i : last inverse mixing ration */ - const Word32 LR_ratio_fx, /* i : mixing ratio */ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration */ - const Word16 start_index, /* i : start index */ - const Word16 end_index, /* i : end index */ - const Word16 fading_type /* i : fading type */ + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_mem_fx, /* i : last mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_mem_fx, /* i : last inverse mixing ration Q31*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 fading_type /* i : fading type Q0*/ ) { Word16 i; Word32 step_fx, step2_fx, fade_in_fx, fade_out_fx; step_fx = inv_time[end_index - start_index]; - fade_out_fx = ONE_IN_Q31; + fade_out_fx = ONE_IN_Q31; /* 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 ); - step2_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_fx ); - step_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_mem_fx ); + fade_out_fx = Mpy_32_32( fade_out_fx, inv_den_LR_ratio_mem_fx ); /* Q31 */ + fade_in_fx = Mpy_32_32( fade_in_fx, inv_den_LR_ratio_fx ); /* Q31 */ + step2_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_fx ); /* Q31 */ + step_fx = Mpy_32_32( step_fx, inv_den_LR_ratio_mem_fx ); /* Q31 */ IF( fading_type == 0 ) /* Switching from YX scheme to SM 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_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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Left_fx[i] = L_shl_sat( L_add( temp_left1, temp_left2 ), 1 ); /* Qx + 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 ); + 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 ); /* Qx */ + 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 ); /* Qx */ + Right_fx[i] = L_shl_sat( L_add( temp_right1, temp_right2 ), 1 ); /* Qx + 1 */ move32(); - fade_in_fx = L_add( fade_in_fx, step2_fx ); - fade_out_fx = L_sub( fade_out_fx, step_fx ); + fade_in_fx = L_add( fade_in_fx, step2_fx ); /* Q31 */ + fade_out_fx = L_sub( fade_out_fx, step_fx ); /* Q31 */ } } @@ -1125,11 +1125,11 @@ void stereo_tdm_combine( #else void stereo_tdm_combine_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel */ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel*/ - const Word16 output_frame, /* i : Number of samples */ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis */ - const Word16 tdm_ratio_idx /* i : TDM ratio index */ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ ) { Word16 i; @@ -1142,33 +1142,33 @@ void stereo_tdm_combine_fx( Word16 tdm_last_ratio_idx = hCPE->hStereoTD->tdm_last_ratio_idx; move16(); - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); - tdm_n_OVA = NS2SA( output_Fs, TDM_L_NOVA_NS ); + tdm_n_OVA = NS2SA( output_Fs, TDM_L_NOVA_NS ); /* Q0 */ move16(); IF( flag_HB ) { - upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); + upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ); /* Q0 */ move16(); } ELSE { - upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); + upmixing_delay = NS2SA( output_Fs, ACELP_LOOK_NS + DELAY_CLDFB_NS ); /* Q0 */ move16(); } - LR_ratio_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; + LR_ratio_fx = tdm_ratio_tabl_fx[tdm_ratio_idx]; /* Q31 */ move32(); - LR_ratio_mem_fx = tdm_ratio_tabl_fx[tdm_last_ratio_idx]; + LR_ratio_mem_fx = tdm_ratio_tabl_fx[tdm_last_ratio_idx]; /* Q31 */ move32(); IF( hCPE->hStereoTD->flag_skip_DMX ) { stereo_tdm_coder_type = 10; /* no DMX */ move16(); - Copy32( PCh_2_L_fx, Left_fx, output_frame ); - Copy32( SCh_2_R_fx, Right_fx, output_frame ); + Copy32( PCh_2_L_fx, Left_fx, output_frame ); /* Qx */ + Copy32( SCh_2_R_fx, Right_fx, output_frame ); /* Qx */ } ELSE IF( EQ_16( hCPE->hStereoTD->tdm_last_SM_flag, 1 ) ) { @@ -1179,7 +1179,7 @@ void stereo_tdm_combine_fx( } ELSE { - stereo_tdm_coder_type = 1; /* mode 2 : SM scheme*/ + stereo_tdm_coder_type = 1; /* mode 2 : SM scheme Q0*/ move16(); } } @@ -1262,9 +1262,9 @@ void stereo_tdm_combine_fx( } FOR( i = 0; i < output_frame; i++ ) { - PCh_2_L_fx[i] = Left_fx[i]; + PCh_2_L_fx[i] = Left_fx[i]; /* Qx */ move32(); - SCh_2_R_fx[i] = Right_fx[i]; + SCh_2_R_fx[i] = Right_fx[i]; /* Qx */ move32(); } @@ -1275,12 +1275,12 @@ void stereo_tdm_combine_fx( IF( hCPE->hStereoDftDmx != NULL ) { - fac_fx = ONE_IN_Q29; + fac_fx = ONE_IN_Q29; /* Q29 */ move32(); } ELSE { - fac_fx = hCPE->hStereoTCA->targetGain_fx; + fac_fx = hCPE->hStereoTCA->targetGain_fx; /* Q29 */ move32(); } @@ -1292,29 +1292,29 @@ void stereo_tdm_combine_fx( SWITCH( output_Fs ) { case ( 16000 ): - step = 15339168; + step = 15339168; /* Q31 */ move32(); BREAK; case ( 32000 ): - step = 7669584; + step = 7669584; /* Q31 */ move32(); BREAK; case ( 48000 ): - step = 5113056; + step = 5113056; /* Q31 */ move32(); BREAK; default: assert( 0 ); BREAK; } - incr_fx = Mpy_32_32( L_sub( ONE_IN_Q29, fac_fx ), step ); + incr_fx = Mpy_32_32( L_sub( ONE_IN_Q29, fac_fx ), step ); /* Q29 */ FOR( i = 0; i < NS2SA( output_Fs, ACELP_LOOK_NS ); i++ ) { - PCh_2_L_fx[i] = L_shl_sat( Mpy_32_32( PCh_2_L_fx[i], fac_fx ), 2 ); + PCh_2_L_fx[i] = L_shl_sat( Mpy_32_32( PCh_2_L_fx[i], fac_fx ), 2 ); /* Qx */ move32(); - fac_fx = L_add( incr_fx, fac_fx ); + fac_fx = L_add( incr_fx, fac_fx ); /* Q29 */ } } } diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 2e4c17c83..cd20bc222 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -214,6 +214,7 @@ Word32 pow32_fx( Word16 inp, Word16 indx ) *-----------------------------------------------------------------------------------------*/ /*! r: AGC enable flag */ +#ifndef IVAS_FLOAT_FIXED Word16 ivas_agc_enc_get_flag( const Word16 nchan_transport /* i : number of transport channels */ ) @@ -226,9 +227,8 @@ Word16 ivas_agc_enc_get_flag( return agc_flag; } - -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_agc_enc_get_flag_fx( +#else +Word16 ivas_agc_enc_get_flag( const Word16 nchan_transport /* i : number of transport channels */ ) { @@ -249,6 +249,7 @@ Word16 ivas_agc_enc_get_flag_fx( * AGC encoder initialization *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_agc_enc_init( ivas_agc_enc_state_t *hAgcEnc, const int16_t input_frame, @@ -289,8 +290,7 @@ static void ivas_agc_enc_init( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_agc_enc_init_fx( ivas_agc_enc_state_t *hAgcEnc, const Word16 input_frame, @@ -343,6 +343,7 @@ static void ivas_agc_enc_init_fx( * Allocate and initialize SPAR AGC encoder handle *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_agc_enc_open( ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -381,8 +382,7 @@ ivas_error ivas_spar_agc_enc_open( return IVAS_ERR_OK; } - -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_spar_agc_enc_open_fx( ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ const Word32 input_Fs, /* i : input sampling rate */ @@ -392,7 +392,7 @@ ivas_error ivas_spar_agc_enc_open_fx( ivas_agc_enc_state_t *hAgc; Word16 input_frame, delay; - if ( ( hAgc = (ivas_agc_enc_state_t *) malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL ) + IF( ( hAgc = (ivas_agc_enc_state_t *) malloc( sizeof( ivas_agc_enc_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } @@ -400,17 +400,17 @@ ivas_error ivas_spar_agc_enc_open_fx( input_frame = (Word16) Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ); delay = NS2SA_FX2( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); - if ( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( input_frame - delay ) ) ) == NULL ) + IF( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( input_frame - delay ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } - if ( ( hAgc->gain_state = (ivas_agc_enc_chan_state_t *) malloc( sizeof( ivas_agc_enc_chan_state_t ) * nchan_inp ) ) == NULL ) + IF( ( hAgc->gain_state = (ivas_agc_enc_chan_state_t *) malloc( sizeof( ivas_agc_enc_chan_state_t ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } - if ( ( hAgc->gain_data = (ivas_agc_chan_data_t *) malloc( sizeof( ivas_agc_chan_data_t ) * nchan_inp ) ) == NULL ) + IF( ( hAgc->gain_data = (ivas_agc_chan_data_t *) malloc( sizeof( ivas_agc_chan_data_t ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 2de97deda..281bd0ff5 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -868,10 +868,88 @@ ivas_error ivas_enc( { ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); + MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); + current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); + previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + } + f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); + current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); + current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); + previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + } + } + +#endif // IVAS_FLOAT_FIXED_CONVERSIONS + if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + } + current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + } + } + if ( st_ivas->hQMetaData->q_direction ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); +#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) @@ -935,10 +1013,88 @@ ivas_error ivas_enc( /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); + MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); + current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); + previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + } + f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); + current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); + current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); + previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS + if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + } + current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + } + } + if ( st_ivas->hQMetaData->q_direction ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); +#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#else if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; @@ -957,38 +1113,11 @@ ivas_error ivas_enc( int16_t nchan_transport = st_ivas->nchan_transport; int16_t nchan_ism = hEncoderConfig->nchan_ism; Word16 block_m_idx, band_m_idx; - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 32; j++ ) - { - for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hOMasa->buffer_intensity_real_fx[i][j][k] = floatToFixed( hOMasa->buffer_intensity_real[i][j][k], hOMasa->buffer_intensity_real_q[j] ); - } - } - } - for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j] = floatToFixed( hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j], hOMasa->buffer_energy_q[i] ); - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - hOMasa->chnlToFoaMtx_fx[0][i] = float_to_fix( hOMasa->chnlToFoaMtx[0][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx_fx[1][i] = float_to_fix( hOMasa->chnlToFoaMtx[1][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx_fx[2][i] = float_to_fix( hOMasa->chnlToFoaMtx[2][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx_fx[3][i] = float_to_fix( hOMasa->chnlToFoaMtx[3][i], 31 ); /*q31*/ - } for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) { for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx] = floatToFixed( hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx], 31 - hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ } } for ( i = 0; i < nchan_ism; i++ ) @@ -1015,17 +1144,6 @@ ivas_error ivas_enc( { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < nchan_ism; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - hOMasa->prev_object_dm_gains_fx[i][j] = float_to_fix16( hOMasa->prev_object_dm_gains[i][j], 15 ); - } - } - for ( i = 0; i < input_frame; i++ ) - { - hOMasa->interpolator_fx[i] = float_to_fix16( hOMasa->interpolator[i], 15 ); - } // int16_t numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { @@ -1047,45 +1165,14 @@ ivas_error ivas_enc( { hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); } - f2me_buf( hOMasa->broadband_energy_sm, hOMasa->broadband_energy_sm_fx, &hOMasa->broadband_energy_sm_e, nchan_ism + nchan_transport ); - f2me_buf( hOMasa->broadband_energy_prev, hOMasa->broadband_energy_prev_fx, &hOMasa->broadband_energy_prev_e, nchan_ism + nchan_transport ); - floatToFixed_arr16( hOMasa->fade_out_gain, hOMasa->fade_out_gain_fx, 15, input_frame ); - floatToFixed_arr16( hOMasa->fade_in_gain, hOMasa->fade_in_gain_fx, 15, input_frame ); #endif ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 32; j++ ) - { - for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hOMasa->buffer_intensity_real[i][j][k] = fixedToFloat( hOMasa->buffer_intensity_real_fx[i][j][k], hOMasa->buffer_intensity_real_q[j] ); - } - } - } - for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j] = me2f( hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j], 31 - hOMasa->buffer_energy_q[i] ); - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - hOMasa->chnlToFoaMtx[0][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[0][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[1][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[1][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[2][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[2][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[3][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[3][i], 31 ); /*q31*/ - } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) { for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx] = me2f( hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx], hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ } } for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) @@ -1127,17 +1214,8 @@ ivas_error ivas_enc( st_ivas->hIsmMetaData[i]->azimuth = fixedToFloat( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ); st_ivas->hIsmMetaData[i]->elevation = fixedToFloat( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ); } - for ( i = 0; i < nchan_ism; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - hOMasa->prev_object_dm_gains[i][j] = fixedToFloat( hOMasa->prev_object_dm_gains_fx[i][j], 15 ); - } - } fixedToFloat_arrL( data_separated_object_fx, data_separated_object, st_ivas->q_data_fx, input_frame ); - me2f_buf( hOMasa->broadband_energy_sm_fx, hOMasa->broadband_energy_sm_e, hOMasa->broadband_energy_sm, nchan_ism + nchan_transport ); - me2f_buf( hOMasa->broadband_energy_prev_fx, hOMasa->broadband_energy_prev_e, hOMasa->broadband_energy_prev, nchan_ism + nchan_transport ); -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED +#endif // IVAS_FLOAT_FIXED_CONVERSIONS } /* Encode ISMs transport channels */ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 215ede716..4d6376af1 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -956,10 +956,17 @@ ivas_error ivas_init_encoder( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED } if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) @@ -1192,13 +1199,87 @@ ivas_error ivas_init_encoder( } #ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } #else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); + MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); + current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); + previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + } + f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); + current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); + current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); + previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + } + current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + } + } + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); +#endif + +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -1604,7 +1685,7 @@ ivas_error ivas_init_encoder_fx( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { - if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1837,13 +1918,87 @@ ivas_error ivas_init_encoder_fx( #ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } #else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); + MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); + current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); + previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + } + f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); + current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); + current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); + previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + } + current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + } + } + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); +#endif + +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -2193,7 +2348,7 @@ void ivas_destroy_enc( #endif /* OMASA handle */ - ivas_omasa_enc_close( &( st_ivas->hOMasa ) ); + ivas_omasa_enc_close_fx( &( st_ivas->hOMasa ) ); /* OSBA handle */ ivas_osba_enc_close_fx( &( st_ivas->hOSba ) ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index e867ae327..3525a8ab0 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -260,10 +260,17 @@ ivas_error ivas_masa_enc_open( hMasa->data.sync_state.prev_offset = 0; hMasa->data.sync_state.frame_mode = MASA_FRAME_4SF; +#ifdef IVAS_FLOAT_FIXED + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); +#else set_zero( hMasa->data.dir_align_state.previous_azi_dir1, MASA_FREQUENCY_BANDS ); set_zero( hMasa->data.dir_align_state.previous_ele_dir1, MASA_FREQUENCY_BANDS ); set_zero( hMasa->data.dir_align_state.previous_azi_dir2, MASA_FREQUENCY_BANDS ); set_zero( hMasa->data.dir_align_state.previous_ele_dir2, MASA_FREQUENCY_BANDS ); +#endif if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { @@ -1861,6 +1868,332 @@ void ivas_masa_estimate_energy( * Frame-by-frame configuration of MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_masa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 i; + MASA_ENCODER_HANDLE hMasa; + IVAS_QMETADATA_HANDLE hQMetaData; + IVAS_FORMAT ivas_format; + UWord8 joinedSubframes; + UWord8 coherencePresent; + UWord8 isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */ + Word32 ivas_total_brate; + UWord8 maxBand; + Word16 maxBin, sf; + ivas_error error; + Word32 ism_total_brate; + Word32 masa_total_brate; + + error = IVAS_ERR_OK; + move16(); + + hMasa = st_ivas->hMasa; + hQMetaData = st_ivas->hQMetaData; + ivas_format = st_ivas->hEncoderConfig->ivas_format; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move16(); + move32(); + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); + } + } + + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); + + hQMetaData->is_masa_ivas_format = 1; + move16(); + + test(); + test(); + IF( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + { + masa_metadata_direction_alignment_fx( hMasa ); + + detect_framing_async_fx( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ + test(); + IF( EQ_16( hMasa->data.sync_state.frame_mode, MASA_FRAME_1SF ) && hMasa->data.sync_state.prev_offset != 0 ) + { + /* average over sub-frames */ + IF( EQ_32( ivas_total_brate, IVAS_512k ) ) + { + average_masa_metadata_fx( &( hMasa->masaMetadata ), hMasa->data.energy_fx, hMasa->data.energy_e, &( hMasa->data.Sph_Grid16 ), TRUE ); + } + ELSE + { + average_masa_metadata_fx( &( hMasa->masaMetadata ), hMasa->data.energy_fx, hMasa->data.energy_e, &( hMasa->data.Sph_Grid16 ), FALSE ); + } + } + + + /* Inspect metadata for parameter changes that affect coding. */ + detect_metadata_composition_fx( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); + + hMasa->config.joinedSubframes = joinedSubframes; + hMasa->config.coherencePresent = coherencePresent; + move16(); + move16(); + test(); + IF( EQ_16( add( hMasa->masaMetadata.descriptive_meta.numberOfDirections, 1 ), 2 ) && isActualTwoDir ) + { + hMasa->config.numberOfDirections = 2; + } + ELSE + { + hMasa->config.numberOfDirections = 1; + } + move16(); + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + { + /* For McMASA, these are set only once as this function is called only once. */ + hMasa->config.joinedSubframes = 0; + hMasa->config.numberOfDirections = 1; + move16(); + move16(); + } + + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) + { + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); + } + ELSE + { + test(); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) ); + } + + /* Setup importance weights for two-direction band selection. */ + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) ) + { + set32_fx( hMasa->data.importanceWeight_fx, ONE_IN_Q30 /*1.0f Q30*/, hMasa->config.numCodingBands ); + + IF( EQ_16( hMasa->config.numCodingBands, 5 ) ) + { + hMasa->data.importanceWeight_fx[4] = 751619277 /*0.7f q30*/; + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 8 ) ) + { + hMasa->data.importanceWeight_fx[7] = 751619277 /*0.7f q30*/; + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 10 ) ) + { + hMasa->data.importanceWeight_fx[8] = 751619277 /*0.7f q30*/; + hMasa->data.importanceWeight_fx[9] = 107374182 /*0.1f q30*/; + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 12 ) ) + { + hMasa->data.importanceWeight_fx[10] = 751619277 /*0.7f q30*/; + hMasa->data.importanceWeight_fx[11] = 107374182 /*0.1f q30*/; + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 18 ) ) + { + hMasa->data.importanceWeight_fx[14] = 858993459 /*0.8f q30*/; + hMasa->data.importanceWeight_fx[15] = 536870912 /*0.5f q30*/; + hMasa->data.importanceWeight_fx[16] = 214748365 /*0.2f q30*/; + hMasa->data.importanceWeight_fx[17] = 0 /*0 q30*/; + move32(); + move32(); + move32(); + move32(); + } + ELSE IF( EQ_16( hMasa->config.numCodingBands, 24 ) ) + { + hMasa->data.importanceWeight_fx[20] = 858993459 /*0.8f q30*/; + hMasa->data.importanceWeight_fx[21] = 536870912 /*0.5f q30*/; + hMasa->data.importanceWeight_fx[22] = 214748365 /*0.2f q30*/; + hMasa->data.importanceWeight_fx[23] = 0 /*0 q30*/; + move32(); + move32(); + move32(); + move32(); + } + + IF( EQ_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) + { + set8_fx( (Word8 *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + } + ELSE + { + set8_fx( (Word8 *) hMasa->data.twoDirBands, 0, hMasa->config.numCodingBands ); + } + + /* Set qmeta to correct values */ + test(); + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) && hMasa->config.numTwoDirBands != 0 ) + { + IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, 2, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, hMasa->config.numCodingBands, 1, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + FOR( i = 0; i < hQMetaData->no_directions; i++ ) + { + hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; + move16(); + IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + hQMetaData->q_direction[i].cfg.nblocks = 1; + } + ELSE + { + hQMetaData->q_direction[i].cfg.nblocks = 4; + } + move16(); + + IF( EQ_16( ivas_format, MC_FORMAT ) ) + { + hQMetaData->q_direction[i].cfg.mc_ls_setup = st_ivas->hEncoderConfig->mc_input_setup; + move16(); + } + ELSE + { + /* Just to be sure that this default value is maintained */ + hQMetaData->q_direction[i].cfg.mc_ls_setup = MC_LS_SETUP_INVALID; + move16(); + } + } + + hQMetaData->all_coherence_zero = !hMasa->config.coherencePresent; + move16(); + + ivas_set_qmetadata_maxbit_req( hQMetaData, ivas_format ); + + /* Find maximum band usable */ + maxBin = extract_l( Mpy_32_32( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_CLDFB_BANDWIDTH_Q31 /*Q31*/ ) ); /*q0+q31-q31->q0*/ + maxBand = 0; + move16(); + WHILE( LE_16( maxBand, MASA_FREQUENCY_BANDS ) && LE_16( MASA_band_grouping_24[maxBand], maxBin ) ) + { + test(); + maxBand = (UWord8) add( maxBand, 1 ); + move16(); /*because typecasting word16 to uword8*/ + } + maxBand = (UWord8) sub( maxBand, 1 ); + move16(); /*because typecasting word16 to uword8*/ + + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + masa_total_brate = ivas_total_brate; + move16(); + move32(); + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); /*q0*/ + } + test(); + test(); + IF( GE_32( masa_total_brate, IVAS_384k ) && ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) ) + { + Word16 continueLoop; + continueLoop = 1; + move16(); + WHILE( GT_16( maxBand, 5 ) && continueLoop ) + { + test(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasa->data.energy_fx[sf][maxBand - 1], hMasa->data.energy_e[sf][maxBand - 1], 100000 /*q0*/, 31 ), 1 ) ) + { + continueLoop = 0; + move16(); + BREAK; + } + } + IF( continueLoop ) + { + maxBand = (UWord8) sub( maxBand, 1 ); + move16(); /*because typecasting word16 to uword8*/ + } + } + + IF( LT_16( maxBand, MASA_MAXIMUM_CODING_SUBBANDS ) ) + { + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = (UWord8) sub( MASA_MAXIMUM_CODING_SUBBANDS, maxBand ); + move16(); /*because typecasting word16 to uword8*/ + } + ELSE + { + st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; + move16(); + } + } + + + masa_sample_rate_band_correction_fx( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, (UWord8) GE_32( masa_total_brate, IVAS_384k ), NULL ); + + + IF( GE_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) + { + hMasa->config.numTwoDirBands = hMasa->config.numCodingBands; + move16(); + set8_fx( (Word8 *) hMasa->data.twoDirBands, 1, hMasa->config.numCodingBands ); + } + + test(); + test(); + test(); + test(); + /* Transmit stereo signals using a mono downmix at lowest bitrates */ + IF( ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->nCPE, 1 ) && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + { + IF( LT_32( L_sub( ivas_total_brate, ism_total_brate ), MASA_STEREO_MIN_BITRATE ) ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 1; + } + ELSE + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; + } + move16(); + } + + test(); + test(); + test(); + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) + { + test(); + IF( EQ_16( st_ivas->hCPE[0]->element_mode, IVAS_CPE_DFT ) || LT_16( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ) ) + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx; /*Q8*/ + } + ELSE + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = shr( add( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise_fx, st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise_fx ), 1 ); /*Q8*/ + } + move16(); + } + return error; +} +#else ivas_error ivas_masa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -1973,7 +2306,7 @@ ivas_error ivas_masa_enc_config( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); } } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#endif // IVAS_FLOAT_FIXED_CONVERSIONS detect_framing_async_fx( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ if ( hMasa->data.sync_state.frame_mode == MASA_FRAME_1SF && hMasa->data.sync_state.prev_offset != 0 ) { @@ -2235,6 +2568,7 @@ ivas_error ivas_masa_enc_config( return error; } +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * ivas_masa_surrcoh_signicant() diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index a15484bfd..821450296 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -220,7 +220,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } /* With McMASA, we config MASA encoder only in init as we know the input and there are no frame-by-frame changes currently. */ - IF( NE_32( ( error = ivas_masa_enc_config( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_enc_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 748bf6423..59ea11b01 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -979,7 +979,7 @@ ivas_error create_mct_enc( } ELSE IF( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { - hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); + hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs_fx( ivas_total_brate, st_ivas->sba_analysis_order ); move16(); test(); @@ -1769,25 +1769,171 @@ static ivas_error ivas_mc_enc_reconfig( return error; } #ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); + MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); + for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); + current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); + previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + } + f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); + current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); + current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); + previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + } + current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + } + } + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif } else { /* reconfigure McMASA instance */ #ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + MASA_METADATA_HANDLE current_meta = &( st_ivas->hMasa->masaMetadata ); + MASA_METADATA_HANDLE previous_meta = &( st_ivas->hMasa->data.sync_state.previous_metadata ); + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); + for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( current_meta->directional_meta[k].azimuth[i][j], Q22 ); + current_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( current_meta->directional_meta[k].elevation[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( current_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + previous_meta->directional_meta[k].azimuth_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].azimuth[i][j], Q22 ); + previous_meta->directional_meta[k].elevation_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].elevation[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio_fx[i][j] = floatToFixed( previous_meta->directional_meta[k].energy_ratio[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->directional_meta[k].spread_coherence[i][j], Q15 ) ); + } + f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); + current_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( current_meta->common_meta.surround_coherence[i][j], Q15 ) ); + current_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( current_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.surround_coherence_fx[i][j] = (Word16) min( 32767, floatToFixed( previous_meta->common_meta.surround_coherence[i][j], Q15 ) ); + previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.diffuse_to_total_ratio[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio_fx[i][j] = floatToFixed( previous_meta->common_meta.remainder_to_total_ratio[i][j], Q30 ); + } + } +#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + for ( int k = 0; k < MASA_MAXIMUM_DIRECTIONS; k++ ) + { + current_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( current_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + current_meta->directional_meta[k].elevation[i][j] = fixedToFloat( current_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + current_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( current_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + current_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( current_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + previous_meta->directional_meta[k].azimuth[i][j] = fixedToFloat( previous_meta->directional_meta[k].azimuth_fx[i][j], Q22 ); + previous_meta->directional_meta[k].elevation[i][j] = fixedToFloat( previous_meta->directional_meta[k].elevation_fx[i][j], Q22 ); + previous_meta->directional_meta[k].energy_ratio[i][j] = fixedToFloat( previous_meta->directional_meta[k].energy_ratio_fx[i][j], Q30 ); + previous_meta->directional_meta[k].spread_coherence[i][j] = fixedToFloat( previous_meta->directional_meta[k].spread_coherence_fx[i][j], Q15 ); + } + current_meta->common_meta.surround_coherence[i][j] = fixedToFloat( current_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + current_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + current_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( current_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.surround_coherence[i][j] = fixedToFloat( previous_meta->common_meta.surround_coherence_fx[i][j], Q15 ); + previous_meta->common_meta.diffuse_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.diffuse_to_total_ratio_fx[i][j], Q30 ); + previous_meta->common_meta.remainder_to_total_ratio[i][j] = fixedToFloat( previous_meta->common_meta.remainder_to_total_ratio_fx[i][j], Q30 ); + } + } + if ( st_ivas->hQMetaData->q_direction != NULL ) + { + for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } + fixedToFloat_arrL( st_ivas->hMasa->data.importanceWeight_fx, st_ivas->hMasa->data.importanceWeight, 30, 24 ); +#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) -#endif { return error; } +#endif } #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 095853da9..0265b1339 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -121,6 +121,117 @@ static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, Wo * Allocate and initialize OMASA handle *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_omasa_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + Word16 i, j; + OMASA_ENC_HANDLE hOMasa; + Word16 numAnalysisChannels; + Word16 input_frame; + ivas_error error; + + error = IVAS_ERR_OK; + move16(); + + assert( st_ivas->hMasa != NULL && "MASA encoder handle is not present" ); + + IF( ( hOMasa = (OMASA_ENC_HANDLE) malloc( sizeof( OMASA_ENC_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA encoder\n" ) ); + } + + numAnalysisChannels = st_ivas->hEncoderConfig->nchan_ism; + move16(); + + /* open/initialize CLDFB */ + hOMasa->num_Cldfb_instances = numAnalysisChannels; + move16(); + FOR( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) + { + IF( ( error = openCldfb_ivas_enc( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + set_zero_fx( &hOMasa->chnlToFoaMtx_fx[0][0], DIRAC_MAX_ANA_CHANS * MCMASA_MAX_ANA_CHANS ); + + /* intensity 3-dim */ + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + hOMasa->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ); + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( ( hOMasa->direction_vector_m_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + set_zero_fx( hOMasa->direction_vector_m_fx[i][j], MASA_FREQUENCY_BANDS ); + } + hOMasa->direction_vector_e[i] = (Word16 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 * ) ); + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + IF( ( hOMasa->direction_vector_e[i][j] = (Word16 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + set16_fx( hOMasa->direction_vector_e[i][j], 0, MASA_FREQUENCY_BANDS ); + } + } + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( ( hOMasa->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( MASA_FREQUENCY_BANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data\n" ) ); + } + set_zero_fx( hOMasa->buffer_intensity_real_fx[i][j], MASA_FREQUENCY_BANDS ); + } + } + set16_fx( hOMasa->buffer_intensity_real_q, 31, DIRAC_NO_COL_AVG_DIFF ); + set_zero_fx( hOMasa->buffer_energy_fx, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); + set16_fx( hOMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); + + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) + { + set16_fx( hOMasa->prev_object_dm_gains_fx[i], INV_SQRT_2_Q15, MASA_MAX_TRANSPORT_CHANNELS ); /*q15*/ + } + set_zero_fx( hOMasa->broadband_energy_sm_fx, MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS ); + hOMasa->broadband_energy_sm_e = 0; + move16(); + set_zero_fx( hOMasa->broadband_energy_prev_fx, MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS ); + hOMasa->broadband_energy_prev_e = 0; + move16(); + + hOMasa->prev_selected_object = 0; + hOMasa->changing_object = 0; + move16(); + move16(); + + input_frame = extract_l( Mult_32_16( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_FRAME_PER_SEC_Q15 /*q15*/ ) ); /*Q0+Q15-Q15->Q0*/ + FOR( i = 0; i < input_frame; i++ ) + { + hOMasa->interpolator_fx[i] = divide1616( i, input_frame ); /*q15*/ + hOMasa->fade_out_gain_fx[i] = add( 16384 /*0.5 in q15*/, shr( getCosWord16R2( mult( hOMasa->interpolator_fx[i], 32767 / 2 ) /*15+15-15=>15*/ ), 1 ) /*q15*/ ); /*(angle in degrees=((float)i/(float)input_frame *pi)*180/pi)/360*32767 =>(float)i/(float)input_frame )*32767/2*/ /*q15*/ + hOMasa->fade_in_gain_fx[i] = sub( 32767 /*1.0 in Q15*/, hOMasa->fade_out_gain_fx[i] ); /*q15*/ + move16(); + move16(); + move16(); + } + + hOMasa->index_buffer_intensity = 0; + move16(); + + st_ivas->hOMasa = hOMasa; + + return error; +} +#else ivas_error ivas_omasa_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -248,7 +359,7 @@ ivas_error ivas_omasa_enc_open( return error; } - +#endif /*--------------------------------------------------------------------------* * ivas_omasa_enc_close() @@ -256,6 +367,50 @@ ivas_error ivas_omasa_enc_open( * Close OMASA handle *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + +void ivas_omasa_enc_close_fx( + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ +) +{ + Word16 i, j; + + test(); + IF( hOMasa == NULL || *hOMasa == NULL ) + { + return; + } + + FOR( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) + { + deleteCldfb_ivas( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); + } + + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( ( *hOMasa )->direction_vector_m_fx[i][j] ); + ( *hOMasa )->direction_vector_m_fx[i][j] = NULL; + free( ( *hOMasa )->direction_vector_e[i][j] ); + ( *hOMasa )->direction_vector_e[i][j] = NULL; + } + + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + free( ( *hOMasa )->buffer_intensity_real_fx[i][j] ); + ( *hOMasa )->buffer_intensity_real_fx[i][j] = NULL; + } + free( ( *hOMasa )->direction_vector_m_fx[i] ); + ( *hOMasa )->direction_vector_m_fx[i] = NULL; + } + + free( *hOMasa ); + ( *hOMasa ) = NULL; + + return; +} +#else void ivas_omasa_enc_close( OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ) @@ -308,13 +463,141 @@ void ivas_omasa_enc_close( return; } - +#endif /*--------------------------------------------------------------------------* * ivas_omasa_enc_config() * * oMASA encoder configuration *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_omasa_enc_config_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 k, sce_id, nSCE_old; + Word32 ivas_total_brate, ism_total_brate; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + nSCE_old = st_ivas->nSCE; + move16(); + move32(); /*hEncoderConfig->ivas_total_brate*/ + + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + move16(); + st_ivas->nchan_transport = 2; + move16(); + + /* reconfiguration in case of bitrate switching */ + IF( NE_32( hEncoderConfig->last_ivas_total_brate, ivas_total_brate ) ) + { + ivas_set_omasa_TC_fx( st_ivas->ism_mode, hEncoderConfig->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); + + k = 0; + move16(); + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) + { + test(); + k = add( k, 1 ); + } + + ism_total_brate = 0; + move32(); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + } + + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + IF( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, 1, NULL, 0, NULL, NULL, NULL, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + IF( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nSCE, NULL, 0, NULL, NULL, NULL, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* reconfigure core-coders for ISMs */ + IF( st_ivas->nSCE > 0 ) + { + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, 1, 2, sep_object_brate[k - 2][st_ivas->nSCE - 1], L_sub( ivas_total_brate, ism_total_brate ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, 1, 2, 0, L_sub( ivas_total_brate, ism_total_brate ), MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* re-write IVAS format signalling - actual 'ism_mode' was not known before */ + IF( st_ivas->nSCE > 0 ) + { + reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot ); + } + ELSE + { + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot ); + } + + ivas_write_format_fx( st_ivas ); + + test(); + test(); + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hOMasa == NULL ) + { + IF( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hOMasa != NULL ) + { + ivas_omasa_enc_close_fx( &( st_ivas->hOMasa ) ); + st_ivas->hOMasa = NULL; + } + + st_ivas->hCPE[0]->element_brate = L_sub( ivas_total_brate, ism_total_brate ); + move32(); + + IF( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + ELSE + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + move16(); + } + + /* Configure MASA encoder based on frame parameters */ + IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + /* Configure oMASA analysis based on MASA config */ + ivas_omasa_set_config_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); + } + + return IVAS_ERR_OK; +} +#else ivas_error ivas_omasa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ @@ -438,6 +721,7 @@ ivas_error ivas_omasa_enc_config( return IVAS_ERR_OK; } +#endif // IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* diff --git a/lib_enc/ivas_pca_enc.c b/lib_enc/ivas_pca_enc.c index 726df7c99..17cd24ba3 100644 --- a/lib_enc/ivas_pca_enc.c +++ b/lib_enc/ivas_pca_enc.c @@ -460,17 +460,28 @@ static void sort4_D_eigVec_fx( * * Initialize PCA encoder *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_pca_enc_init( PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ ) { hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; + move32(); pca_enc_reset( hPCA ); return; } +#else +void ivas_pca_enc_init( + PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ +) +{ + hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; + pca_enc_reset( hPCA ); + return; +} +#endif /*------------------------------------------------------------------------- * ivas_pca_enc() diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 3e9f1e2ed..68b457c3c 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -177,7 +177,7 @@ ivas_error ivas_spar_enc_open( /* AGC handle */ #ifdef IVAS_FLOAT_FIXED - hSpar->AGC_Enable = ivas_agc_enc_get_flag_fx( nchan_transport ); + hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #else hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); #endif @@ -295,6 +295,7 @@ ivas_error ivas_spar_enc_open_fx( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; + move32(); hSpar = st_ivas->hSpar; IF( !spar_reconfig_flag ) @@ -307,24 +308,30 @@ ivas_error ivas_spar_enc_open_fx( } hSpar->spar_reconfig_flag = 0; + move16(); input_Fs = hEncoderConfig->input_Fs; + move32(); sba_order_internal = extract_l( L_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ) ); nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; - + move32(); nchan_fb_in = 0; + move16(); IF( EQ_16( st_ivas->sba_analysis_order, 1 ) ) { nchan_fb_in = FOA_CHANNELS; + move16(); } ELSE IF( EQ_16( st_ivas->sba_analysis_order, 2 ) ) { nchan_fb_in = 9; + move16(); } ELSE IF( EQ_16( st_ivas->sba_analysis_order, 3 ) ) { nchan_fb_in = 11; + move16(); } ELSE { @@ -343,6 +350,7 @@ ivas_error ivas_spar_enc_open_fx( /* set FB config. */ active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + move16(); IF( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in ) ) != IVAS_ERR_OK ) { return error; @@ -350,24 +358,16 @@ ivas_error ivas_spar_enc_open_fx( fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ - IF( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_FB_mixer_open_fx( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { return error; } /* Covariance handle */ -#ifdef IVAS_FLOAT_FIXED IF( NE_32( ( error = ivas_spar_covar_enc_open_fx( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } -#else - IF( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - IF( !spar_reconfig_flag ) { /* Transient Detector handle */ @@ -379,14 +379,14 @@ ivas_error ivas_spar_enc_open_fx( /* initialization */ hSpar->hMdEnc->table_idx = -1; - + move16(); /* AGC handle */ hSpar->AGC_Enable = ivas_agc_enc_get_flag( nchan_transport ); - + move16(); hSpar->hAgcEnc = NULL; IF( hSpar->AGC_Enable ) { - IF( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_agc_enc_open_fx( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { return error; } @@ -405,16 +405,12 @@ ivas_error ivas_spar_enc_open_fx( /* initialization */ hSpar->hMdEnc->table_idx = -1; - + move16(); /*-----------------------------------------------------------------* * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); -#else - ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); -#endif + ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { @@ -424,7 +420,7 @@ ivas_error ivas_spar_enc_open_fx( { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } - + move16(); /*-----------------------------------------------------------------* * Allocate and initialize Front-VAD handle *-----------------------------------------------------------------*/ @@ -432,9 +428,11 @@ ivas_error ivas_spar_enc_open_fx( IF( !spar_reconfig_flag ) { hSpar->front_vad_flag = 0; + move16(); hSpar->front_vad_dtx_flag = 0; + move16(); hSpar->force_front_vad = 0; - + move16(); IF( hEncoderConfig->Opt_DTX_ON ) { IF( ( error = front_vad_create_fx( &( hSpar->hFrontVad ), hEncoderConfig ) ) != IVAS_ERR_OK ) @@ -451,7 +449,8 @@ ivas_error ivas_spar_enc_open_fx( hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; - + move32(); + move32(); IF( ( error = init_encoder_ivas_fx( hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 3c97580fc..d61ed4bd6 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -250,7 +250,7 @@ ivas_error ivas_spar_md_enc_open_fx( ivas_error error; Word16 num_channels, i, j; error = IVAS_ERR_OK; - + move32(); IF( ( hMdEnc = (ivas_spar_md_enc_state_t *) malloc( sizeof( ivas_spar_md_enc_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); @@ -258,6 +258,12 @@ ivas_error ivas_spar_md_enc_open_fx( num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); + IF( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); + } + memset( hMdEnc->spar_md.band_coeffs, 0, IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ); + IF( ( hMdEnc->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -426,25 +432,38 @@ ivas_error ivas_spar_md_enc_init_fx( Word32 pFC[IVAS_MAX_NUM_BANDS]; Word16 table_idx; Word16 num_channels, i, j, k; - + Word32 PR_minmax_fx[2]; ivas_sba_get_spar_hoa_md_flag_fx( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); table_idx = ivas_get_spar_table_idx_fx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); hMdEnc->spar_md.prior_dyn_active_w_flag = 0; + move16(); + Word16 num_bands; + IF( hMdEnc->spar_hoa_md_flag != 0 ) + { + num_bands = IVAS_MAX_NUM_BANDS; + move16(); + } + ELSE + { + num_bands = SPAR_DIRAC_SPLIT_START_BAND; + move16(); + } - ivas_spar_set_bitrate_config_fx( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, + ivas_spar_set_bitrate_config_fx( &hMdEnc->spar_md_cfg, table_idx, num_bands, hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag( ivas_spar_br_table_consts[table_idx].nchan_transport ) ); // TODO: some log operations pending. - /* get FB coefficients */ FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { pFC[i] = L_shr( Mpy_32_32( ivas_fb_fcs_12band_1ms_fx[i], hEncoderConfig->input_Fs ), 1 ); // Q0 + move32(); } ivas_spar_set_enc_config_fx( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels ); - + test(); + test(); IF( NE_16( hMdEnc->spar_md_cfg.nchan_transport, 2 ) && ( EQ_16( hMdEnc->spar_md_cfg.remix_unmix_order, 1 ) || EQ_16( hMdEnc->spar_md_cfg.remix_unmix_order, 2 ) ) ) { return IVAS_ERR_INTERNAL; @@ -452,18 +471,19 @@ ivas_error ivas_spar_md_enc_init_fx( ivas_spar_arith_coeffs_com_init_fx( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); ivas_spar_huff_coeffs_com_init_fx( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); -#if 0 // Some issues - IF (EQ_16(hEncoderConfig->Opt_DTX_ON, 1)) - { - /* DTX quant init */ - PR_minmax_fx[0] = hMdEnc->spar_md_cfg.quant_strat[0].PR.min_fx; - PR_minmax_fx[1] = hMdEnc->spar_md_cfg.quant_strat[0].PR.max_fx; - ivas_spar_quant_dtx_init_fx(&hMdEnc->spar_md, PR_minmax_fx); - } -#endif + IF( EQ_16( hEncoderConfig->Opt_DTX_ON, 1 ) ) + { + /* DTX quant init */ + PR_minmax_fx[0] = hMdEnc->spar_md_cfg.quant_strat[0].PR.min_fx; + move32(); + PR_minmax_fx[1] = hMdEnc->spar_md_cfg.quant_strat[0].PR.max_fx; + move32(); + ivas_spar_quant_dtx_init_fx( &hMdEnc->spar_md, PR_minmax_fx ); + } hMdEnc->spar_md_cfg.prior_strat = START; + move16(); hMdEnc->spar_md_cfg.prev_quant_idx = -1; - + move16(); FOR( i = 0; i < num_channels; i++ ) { FOR( j = 0; j < num_channels; j++ ) @@ -471,13 +491,13 @@ ivas_error ivas_spar_md_enc_init_fx( FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { hMdEnc->mixer_mat_fx[i][j][k] = 0; + move32(); } } } hMdEnc->q_mixer_mat_fx = 0; -#if 0 // Some issue - ivas_clear_band_coeffs_fx(hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS); -#endif + move16(); + ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); @@ -547,19 +567,30 @@ static void ivas_spar_set_enc_config_fx( { IF( max_freq_per_chan != NULL ) { - hMdEnc->spar_md_cfg.max_freq_per_chan[i] = ( max_freq_per_chan[i] != 0 ) ? max_freq_per_chan[i] : max_freq_per_chan[0]; + IF( max_freq_per_chan[i] != 0 ) + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = max_freq_per_chan[i]; + } + ELSE + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = max_freq_per_chan[0]; + } + move16(); } ELSE { hMdEnc->spar_md_cfg.max_freq_per_chan[i] = IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN; + move16(); } } hMdEnc->num_umx_ch = nchan_inp; + move16(); hMdEnc->num_decorr = sub( nchan_inp, 1 ); - + move16(); FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { tmp_dmx_ch = 0; + move16(); FOR( j = 0; j < nchan_transport; j++ ) { IF( LT_32( pFC[i], hMdEnc->spar_md_cfg.max_freq_per_chan[j] ) ) @@ -569,7 +600,9 @@ static void ivas_spar_set_enc_config_fx( } hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i] = tmp_dmx_ch; + move16(); hMdEnc->spar_md_cfg.num_decorr_per_band[i] = sub( hMdEnc->num_umx_ch, tmp_dmx_ch ); + move16(); } return; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 1e2eea3d7..67ff327e2 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1176,22 +1176,22 @@ typedef struct ivas_mc_paramupmix_enc_data_structure typedef struct ivas_omasa_enc_state_structure { #ifdef IVAS_FLOAT_FIXED - Word16 interpolator_fx[L_FRAME48k]; /*q15*/ - Word16 prev_object_dm_gains_fx[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; /*q15*/ - Word32 chnlToFoaMtx_fx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; /*q15*/ - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ - Word16 **direction_vector_e[DIRAC_NUM_DIMS]; /* Average direction vector */ - Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; - Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; - Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; - Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; - Word32 broadband_energy_sm_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - Word16 broadband_energy_sm_e; - Word32 broadband_energy_prev_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - Word16 broadband_energy_prev_e; - Word16 fade_out_gain_fx[L_FRAME48k]; /*q15*/ - Word16 fade_in_gain_fx[L_FRAME48k]; /*q15*/ -#endif // IVAS_FLOAT_FIXED + Word16 interpolator_fx[L_FRAME48k]; /*q15*/ + Word16 prev_object_dm_gains_fx[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; /*q15*/ + Word32 chnlToFoaMtx_fx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; /*q31*/ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector*/ /*q is 31-direction_vector_e*/ + Word16 **direction_vector_e[DIRAC_NUM_DIMS]; /* exp for direction_vector_m_fx */ + Word32 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; /*q is buffer_intensity_real_q*/ + Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; /*q is buffer_energy_q*/ + Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; /*q for buffer_intensity_real_fx*/ + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; /*q for buffer_energy_fx*/ + Word32 broadband_energy_sm_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; /* q is 31-broadband_energy_sm_e*/ + Word16 broadband_energy_sm_e; /*exponent for broadband_energy_sm_fx*/ + Word32 broadband_energy_prev_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; /*q is 31-broadband_energy_prev_e*/ + Word16 broadband_energy_prev_e; /*exponent for broadband_energy_prev_fx*/ + Word16 fade_out_gain_fx[L_FRAME48k]; /*q15*/ + Word16 fade_in_gain_fx[L_FRAME48k]; /*q15*/ +#endif // IVAS_FLOAT_FIXED uint8_t nbands; uint8_t nCodingBands; uint8_t nSubframes; @@ -1201,26 +1201,34 @@ typedef struct ivas_omasa_enc_state_structure HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; /* DirAC parameter estimation */ +#ifndef IVAS_FLOAT_FIXED float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ +#endif int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; int16_t block_grouping[5]; /* diffuseness */ int16_t index_buffer_intensity; +#ifndef IVAS_FLOAT_FIXED float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; float chnlToFoaMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; float interpolator[L_FRAME48k]; +#endif // !IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED float prev_object_dm_gains[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; float broadband_energy_sm[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; float broadband_energy_prev[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; +#endif // !IVAS_FLOAT_FIXED int16_t prev_selected_object; uint8_t changing_object; +#ifndef IVAS_FLOAT_FIXED float fade_out_gain[L_FRAME48k]; float fade_in_gain[L_FRAME48k]; +#endif // !IVAS_FLOAT_FIXED } OMASA_ENC_STATE, *OMASA_ENC_HANDLE; @@ -1261,13 +1269,14 @@ typedef struct ivas_masa_dir_align_struct Word32 previous_azi_dir2_fx[MASA_FREQUENCY_BANDS]; /*q22*/ Word32 previous_ele_dir2_fx[MASA_FREQUENCY_BANDS]; /*q22*/ -#endif // IVAS_FLOAT_FIXED +#else float previous_azi_dir1[MASA_FREQUENCY_BANDS]; float previous_ele_dir1[MASA_FREQUENCY_BANDS]; float previous_azi_dir2[MASA_FREQUENCY_BANDS]; float previous_ele_dir2[MASA_FREQUENCY_BANDS]; +#endif } MASA_DIR_ALIGN_STATE, *MASA_DIR_ALIGN_HANDLE; @@ -1297,7 +1306,7 @@ typedef struct ivas_masa_encoder_data_struct SPHERICAL_GRID_DATA Sph_Grid16; float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED - Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; + Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; /*q30*/ Word32 lfeToTotalEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 lfeToTotalEnergyRatio_e[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 0dadad669..683907e8a 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -325,7 +325,7 @@ ivas_error stereo_memory_enc_fx( test(); IF( hCPE->hStereoTCA != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - set16_fx( hCPE->hStereoTCA->prevCorrLagStats, (Word16) hCPE->hStereoDft->hItd->itd_fx[1], 3 ); + set16_fx( hCPE->hStereoTCA->prevCorrLagStats, extract_h( hCPE->hStereoDft->hItd->itd_fx[1] ), 3 ); IF( hCPE->hStereoDft->hItd->itd_fx[1] >= 0 ) { hCPE->hStereoTCA->prevRefChanIndx = L_CH_INDX; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 7a60a2e1a..fdb85842b 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1327,7 +1327,7 @@ static ivas_error configureEncoder_fx( } IF( hEncoderConfig->Opt_DTX_ON && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && - ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_32( ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || + ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_32( ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) || EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) ) { return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 2d2028492..525c2af46 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -967,13 +967,13 @@ static void quant_peaks_ivas_fx( cb_class = w_vquant_fx( x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0 ); IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - indx = sub( HVQ_MAX_PEAKS_24k, Npeaks ); + indx = s_max( 0, sub( HVQ_MAX_PEAKS_24k, Npeaks ) ); search_overlap = hvq_cb_search_overlap24k[indx]; move16(); } ELSE { - indx = sub( HVQ_MAX_PEAKS_32k, Npeaks ); + indx = s_max( 0, sub( HVQ_MAX_PEAKS_32k, Npeaks ) ); search_overlap = hvq_cb_search_overlap32k[indx]; move16(); } -- GitLab