From 210e424e4181784a9ff552c5626c19bf58629eb4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 25 May 2024 15:42:09 +0530 Subject: [PATCH] Renderer functions integration, float buffers and structure elements cleanup [x] Binaural renderer unwrap conversion and integration [x] getDirectPartGains_fx integration [x] ivas_dirac_dec_render_sf_fx float buffers cleanup [x] lib rend.c float code cleanup --- apps/renderer.c | 15 +- lib_com/common_api_types.h | 6 + lib_com/ivas_cnst.h | 2 +- lib_com/ivas_prot.h | 14 + lib_com/ivas_stat_com.h | 16 +- lib_com/stat_com.h | 4 +- lib_dec/ivas_dirac_dec.c | 62 +-- lib_dec/ivas_init_dec.c | 41 +- lib_dec/ivas_ism_dec.c | 4 +- lib_dec/ivas_ism_param_dec.c | 208 ++++----- lib_dec/ivas_jbm_dec.c | 85 +--- lib_dec/ivas_masa_dec.c | 37 +- lib_dec/ivas_omasa_dec.c | 3 - lib_dec/ivas_sba_dec.c | 7 - lib_dec/ivas_spar_decoder.c | 31 -- lib_dec/ivas_spar_md_dec.c | 95 ++--- lib_dec/ivas_stat_dec.h | 30 +- lib_dec/ivas_stereo_cng_dec.c | 47 ++- lib_dec/lib_dec_fx.c | 34 -- lib_rend/ivas_dirac_dec_binaural_functions.c | 66 ++- lib_rend/ivas_dirac_rend.c | 149 ++----- lib_rend/ivas_objectRenderer.c | 362 +++++----------- lib_rend/ivas_objectRenderer_sources.c | 14 +- lib_rend/ivas_prot_rend.h | 2 +- lib_rend/ivas_stat_rend.h | 21 +- lib_rend/lib_rend.c | 423 ++++++++++++------- lib_rend/lib_rend.h | 12 + 27 files changed, 731 insertions(+), 1059 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 82eb11067..df81d926b 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -48,6 +48,10 @@ #include "vector3_pair_file_reader.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx1.h" +#endif + #define WMC_TOOL_SKIP /*------------------------------------------------------------------------------------------* @@ -826,11 +830,20 @@ int main( } const int16_t frameSize_smpls = (int16_t) ( ( args.render_framesize ) * args.sampleRate * 5 / ( 1000 ) ); - if ( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, args.nonDiegeticPanGain, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) +#ifdef IVAS_FLOAT_FIXED + Word32 nonDiegeticPanGain_fx = (args.nonDiegeticPanGain ==1.0f)? ONE_IN_Q31: (args.nonDiegeticPanGain == -1.0f)? L_negate(ONE_IN_Q31):(Word32)(args.nonDiegeticPanGain*(1LL<< Q31 )); + IF( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, nonDiegeticPanGain_fx, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Error opening renderer handle: %s\n", ivas_error_to_string( error ) ); + exit( -1 ); + } +#else + IF ( ( error = IVAS_REND_Open( &hIvasRend, args.sampleRate, args.outConfig.audioConfig, args.nonDiegeticPan, args.nonDiegeticPanGain, (int16_t) args.render_framesize ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Error opening renderer handle: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } +#endif // IVAS_FLOAT_FIXED /* === Configure === */ if ( ( error = IVAS_REND_InitConfig( hIvasRend, args.outConfig.audioConfig ) ) != IVAS_ERR_OK ) diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 563c51d6d..6af1b0ee1 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -121,6 +121,11 @@ typedef struct _IVAS_ISM_METADATA #ifdef IVAS_FLOAT_FIXED Word32 azimuth_fx; Word32 elevation_fx; + Word16 radius_fx; + Word32 spread_fx; + Word32 gainFactor_fx; + Word32 yaw_fx; + Word32 pitch_fx; #endif float azimuth; float elevation; @@ -255,4 +260,5 @@ typedef struct _IVAS_RENDER_CONFIG #endif } IVAS_RENDER_CONFIG_DATA, *IVAS_RENDER_CONFIG_HANDLE; + #endif /* COMMON_API_TYPES_H */ diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index c7b930a31..da5d5fcef 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -48,7 +48,7 @@ #define ONE_BY_PI_OVER_180_Q25 ( 1922527360 ) #define _180_OVER_PI ( 180.0f / EVS_PI ) #ifdef IVAS_FLOAT_FIXED -#define _180_OVER_PI_Q25 1922527233 +#define _180_OVER_PI_Q25 1922521886 #define _180_IN_Q22 (754974720) #define _360_IN_Q22 (1509949440) #define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 41fa20009..11d2199a1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1280,15 +1280,29 @@ ivas_error ivas_ism_dec_config( ); #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_param_ism_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#else ivas_error ivas_param_ism_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#endif +#ifdef IVAS_FLOAT_FIXED +void ivas_param_ism_dec_close_fx( + PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ + const AUDIO_CONFIG output_config /* i : output audio configuration */ +); +#else void ivas_param_ism_dec_close( PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ const AUDIO_CONFIG output_config /* i : output audio configuration */ ); +#endif void ivas_param_ism_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index dfe9942a5..efd2b299d 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -446,10 +446,10 @@ typedef struct ivas_masa_directional_spatial_meta_struct float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float spread_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q22 */ + Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ + Word16 spread_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q15 */ #endif uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; @@ -522,15 +522,15 @@ typedef struct ivas_qdirection_band_data_struct float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED - Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q30 */ #endif uint8_t distance[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -595,7 +595,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifndef IVAS_FLOAT_FIXED float dir_comp_ratio; #else - Word16 dir_comp_ratio_fx; + Word16 dir_comp_ratio_fx; /* Q15 */ #endif uint8_t is_masa_ivas_format; diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index e58393e8d..538d5c934 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -519,8 +519,8 @@ typedef struct #endif Word16 likelihood_noisy_speech; - float coherence_flt; /* inter-channel coherence of noise */ - Word16 coherence_fx; /* inter-channel coherence of noise */ + float coherence_flt; /* inter-channel coherence of noise */ + Word16 coherence_fx; /* inter-channel coherence of noise */ /* Q15 */ int16_t no_side_flag; /* indicates whether the side noise shape should be zeroed-out or not */ } FD_CNG_COM, *HANDLE_FD_CNG_COM; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 29cca5c92..ec86f6303 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3540,15 +3540,6 @@ void ivas_dirac_dec_render_sf_fx( set_s( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX ); //////////////////////////////////////////////////////////////////////////// to be removed /////////////////////////////////////////////////////////////////// - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) - { - floatToFixed_arrL32( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], Q30, hSpatParamRendCom->num_freq_bands ); - md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]; - } - ELSE - { - md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->slots_rendered]; - } IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) { @@ -3559,14 +3550,6 @@ void ivas_dirac_dec_render_sf_fx( { p_Rmat_fx = 0; } - IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) - { - IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) - { - floatToFixed_arrL32( hSpatParamRendCom->energy_ratio1[md_idx], hSpatParamRendCom->energy_ratio1_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL32( hSpatParamRendCom->energy_ratio2[md_idx], hSpatParamRendCom->energy_ratio2_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); - } - } IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) { @@ -3601,14 +3584,6 @@ void ivas_dirac_dec_render_sf_fx( floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); IF( hDirACRend->masa_stereo_type_detect ) { - IF( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db == -INFINITY ) - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = MIN_32; - } - ELSE - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db, Q21 ); - } hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0; hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31; } @@ -3633,14 +3608,6 @@ void ivas_dirac_dec_render_sf_fx( floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); IF( hDirACRend->masa_stereo_type_detect ) { - IF( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db == -INFINITY ) - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = MIN_32; - } - ELSE - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db, Q21 ); - } hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = floatToFixed(hDirACRend->masa_stereo_type_detect->subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y); } } @@ -3687,15 +3654,6 @@ void ivas_dirac_dec_render_sf_fx( num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; } - if ( hDirAC->hConfig->dec_param_estim == FALSE && hodirac_flag ) - { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[md_idx], hSpatParamRendCom->energy_ratio1_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[md_idx], hSpatParamRendCom->energy_ratio2_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); - } - } - if ( h_dirac_output_synthesis_params->use_onset_filters && ( hDirAC->hConfig->dec_param_estim != TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) ) { h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); @@ -3801,10 +3759,6 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - IF( st_ivas->hMasa != NULL ) - { - st_ivas->hMasa->data.dir_decode_quality_fx = float_to_fix16( st_ivas->hMasa->data.dir_decode_quality, Q15 ); - } floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); IF( hDirACRend->masa_stereo_type_detect != NULL ) { @@ -4711,14 +4665,7 @@ void ivas_dirac_dec_render_sf_fx( IF( st_ivas->hMasa != NULL ) { - IF( EQ_16( st_ivas->hMasa->data.dir_decode_quality_fx, MAX_16 ) ) - { - qualityBasedSmFactor_fx = MAX_32; - } - ELSE - { - qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); // (Q15, Q15) -> Q31 - } + qualityBasedSmFactor_fx = L_mult( st_ivas->hMasa->data.dir_decode_quality_fx, st_ivas->hMasa->data.dir_decode_quality_fx ); /* (Q15, Q15) -> Q31 */ } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) @@ -5327,11 +5274,6 @@ void ivas_dirac_dec_render_sf_fx( fixedToFloat_arrL32( hDirACRend->buffer_intensity_real_fx[2][i], hDirACRend->buffer_intensity_real[2][i], hDirACRend->q_buffer_intensity_real[i], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); fixedToFloat_arrL32( &hDirACRend->buffer_energy_fx[i * num_freq_bands], &hDirACRend->buffer_energy[i * num_freq_bands], hDirACRend->q_buffer_energy[i], hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); } - FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - md_idx = hSpatParamRendCom->render_to_md_map[add( hSpatParamRendCom->slots_rendered, slot_idx )]; - fixedToFloat_arrL32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->diffuseness_vector[md_idx], Q30, hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band] ); - } } IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) @@ -5443,8 +5385,6 @@ void ivas_dirac_dec_render_sf_fx( IF( hDirACRend->masa_stereo_type_detect != NULL ) { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx, Q21 ); - hDirACRend->masa_stereo_type_detect->target_power_y_smooth = fixedToFloat( hDirACRend->masa_stereo_type_detect->target_power_y_smooth_fx, hDirACRend->masa_stereo_type_detect->q_target_power_y_smooth ); hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); hDirACRend->masa_stereo_type_detect->subtract_power_y = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 0947468a2..9e57b7245 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -362,16 +362,9 @@ ivas_error ivas_dec_setup( TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; IF( Src_p->SrcSpatial_p != NULL ) { - FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) - { - fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); - fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); - } Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); - fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); SrcSpatial_p->q_Pos_p = Q31; } } @@ -469,16 +462,9 @@ ivas_error ivas_dec_setup( TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; IF( Src_p->SrcSpatial_p != NULL ) { - FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) - { - fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); - fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); - } Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); - fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); SrcSpatial_p->q_Pos_p = Q31; } } @@ -1472,7 +1458,7 @@ ivas_error ivas_init_decoder_fx( st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; st_ivas->nSCE = MAX_PARAM_ISM_WAVE; - IF ( ( error = ivas_param_ism_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -2230,16 +2216,9 @@ ivas_error ivas_init_decoder_fx( TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; IF( Src_p->SrcSpatial_p != NULL ) { - FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) - { - fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); - fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); - } Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); - fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); SrcSpatial_p->q_Pos_p = Q31; } #endif @@ -2348,16 +2327,9 @@ ivas_error ivas_init_decoder_fx( TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; IF(Src_p->SrcSpatial_p != NULL) { - FOR(Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++) - { - fixedToFloat_arrL(Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3); - fixedToFloat_arrL(Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3); - } Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL(SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3); - fixedToFloat_arrL(SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3); SrcSpatial_p->q_Pos_p = Q31; } #endif @@ -2426,16 +2398,9 @@ ivas_error ivas_init_decoder_fx( TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; IF(Src_p->SrcSpatial_p != NULL) { - FOR(Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++) - { - fixedToFloat_arrL(Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3); - fixedToFloat_arrL(Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3); - } Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL(SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3); - fixedToFloat_arrL(SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3); SrcSpatial_p->q_Pos_p = Q31; } #endif @@ -4087,7 +4052,11 @@ void ivas_destroy_dec( /* DirAC handle */ IF ( st_ivas->ivas_format == ISM_FORMAT ) { +#ifdef IVAS_FLOAT_FIXED + ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#else ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); +#endif } ELSE { diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index ce704794f..f016a00e6 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -182,7 +182,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF ( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) && EQ_32( last_ism_mode, ISM_MODE_PARAM ) ) { /* Deallocate the ParamISM struct */ - ivas_param_ism_dec_close( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); + ivas_param_ism_dec_close_fx( &( st_ivas->hParamIsmDec ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); IF ( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { @@ -236,7 +236,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && EQ_32( last_ism_mode, ISM_MODE_DISC ) ) { /* Allocate and initialize the ParamISM struct */ - IF( ( error = ivas_param_ism_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_param_ism_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index a9bcb7f64..1dc4b95bd 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -46,6 +46,7 @@ #include "debug.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* @@ -492,7 +493,11 @@ static void ivas_param_ism_compute_mixing_matrix( } else { +#ifndef IVAS_FLOAT_FIXED direct_power[w] = hParamIsmDec->power_ratios[band_idx][0][w] * ref_power[bin_idx]; +#else + direct_power[w] = fix16_to_float( hParamIsmDec->power_ratios_fx[band_idx][0][w], Q15 ) * ref_power[bin_idx]; +#endif } if ( direct_power[w] != 0.f ) @@ -701,7 +706,7 @@ static void ivas_param_ism_rendering( #ifdef IVAS_FLOAT_FIXED -static ivas_error ivas_param_ism_rendering_init( +static ivas_error ivas_param_ism_rendering_init_fx( PARAM_ISM_RENDERING_HANDLE hParamIsmRendering, IVAS_OUTPUT_SETUP hOutSetup, const Word16 nchan_transport, @@ -720,16 +725,17 @@ static ivas_error ivas_param_ism_rendering_init( #endif /* memory allocation for proto matrix and interpolator */ - if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + IF ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) ); } -#ifdef IVAS_FLOAT_FIXED +#endif IF( ( hParamIsmRendering->proto_matrix_fx = (Word16 *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for proto matrix\n" ) ); } -#endif // IVAS_FLOAT_FIXED + IF( ( hParamIsmRendering->interpolator_fx = (Word16 *) malloc( subframe_nbslots * sizeof( Word16 ) ) ) == NULL ) { @@ -741,15 +747,14 @@ static ivas_error ivas_param_ism_rendering_init( IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { /* computation of proto matrix */ -#ifdef IVAS_FLOAT_FIXED ivas_ism_get_proto_matrix_fx( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix_fx ); - for ( int idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) + +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + FOR ( Word16 idx = 0; idx < hOutSetup.nchan_out_woLFE; idx++ ) { hParamIsmRendering->proto_matrix[idx] = (float) hParamIsmRendering->proto_matrix_fx[idx] / ( 1 << 15 ); hParamIsmRendering->proto_matrix[idx + hOutSetup.nchan_out_woLFE] = (float) hParamIsmRendering->proto_matrix_fx[idx + hOutSetup.nchan_out_woLFE] / ( 1 << 15 ); } -#else - ivas_ism_get_proto_matrix( hOutSetup, nchan_transport, hParamIsmRendering->proto_matrix ); #endif } @@ -871,16 +876,16 @@ static void ivas_param_ism_update_mixing_matrix( * Open Param ISM handle *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_ism_dec_open( +ivas_error ivas_param_ism_dec_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t i; + Word16 i, scale, tmp; PARAM_ISM_DEC_HANDLE hParamIsmDec; IVAS_OUTPUT_SETUP hOutSetup; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; AUDIO_CONFIG output_config; - int32_t output_Fs; + Word32 output_Fs; ivas_error error; error = IVAS_ERR_OK; @@ -891,61 +896,66 @@ ivas_error ivas_param_ism_dec_open( * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) + IF ( ( hParamIsmDec = (PARAM_ISM_DEC_HANDLE) malloc( sizeof( PARAM_ISM_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); } - if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) + IF ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } /* Assign memory to Param Object handle */ - if ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) + IF ( ( hParamIsmDec->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM\n" ) ); } - if ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL ) + IF ( ( hParamIsmDec->hParamIsmRendering = (PARAM_ISM_RENDERING_HANDLE) malloc( sizeof( PARAM_ISM_RENDERING_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ParamISM Rendering handle\n" ) ); } output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); output_config = st_ivas->hDecoderConfig->output_config; -#ifdef IVAS_FLOAT_FIXED - ivas_param_ism_config_fx( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); // assuming Q14 for gains; +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED hParamIsmDec->hParamIsm->last_dmx_gain = 1.0f; set_f(hParamIsmDec->hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS ); -#else - ivas_param_ism_config( hParamIsmDec->hParamIsm, st_ivas->nchan_ism ); #endif /*-----------------------------------------------------------------* * set input parameters *-----------------------------------------------------------------*/ - hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + tmp = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &scale ); // FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + hSpatParamRendCom->slot_size = shr(tmp, 15 - scale); set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; hSpatParamRendCom->subframes_rendered = 0; + move16(); hSpatParamRendCom->slots_rendered = 0; + move16(); + hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + tmp = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &scale ); + hSpatParamRendCom->num_freq_bands = shr(tmp, 15 - scale ); hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; - for ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ ) + FOR ( i = 0; i < ( hParamIsmDec->hParamIsm->nbands + 1 ); i++ ) { hParamIsmDec->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i]; + move16(); - if ( hParamIsmDec->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands ) + IF ( GT_16( hParamIsmDec->hParamIsm->band_grouping[i], hSpatParamRendCom->num_freq_bands ) ) { hParamIsmDec->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands; + move16(); } } @@ -954,123 +964,127 @@ ivas_error ivas_param_ism_dec_open( *-----------------------------------------------------------------*/ /* hIntSetup and hOutSetup differs only for Binaural rendering */ - if ( output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF ( EQ_16( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { /* nchan_out is essential for memory initialization for CLDFB Synthesis */ st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->nchan_ism; + move16(); st_ivas->hIntSetup.is_loudspeaker_setup = 1; } hOutSetup = st_ivas->hIntSetup; - if ( !( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + IF ( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Initialize Param ISM Rendering handle */ - if ( st_ivas->hDecoderConfig->Opt_tsm ) + IF ( st_ivas->hDecoderConfig->Opt_tsm ) { - if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, MAX_JBM_CLDFB_TIMESLOTS, output_config ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { - if ( ( error = ivas_param_ism_rendering_init( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_param_ism_rendering_init_fx( hParamIsmDec->hParamIsmRendering, hOutSetup, st_ivas->nchan_transport, CLDFB_NO_COL_MAX, output_config ) ) != IVAS_ERR_OK ) { return error; } } } - if ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || + test(); test(); test(); test(); test(); + IF ( !( output_config == IVAS_AUDIO_CONFIG_EXTERNAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB || output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) ) { /* Initialize efap handle */ - if ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF ( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), hOutSetup.ls_azimuth_fx, hOutSetup.ls_elevation_fx, hOutSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; } } /* Azi and Ele values are transmitted once per frame per object */ -#ifdef IVAS_FLOAT_FIXED + set32_fx( hParamIsmDec->azimuth_values_fx, 0, MAX_NUM_OBJECTS ); set32_fx( hParamIsmDec->elevation_values_fx, 0, MAX_NUM_OBJECTS ); -#else - set_zero( hParamIsmDec->azimuth_values, MAX_NUM_OBJECTS ); - set_zero( hParamIsmDec->elevation_values, MAX_NUM_OBJECTS ); -#endif hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); hSpatParamRendCom->dirac_bs_md_write_idx = 0; + move16(); hSpatParamRendCom->dirac_read_idx = 0; + move16(); - if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + test(); test(); + IF ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { -#ifdef IVAS_FLOAT_FIXED IF ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) -#endif { return error; } -#ifdef IVAS_FLOAT_FIXED IF ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) -#endif { return error; } } st_ivas->hISMDTX.dtx_flag = 0; + move16(); st_ivas->hParamIsmDec = hParamIsmDec; st_ivas->hSpatParamRendCom = hSpatParamRendCom; - if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) + test(); + IF ( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) { - int16_t nchan_transport = st_ivas->nchan_transport; - int16_t nchan_full = 0; + Word16 nchan_transport = st_ivas->nchan_transport; + move16(); + Word16 nchan_full = 0; + move16(); - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + test(); + IF ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { nchan_full = nchan_transport; +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; -#ifdef IVAS_FLOAT_FIXED +#endif hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; -#endif // IVAS_FLOAT_FIXED } - else + ELSE { - int16_t n_slots_to_alloc; - if ( st_ivas->hDecoderConfig->Opt_tsm == 1 ) + Word16 n_slots_to_alloc; + IF ( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) { n_slots_to_alloc = MAX_JBM_CLDFB_TIMESLOTS; + move16(); } - else + ELSE { n_slots_to_alloc = CLDFB_SLOTS_PER_SUBFRAME * MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); } - if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + IF ( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); - if ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + IF ( ( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } set_zero( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED +#endif + IF( ( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); @@ -1082,38 +1096,30 @@ ivas_error ivas_param_ism_dec_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } set32_fx( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx, 0, n_slots_to_alloc * nchan_transport * hSpatParamRendCom->num_freq_bands ); -#endif // IVAS_FLOAT_FIXED } - if ( st_ivas->hTcBuffer == NULL ) + IF ( st_ivas->hTcBuffer == NULL ) { + IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) -#endif { return error; } } } - else + ELSE { +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; -#ifdef IVAS_FLOAT_FIXED +#endif hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx = NULL; hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx = NULL; -#endif // IVAS_FLOAT_FIXED - if ( st_ivas->hTcBuffer == NULL ) + IF ( st_ivas->hTcBuffer == NULL ) { - int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) -#endif + Word16 nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; + move16(); + IF ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1335,7 +1341,7 @@ ivas_error ivas_param_ism_dec_open( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_close( +void ivas_param_ism_dec_close_fx( PARAM_ISM_DEC_HANDLE *hParamIsmDec_out, /* i/o: decoder DirAC handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ AUDIO_CONFIG output_config /* i : output audio configuration */ @@ -1356,13 +1362,14 @@ void ivas_param_ism_dec_close( IF( !( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { /* Param ISM Rendering */ +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed later: Freeing memory allocated to float pointers IF( hParamIsmDec->hParamIsmRendering->proto_matrix != NULL ) { free( hParamIsmDec->hParamIsmRendering->proto_matrix ); hParamIsmDec->hParamIsmRendering->proto_matrix = NULL; } - //------------------------------------------------------------ +#endif IF( hParamIsmDec->hParamIsmRendering->interpolator_fx != NULL ) { free( hParamIsmDec->hParamIsmRendering->interpolator_fx ); @@ -1374,6 +1381,7 @@ void ivas_param_ism_dec_close( hParamIsmDec->hParamIsmRendering->proto_matrix_fx = NULL; } } +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed later: Freeing memory allocated to float pointers IF( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL ) { @@ -1385,7 +1393,7 @@ void ivas_param_ism_dec_close( free( hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc ); hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; } - //----------------------------------------------------------------- +#endif IF( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx != NULL ) { free( hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx ); @@ -1410,13 +1418,8 @@ void ivas_param_ism_dec_close( { IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { -#ifdef IVAS_FLOAT_FIXED ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 1 ); ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 2 ); -#else - ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); - ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); -#endif } free( *hSpatParamRendCom_out ); @@ -1484,13 +1487,8 @@ void ivas_param_ism_dec_close( { if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 1); - ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 2); -#else ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); -#endif } free( *hSpatParamRendCom_out ); @@ -2047,29 +2045,7 @@ void ivas_param_ism_dec_digest_tc( { #ifdef IVAS_FLOAT_FIXED ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); -#ifndef MSAN_FIX - for ( i = 0; i < 11; i++ ) - { - for ( int j = 0; j < 1; j++ ) - { - for ( int k = 0; k < 2; k++ ) - { - hParamIsmDec->power_ratios_fx[i][j][k] = (Word16) floatToFixed( hParamIsmDec->power_ratios[i][j][k], 15 ); - } - } - } -#endif ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); - for ( i = 0; i < 11; i++ ) - { - for ( int j = 0; j < 1; j++ ) - { - for ( int k = 0; k < 2; k++ ) - { - hParamIsmDec->power_ratios[i][j][k] = fixedToFloat( hParamIsmDec->power_ratios_fx[i][j][k], 15 ); - } - } - } #else ivas_param_ism_dec_dequant_DOA( hParamIsmDec, st_ivas->nchan_ism ); ivas_param_ism_dec_dequant_powrat( hParamIsmDec ); @@ -2862,7 +2838,7 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( Word16 brange[2]; Word16 azimuth[2]; Word16 elevation[2]; - Word16 power_ratio_fx[2]; + Word16 power_ratio_fx[2]; /* Q15 */ Word32 ivas_total_brate; hParamIsmDec = st_ivas->hParamIsmDec; @@ -2890,8 +2866,8 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { IF ( st_ivas->hISMDTX.dtx_flag ) { - Word16 energy_ratio_fx; - energy_ratio_fx = mult( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx, st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx );/*Q15*/ + Word32 energy_ratio_fx; /* Q30 */ + energy_ratio_fx = L_mult0( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx, st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx ); /* Q15 + Q15 -> Q30 */ hSpatParamRendCom->numSimultaneousDirections = 1; move16(); @@ -2945,10 +2921,10 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = power_ratio_fx[0]; + hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[0], Q15 ); hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1]; hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; - hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = power_ratio_fx[1]; + hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = L_shl( power_ratio_fx[1], Q15 ); move16(); move16(); move16(); @@ -2986,7 +2962,7 @@ void ivas_param_ism_params_to_masa_param_mapping_fx( { hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = 32767; + hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = ONE_IN_Q30; /* 1.0f in Q30 */ hSpatParamRendCom->spreadCoherence_fx[sf_idx][bin_idx] = 0; hSpatParamRendCom->surroundingCoherence_fx[sf_idx][bin_idx] = 0; move16(); diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 76a0a6951..2666c13d5 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -100,7 +100,7 @@ ivas_error ivas_jbm_dec_tc_fx( Word32 *data_fx ) { - Word16 n, output_frame, nchan_out, i, j; + Word16 n, output_frame, nchan_out, i; Decoder_State *st; /* used for bitstream handling */ Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* 'float' buffer for output synthesis */ Word16 nchan_remapped; @@ -1176,36 +1176,6 @@ ivas_error ivas_jbm_dec_tc_fx( return error; } - // Fix to float conversion starts here. - IF( st_ivas->hSpatParamRendCom != NULL ) - { - FOR( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - FOR( j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ ) - { - st_ivas->hSpatParamRendCom->energy_ratio1[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j], 30 ); - st_ivas->hSpatParamRendCom->diffuseness_vector[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j], 30 ); - IF( EQ_32( st_ivas->hQMetaData->no_directions, 2 ) ) - { - st_ivas->hSpatParamRendCom->energy_ratio2[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j], 30 ); - } - } - } - } - st_ivas->hMasa->data.dir_decode_quality = fix16_to_float( st_ivas->hMasa->data.dir_decode_quality_fx, Q14 ); - IF( st_ivas->hSpatParamRendCom != NULL ) - { - FOR( i = 0; i < st_ivas->hSpatParamRendCom->numIsmDirections; i++ ) - { - FOR( Word16 block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - FOR( Word16 b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) - { - st_ivas->hMasaIsmData->energy_ratio_ism[i][block][b] = fix_to_float( st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][block][b], Q30 ); - } - } - } - } // Fixed to float conversion ends here. IF( st_ivas->hOutSetup.separateChannelEnabled ) { @@ -2150,55 +2120,14 @@ void ivas_jbm_dec_feed_tc_to_renderer( { if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { - ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots ); -#if 1 /*Float to fix */ - PARAM_ISM_DEC_HANDLE hParamIsmDec; - hParamIsmDec = st_ivas->hParamIsmDec; #ifndef IVAS_FLOAT_FIXED - FOR( i = 0; i < 11; i++ ) - { - FOR( Word16 j = 0; j < 1; j++ ) - { - FOR( Word16 k = 0; k < 2; k++ ) - { - hParamIsmDec->power_ratios_fx[i][j][k] = (Word16) floatToFixed( hParamIsmDec->power_ratios[i][j][k], 15 ); - } - } - } -#endif - // st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = float_to_fix16( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt, 15 ); - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - hSpatParamRendCom = st_ivas->hSpatParamRendCom; - Word16 nBins = hSpatParamRendCom->num_freq_bands; - for ( Word16 sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - for ( Word16 bin_idx = 0; bin_idx < nBins; bin_idx++ ) - { - hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx] = float_to_fix16( hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx], 15 ); - hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx] = float_to_fix16( hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx], 15 ); - } - } -#endif // IVAS_FLOAT_FIXED + ivas_dirac_dec_set_md_map(st_ivas, n_render_timeslots); + + ivas_param_ism_params_to_masa_param_mapping(st_ivas); +#else + ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots ); + ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas ); -#if 1 /*Fix to float*/ - FOR( i = 0; i < 11; i++ ) - { - FOR( Word16 j = 0; j < 1; j++ ) - { - FOR( Word16 k = 0; k < 2; k++ ) - { - hParamIsmDec->power_ratios[i][j][k] = fixedToFloat( hParamIsmDec->power_ratios_fx[i][j][k], 15 ); - } - } - } - for ( Word16 sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ ) - { - for ( Word16 bin_idx = 0; bin_idx < nBins; bin_idx++ ) - { - hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = fixedToFloat( hSpatParamRendCom->energy_ratio1_fx[sf_idx][bin_idx], 15 ); - hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = fixedToFloat( hSpatParamRendCom->energy_ratio2_fx[sf_idx][bin_idx], 15 ); - } - } #endif } else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index d83a1bfb4..424726a4d 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -641,7 +641,7 @@ ivas_error ivas_masa_decode_fx( ivas_format = st_ivas->ivas_format; move32(); - hMasa->data.dir_decode_quality_fx = ONE_IN_Q14; /* Set to default of max quality */ + hMasa->data.dir_decode_quality_fx = MAX16B; /* Set to default of max quality */ /* 1.0f in Q15 */ move16(); hQMetaData->is_masa_ivas_format = 1; @@ -951,7 +951,7 @@ ivas_error ivas_masa_decode_fx( /* Get direction decoding quality. EC 1 and 2 are handled by the default value. */ IF( EQ_16( hQMetaData->ec_flag, 2 ) ) { - hMasa->data.dir_decode_quality_fx = shr( hQMetaData->dir_comp_ratio_fx, 1 ); // Q14 + hMasa->data.dir_decode_quality_fx = hQMetaData->dir_comp_ratio_fx; /* Q15 */ } hMasa->config.coherencePresent = !hQMetaData->all_coherence_zero; @@ -3306,7 +3306,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( Word16 num_q, denom_q, res_q; Word16 headroom_left_max_common = 63; // 0 value Word16 q_max_common = 31; - Word32 ratio_float_fx_Q15, max_ratio_1_Q15; + Word32 ratio_fx; /* Q30 */ FOR( Word16 ind = 0; ind < 6; ind++ ) { FOR( Word16 ind2 = 0; ind2 < 4; ind2++ ) @@ -3603,20 +3603,10 @@ void ivas_spar_param_to_masa_param_mapping_fx( E_fx = GT_32( E_fx, 0 ) ? E_fx : 1; ratio_float_fx = BASOP_Util_Divide3232_Scale( I_fx, E_fx, &res_q ); res_q = sub( res_q, sub( num_q, denom_q ) ); - IF( LT_16( res_q, 0 ) ) - { - ratio_float_fx = L_shr( ratio_float_fx, -1 * res_q ); - res_q = 0; - move16(); - } - ratio_float_fx_Q15 = L_shl( ratio_float_fx, res_q ); - max_ratio_1_Q15 = MAX_WORD16; - move32(); - IF( GT_32( ratio_float_fx_Q15, max_ratio_1_Q15 ) ) - { - ratio_float_fx_Q15 = max_ratio_1_Q15; - move32(); - } + ratio_fx = L_shl_sat( ratio_float_fx, Q15 + res_q ); + + ratio_fx = L_max( 0, L_min( ratio_fx, ONE_IN_Q30 ) ); + azi_val = (Word64) azi_fx * ONE_BY_PI_OVER_180_Q25; IF( LT_64( azi_val, 0 ) ) { @@ -3642,23 +3632,16 @@ void ivas_spar_param_to_masa_param_mapping_fx( move16(); hSpatParamRendCom->elevation[dirac_write_idx][bin] = (Word16) ele_val; move16(); - - hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = L_deposit_h( (Word16) ratio_float_fx_Q15 ); + hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] = ratio_fx; move32(); - hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_deposit_h( sub( 32767, (Word16) ratio_float_fx_Q15 ) ); + hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] = L_sub( ONE_IN_Q30, ratio_fx ); move32(); + hSpatParamRendCom->spreadCoherence_fx[dirac_write_idx][bin] = 0; move16(); hSpatParamRendCom->surroundingCoherence_fx[dirac_write_idx][bin] = 0; move16(); - - // Tobe deleted - hSpatParamRendCom->energy_ratio1[dirac_write_idx][bin] = (float) hSpatParamRendCom->energy_ratio1_fx[dirac_write_idx][bin] / ONE_IN_Q31; - hSpatParamRendCom->diffuseness_vector[dirac_write_idx][bin] = (float) hSpatParamRendCom->diffuseness_vector_fx[dirac_write_idx][bin] / ONE_IN_Q31; - //// - - /* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */ IF( hDiffuseDist != NULL ) { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 04d732ee9..af6a0705f 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -163,9 +163,6 @@ ivas_error ivas_omasa_data_open_fx( set16_fx( hMasaIsmData->elevation_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ ) { - // To be removed later ///////////////////////////////////////////////////////////////////////// - set_zero( hMasaIsmData->energy_ratio_ism[obj_idx][sf], CLDFB_NO_CHANNELS_MAX ); - ///////////////////////////////////////////////////////////////////////////////////////////////// set32_fx( hMasaIsmData->energy_ratio_ism_fx[obj_idx][sf], 0, CLDFB_NO_CHANNELS_MAX ); } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 561335d86..6cae8ac1e 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -1478,16 +1478,9 @@ ivas_error ivas_sba_dec_reconfigure_fx( TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; IF(Src_p->SrcSpatial_p != NULL) { - FOR(Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++) - { - fixedToFloat_arrL(Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3); - fixedToFloat_arrL(Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3); - } Src_p->SrcSpatial_p->q_Pos_p = Q31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL(SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3); - fixedToFloat_arrL(SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3); SrcSpatial_p->q_Pos_p = Q31; } #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index d29f63ceb..e54f30546 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -575,7 +575,6 @@ ivas_error ivas_spar_dec_fx( hDecoderConfig = st_ivas->hDecoderConfig; #ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - Word16 hodirac_flag = ivas_get_hodirac_flag_fx( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); Word16 j, k, d; IF( st_ivas->hQMetaData != NULL ) { @@ -601,21 +600,6 @@ ivas_error ivas_spar_dec_fx( } } } - IF( st_ivas->hDirAC != NULL && st_ivas->hSpatParamRendCom != NULL ) - { - for ( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - for ( j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ ) - { - st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->diffuseness_vector[i][j], 30 ); - st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio1[i][j], 30 ); - IF( hodirac_flag ) - { - st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio2[i][j], 30 ); - } - } - } - } } #endif @@ -698,21 +682,6 @@ ivas_error ivas_spar_dec_fx( } } } - IF( st_ivas->hDirAC != NULL && st_ivas->hSpatParamRendCom != NULL ) - { - for ( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - for ( j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ ) - { - st_ivas->hSpatParamRendCom->diffuseness_vector[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j], 30 ); - st_ivas->hSpatParamRendCom->energy_ratio1[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j], 30 ); - IF( hodirac_flag ) - { - st_ivas->hSpatParamRendCom->energy_ratio2[i][j] = fix_to_float( st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j], 30 ); - } - } - } - } } #endif diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 63c16aa1d..1b05166dc 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -1211,11 +1211,13 @@ static ivas_error ivas_spar_set_dec_config( } #endif + /*-----------------------------------------------------------------------------------------* * Function ivas_dec_mono_sba_handling() * * *-----------------------------------------------------------------------------------------*/ + #ifndef IVAS_FLOAT_FIXED static void ivas_dec_mono_sba_handling( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ @@ -1272,74 +1274,72 @@ static void ivas_dec_mono_sba_handling( } #else static void ivas_dec_mono_sba_handling_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { - Word16 mono_flag, b, block; + Word16 mono_flag, b, block; - mono_flag = 1; + mono_flag = 1; + move16(); - FOR ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) - { - - Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; - Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; - Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; + FOR( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + { + Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + move32(); + Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + move32(); + Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; + move32(); - IF ( - ( NE_32(azimuth_fx, 0) ) || - (NE_32(elevation_fx, 0) ) || - (GT_32(energy_ratio_fx, 161061274) ) ) /* 0.15f is just above the lowest quantised value. */ + test(); + test(); + IF( + ( NE_32( azimuth_fx, 0 ) ) || + ( NE_32( elevation_fx, 0 ) ) || + ( GT_32( energy_ratio_fx, 161061274 /* 0.15f in Q30 */ ) ) ) /* 0.15f is just above the lowest quantised value. */ { mono_flag = 0; + move16(); } } } /* Combine the SPAR prediction coefs flag with the azimuth, elevation and energy ratio flag.*/ - //mono_flag = mono_flag && ivas_spar_chk_zero_coefs( st_ivas ); mono_flag = mono_flag && ivas_spar_chk_zero_coefs_fx( st_ivas ); - if ( mono_flag ) + IF( mono_flag ) { /* Set Energy Ratio values to be zero */ - for ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) + FOR( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) { +#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); - - set32_fx( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio_fx,0, MAX_PARAM_SPATIAL_SUBFRAMES ); - +#endif + set32_fx( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); } - if ( st_ivas->hDirAC != NULL ) + IF( st_ivas->hDirAC != NULL ) { - for ( block = 0; block < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; ++block ) + FOR( block = 0; block < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; ++block ) { /* Set directional Energy Ratio values to be zero */ - set_zero( st_ivas->hSpatParamRendCom->energy_ratio1[block], st_ivas->hSpatParamRendCom->num_freq_bands ); - - set32_fx( st_ivas->hSpatParamRendCom->energy_ratio1_fx[block],0, st_ivas->hSpatParamRendCom->num_freq_bands ); - - if ( st_ivas->hQMetaData->no_directions == 2 ) + set32_fx( st_ivas->hSpatParamRendCom->energy_ratio1_fx[block], 0, st_ivas->hSpatParamRendCom->num_freq_bands ); + IF( EQ_32( st_ivas->hQMetaData->no_directions, 2 ) ) { - set_zero( st_ivas->hSpatParamRendCom->energy_ratio2[block], st_ivas->hSpatParamRendCom->num_freq_bands ); - - set32_fx( st_ivas->hSpatParamRendCom->energy_ratio2_fx[block],0, st_ivas->hSpatParamRendCom->num_freq_bands ); - + set32_fx( st_ivas->hSpatParamRendCom->energy_ratio2_fx[block], 0, st_ivas->hSpatParamRendCom->num_freq_bands ); } /* Set Diffuseness values to be 1.0 */ - set_f( st_ivas->hSpatParamRendCom->diffuseness_vector[block], 1.0f, st_ivas->hSpatParamRendCom->num_freq_bands ); - set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); - } } } return; } -#endif +#endif + + #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_spar_md_dec_process_fx() @@ -5160,32 +5160,29 @@ void ivas_spar_to_dirac_fx( for (b = qmf_band_start; b < qmf_band_end; b++) { - azi_dith = azi[band]; - ele_dith = ele[band]; + azi_dith = azi[band]; + ele_dith = ele[band]; - hSpatParamRendCom->energy_ratio1[block][b] = en_ratio_fx / ((float)ONE_IN_Q30); - hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; - tmp_write_idx_band = tmp_write_idx_param_band; + hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; + tmp_write_idx_band = tmp_write_idx_param_band; if (hDirAC->hConfig->dec_param_estim == FALSE) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; - hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness_fx[band] / ((float)ONE_IN_Q30); + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; } else { for (ts = ts_start; ts < ts_end; ts++) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; - hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness_fx[band] / ((float)ONE_IN_Q30); + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; tmp_write_idx_band = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 04f2452d7..ca390f894 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -726,12 +726,12 @@ typedef struct ivas_param_ism_dec_data_structure #ifndef IVAS_FLOAT_FIXED float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; -#else - Word32 azimuth_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; /* Q22 */ - Word32 elevation_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; /* Q22 */ - Word16 power_ratios_fx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; -#endif // IVAS_FLOAT_FIXED float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; +#else + Word32 azimuth_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; /* Q22 */ + Word32 elevation_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; /* Q22 */ + Word16 power_ratios_fx[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; /* Q15 */ +#endif /*sub-modules*/ PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM common handle */ @@ -1334,9 +1334,10 @@ typedef struct ivas_masa_decoder_data_struct SPHERICAL_GRID_DATA *sph_grid16; MASA_DECODER_EXT_OUT_META *extOutMeta; +#ifndef IVAS_FLOAT_FIXED float dir_decode_quality; -#ifdef IVAS_FLOAT_FIXED - Word16 dir_decode_quality_fx; // Q14 +#else + Word16 dir_decode_quality_fx; /* Q15 */ #endif } MASA_DECODER_DATA; @@ -1354,15 +1355,14 @@ typedef struct ivas_masa_ism_data_structure { int16_t azimuth_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; int16_t elevation_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; - float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; -#ifdef IVAS_FLOAT_FIXED - Word32 energy_ratio_ism_fx[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; /* Q30 */ -#endif #ifndef IVAS_FLOAT_FIXED + float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; #else - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ + Word32 energy_ratio_ism_fx[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; /* Q30 */ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ #endif + int16_t azimuth_ism_edited[MAX_NUM_OBJECTS]; int16_t elevation_ism_edited[MAX_NUM_OBJECTS]; uint8_t ism_is_edited[MAX_NUM_OBJECTS]; @@ -1375,14 +1375,14 @@ typedef struct ivas_masa_ism_data_structure float q_azimuth_old[MAX_NUM_OBJECTS]; float q_elevation_old[MAX_NUM_OBJECTS]; #else - Word32 q_azimuth_old_fx[MAX_NUM_OBJECTS]; /* Q22 */ - Word32 q_elevation_old_fx[MAX_NUM_OBJECTS]; /* Q22 */ + Word32 q_azimuth_old_fx[MAX_NUM_OBJECTS]; /* Q22 */ + Word32 q_elevation_old_fx[MAX_NUM_OBJECTS]; /* Q22 */ #endif #ifndef IVAS_FLOAT_FIXED float ismPreprocMatrix[2][2][CLDFB_NO_CHANNELS_MAX]; #else - Word16 ismPreprocMatrix_fx[2][2][CLDFB_NO_CHANNELS_MAX]; /* Q15 */ + Word16 ismPreprocMatrix_fx[2][2][CLDFB_NO_CHANNELS_MAX]; /* Q15 */ #endif uint8_t objectsMoved; #ifndef IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index c103dff09..e2e0c238c 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -689,6 +689,7 @@ static void stereo_dft_generate_comfort_noise_fx( Word16 *ptr_q_shb; Word16 dmpf[M + 2], Atmp[M + 2]; Word32 cngNoiseLevel_upd[L_FRAME16k], cngNoiseLevel_hist[L_FRAME16k - 2]; + Word16 q_cng_temp[L_FRAME16k]; Word32 *ptr_tmp, *ptr_cng; Word32 E0, E1; Word16 b, q_cngNoiseLevel_upd, q_cngNoiseLevel; @@ -705,7 +706,7 @@ static void stereo_dft_generate_comfort_noise_fx( const Word16 *pTrigo; Word16 trigo_step; Word16 addl_guard_bits; - + Word16 max_diff; /* * The additional guard bits data is added to tackle very small shb_cng_gain_fx_32. * One additional guard bit is added for every 6dB post -12dB. @@ -916,6 +917,8 @@ static void stereo_dft_generate_comfort_noise_fx( // by adjusting q_inv_sqrt. minimum_abs32_fx( ptr0, st->L_frame, &min_val ); //q_inv_sqrt = sub( sub( Q31, norm_l( L_abs( min_val ) ) ), add( q_div, 1 ) ); + + /* cngNoiseLevel_upd buffer has Q of ( Q30 - rshift_cng )*/ FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) { //if ((*ptr1 == 0) && (*ptr2 == 0)) @@ -938,13 +941,47 @@ static void stereo_dft_generate_comfort_noise_fx( } tmp = ISqrt32(ftmp, &q_sqrt); tmp = Mpy_32_16_1(tmp, factor); - tmp = L_shl(tmp, add(sub(sub(Q30, rshift_cng), sub(Q31, q_sqrt)), add(q_div, 1))); - *ptr0++ = tmp; move32(); + q_cng_temp[i] = sub( add( sub( Q31, q_sqrt ), sub( Q15, add( q_div, 1 ) ) ), Q15 ); + *ptr0++ = tmp; + move32(); ptr1 += 2; ptr2 += 2; } - // q_div + 1 has to be added back to q_inv_sqrt. - q_cngNoiseLevel_upd = sub(Q30, rshift_cng); + + /* The initial values in the cngNoiseLevel_upd buffer, from index 0 to st->L_frame / 2 - 1, are updated in the for loop above, + with their Q factors stored in q_cng_temp. The values stored after index st->L_frame / 2 - 1 have a Q factor of (Q30 - rshift_cng). + + Calculate the maximum difference between (Q30 - rshift_cng) and the headroom available for the values stored in cngNoiseLevel_upd + for the initial st->L_frame / 2 - 1 value that were updated in the above for loop. + - If the maximum difference is negative, the cngNoiseLevel_upd buffer has enough headroom to accommodate all the values + with a Q factor of (Q30 - rshift_cng). + + - If the maximum difference is positive, some values in the cngNoiseLevel_upd buffer may overflow with a Q factor of + (Q30 - rshift_cng). In this case, scale the cngNoiseLevel_upd buffer to a Q factor of (Q30 - rshift_cng - max_diff) + to prevent overflows. */ + + max_diff = sub( sub( sub( Q30, rshift_cng ), q_cng_temp[0] ), norm_l( cngNoiseLevel_upd[0] ) ); + FOR( i = 1; i < shr( st->L_frame, 1 ) - 1; i++ ) + { + max_diff = s_max( max_diff, sub( sub( sub( Q30, rshift_cng ), q_cng_temp[i] ), norm_l( cngNoiseLevel_upd[i] ) ) ); + } + IF( LT_16( max_diff, 0 ) ) + { + FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) + { + cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( sub( Q30, rshift_cng ), q_cng_temp[i] ) ); + } + q_cngNoiseLevel_upd = sub( Q30, rshift_cng ); + } + ELSE + { + FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) + { + cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( sub( sub( Q30, rshift_cng ), q_cng_temp[i] ), max_diff ) ); + } + scale_sig32( cngNoiseLevel_upd + shr( st->L_frame, 1 ) - 1, shr( st->L_frame, 1 ) + 1, -max_diff ); + q_cngNoiseLevel_upd = sub( sub( Q30, rshift_cng ), max_diff ); + } IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) { diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 69c5ddb67..95a3d4a25 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1307,40 +1307,6 @@ static ivas_error IVAS_DEC_GetTcSamples( hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ - IF((st_ivas->ivas_format == MASA_FORMAT && st_ivas->hQMetaData != NULL) || (st_ivas->ivas_format == MASA_ISM_FORMAT)) - { - // Fix to float conversion starts here. - IF(st_ivas->hSpatParamRendCom != NULL) - { - FOR(Word16 i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++) - { - FOR(Word16 j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++) - { - st_ivas->hSpatParamRendCom->energy_ratio1[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j], 30); - st_ivas->hSpatParamRendCom->diffuseness_vector[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j], 30); - IF(EQ_32(st_ivas->hQMetaData->no_directions, 2)) - { - st_ivas->hSpatParamRendCom->energy_ratio2[i][j] = fix_to_float(st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j], 30); - } - } - } - } - st_ivas->hMasa->data.dir_decode_quality = fix16_to_float(st_ivas->hMasa->data.dir_decode_quality_fx, Q14); - IF(st_ivas->hSpatParamRendCom != NULL) - { - FOR(Word16 i = 0; i < st_ivas->hSpatParamRendCom->numIsmDirections; i++) - { - FOR(Word16 block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) - { - FOR(Word16 b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++) - { - st_ivas->hMasaIsmData->energy_ratio_ism[i][block][b] = fix_to_float(st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][block][b], Q30); - } - } - } - } - } - IF(((st_ivas->mc_mode == MC_MODE_PARAMUPMIX) || (st_ivas->mc_mode == MC_MODE_MCT) || st_ivas->ivas_format == SBA_ISM_FORMAT || (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT) || st_ivas->mc_mode == MC_MODE_PARAMMC) && (GT_16(st_ivas->nCPE, 1))) { FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) { diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 0b9a5447d..037435a67 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -104,9 +104,10 @@ typedef struct parambin_rend_config_data MC_MODE mc_mode; int32_t ivas_total_brate; int16_t nchan_transport; +#ifndef IVAS_FLOAT_FIXED float qualityBasedSmFactor; -#ifdef IVAS_FLOAT_FIXED - Word32 qualityBasedSmFactor_fx; +#else + Word32 qualityBasedSmFactor_fx; /* Q31 */ #endif int16_t processReverb; ISM_MODE ism_mode; @@ -158,16 +159,16 @@ static void formulate2x2MixingMatrix( float Ein1, float Ein2, float CinRe, float #ifdef IVAS_FLOAT_FIXED static void hrtfShGetHrtf_fx( const Word16 bin, const Word16 aziDeg, const Word16 eleDeg, Word32 *lRealp, Word32 *lImagp, Word32 *rRealp, Word32 *rImagp, PARAMBIN_HRTF_GAIN_CACHE *gainCache, const Word16 useCachedValue ); -#endif +#else static void hrtfShGetHrtf( const int16_t bin, const int16_t aziDeg, const int16_t eleDeg, float *lRealp, float *lImagp, float *rRealp, float *rImagp, PARAMBIN_HRTF_GAIN_CACHE *gainCache, const int16_t useCachedValue ); - +#endif #ifdef IVAS_FLOAT_FIXED static void getDirectPartGains_fx( const Word16 bin, Word16 aziDeg, Word16 eleDeg, Word32 *lRealp, Word32 *lImagp, Word32 *rRealp, Word32 *rImagp, const UWord8 renderStereoOutputInsteadOfBinaural, Word32 Rmat[3][3], PARAMBIN_HRTF_GAIN_CACHE *gainCache, const Word16 isHeadtracked ); -#endif +#else static void getDirectPartGains( const int16_t bin, int16_t aziDeg, int16_t eleDeg, float *lRealp, float *lImagp, float *rRealp, float *rImagp, const uint8_t stereoMode, float Rmat[3][3], PARAMBIN_HRTF_GAIN_CACHE *gainCache, const int16_t isHeadtracked ); - +#endif static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); @@ -1184,10 +1185,6 @@ static void ivas_dirac_dec_binaural_internal( q_cldfb[ind][ind2] = q_input; } } - IF(st_ivas->hMasa) - { - st_ivas->hMasa->data.dir_decode_quality_fx = float_to_fix16(st_ivas->hMasa->data.dir_decode_quality, 14); - } #endif DIRAC_DEC_BIN_HANDLE hDiracDecBin; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -1216,8 +1213,7 @@ static void ivas_dirac_dec_binaural_internal( move32(); config_data.nchan_transport = st_ivas->nchan_transport; move16(); - config_data.qualityBasedSmFactor = st_ivas->hMasa != NULL ? st_ivas->hMasa->data.dir_decode_quality : 1.0f; - config_data.qualityBasedSmFactor_fx = st_ivas->hMasa != NULL ? L_shl_sat(st_ivas->hMasa->data.dir_decode_quality_fx, 17) : ONE_IN_Q31; + config_data.qualityBasedSmFactor_fx = st_ivas->hMasa != NULL ? L_deposit_h( st_ivas->hMasa->data.dir_decode_quality_fx ) : ONE_IN_Q31; move32(); config_data.processReverb = st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0; move16(); @@ -1442,21 +1438,6 @@ static void ivas_dirac_dec_binaural_internal( f2me( hDiracDecBin->ChEneOutPrev[i][j], &hDiracDecBin->ChEneOutPrev_fx[i][j], &hDiracDecBin->ChEneOutPrev_e[i][j] ); } } - FOR( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - IF( hSpatParamRendCom->energy_ratio1 ) - floatToFixed_arrL32( hSpatParamRendCom->energy_ratio1[i], hSpatParamRendCom->energy_ratio1_fx[i], Q30, hSpatParamRendCom->num_freq_bands ); - IF( hSpatParamRendCom->energy_ratio2 ) - floatToFixed_arrL32( hSpatParamRendCom->energy_ratio2[i], hSpatParamRendCom->energy_ratio2_fx[i], Q30, hSpatParamRendCom->num_freq_bands ); - } - IF( st_ivas->hMasaIsmData ) - FOR( i = 0; i < 4; i++ ) - { - FOR( j = 0; j < 6; j++ ) - { - floatToFixed_arrL32( st_ivas->hMasaIsmData->energy_ratio_ism[i][j], st_ivas->hMasaIsmData->energy_ratio_ism_fx[i][j], Q30, 60 ); - } - } floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherence, hDiracDecBin->diffuseFieldCoherence_fx, 31, hSpatParamRendCom->num_freq_bands ); IF( hDiracDecBin->hDiffuseDist ) { @@ -3059,9 +3040,22 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; } +#ifdef IVAS_FLOAT_FIXED + Word32 Rmat_fx[3][3], lRealp_fx, lImagp_fx, rRealp_fx, rImagp_fx; + for ( int p = 0; p < 3; p++ ) + { + floatToFixed_arrL( Rmat[p], Rmat_fx[p], Q30, 3 ); + } - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); + getDirectPartGains_fx( bin, aziDeg, eleDeg, &lRealp_fx, &lImagp_fx, &rRealp_fx, &rImagp_fx, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat_fx, &gainCache[chB], isHeadtracked ); + lRealp = fixedToFloat_32( lRealp_fx, Q28 ); + lImagp = fixedToFloat_32( lImagp_fx, Q28 ); + rRealp = fixedToFloat_32( rRealp_fx, Q28 ); + rImagp = fixedToFloat_32( rImagp_fx, Q28 ); +#else + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); +#endif hDiracDecBin->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; hDiracDecBin->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; hDiracDecBin->processMtxRe[1][chB + 2][bin] = rRealp * gainFactor; @@ -4732,7 +4726,7 @@ static void getDirectPartGains_fx( return; } -#endif +#else static void getDirectPartGains( const int16_t bin, @@ -4806,7 +4800,7 @@ static void getDirectPartGains( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void hrtfShGetHrtf_fx( @@ -4865,7 +4859,7 @@ static void hrtfShGetHrtf_fx( return; } -#endif +#else static void hrtfShGetHrtf( const int16_t bin, @@ -4920,7 +4914,7 @@ static void hrtfShGetHrtf( return; } - +#endif /*------------------------------------------------------------------------- * configure_reqularization_factor() @@ -5784,13 +5778,6 @@ static void ivas_masa_ext_rend_parambin_internal( f2me( hDiracDecBin->ChEneOutPrev[i][j], &hDiracDecBin->ChEneOutPrev_fx[i][j], &hDiracDecBin->ChEneOutPrev_e[i][j] ); } } - FOR( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - IF( hSpatParamRendCom->energy_ratio1 ) - floatToFixed_arrL32( hSpatParamRendCom->energy_ratio1[i], hSpatParamRendCom->energy_ratio1_fx[i], Q30, hSpatParamRendCom->num_freq_bands ); - IF( hSpatParamRendCom->energy_ratio2 ) - floatToFixed_arrL32( hSpatParamRendCom->energy_ratio2[i], hSpatParamRendCom->energy_ratio2_fx[i], Q30, hSpatParamRendCom->num_freq_bands ); - } floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherence, hDiracDecBin->diffuseFieldCoherence_fx, 31, hSpatParamRendCom->num_freq_bands ); IF( hDiracDecBin->hDiffuseDist ) { @@ -5825,7 +5812,6 @@ static void ivas_masa_ext_rend_parambin_internal( move32(); config_data.nchan_transport = hMasaExtRend->nchan_input; move16(); - config_data.qualityBasedSmFactor = 1.0f; config_data.qualityBasedSmFactor_fx = ONE_IN_Q31; move32(); config_data.processReverb = hMasaExtRend->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0; diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 3210d47e7..accca0e5b 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -187,174 +187,132 @@ ivas_error ivas_dirac_allocate_parameters( #else ivas_error ivas_dirac_allocate_parameters_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ - const Word16 params_flag /* i : set of parameters flag */ + const Word16 params_flag /* i : set of parameters flag */ ) { Word16 i; - IF ( params_flag == 1 ) + IF( EQ_16( params_flag, 1 ) ) { - IF ( ( hSpatParamRendCom->azimuth = ( Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->azimuth = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->elevation = ( Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->elevation = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->diffuseness_vector = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->diffuseness_vector_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - - IF ( ( hSpatParamRendCom->energy_ratio1 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - -#ifdef IVAS_FLOAT_FIXED - IF ( ( hSpatParamRendCom->diffuseness_vector_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->energy_ratio1_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->energy_ratio1_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - IF ( ( hSpatParamRendCom->spreadCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->spreadCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->surroundingCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->surroundingCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } -#endif - FOR ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) + FOR( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) { - IF ( ( hSpatParamRendCom->azimuth[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_s( hSpatParamRendCom->azimuth[i], 0, hSpatParamRendCom->num_freq_bands ); - - IF ( ( hSpatParamRendCom->elevation[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_s( hSpatParamRendCom->elevation[i], 0, hSpatParamRendCom->num_freq_bands ); - - IF ( ( hSpatParamRendCom->diffuseness_vector[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + IF( ( hSpatParamRendCom->azimuth[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_f( hSpatParamRendCom->diffuseness_vector[i], 1.0f, hSpatParamRendCom->num_freq_bands ); + set16_fx( hSpatParamRendCom->azimuth[i], 0, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->energy_ratio1[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + IF( ( hSpatParamRendCom->elevation[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_f( hSpatParamRendCom->energy_ratio1[i], 0.0f, hSpatParamRendCom->num_freq_bands ); + set16_fx( hSpatParamRendCom->elevation[i], 0, hSpatParamRendCom->num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED - IF ( ( hSpatParamRendCom->diffuseness_vector_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hSpatParamRendCom->diffuseness_vector_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hSpatParamRendCom->energy_ratio1_fx[i], 0, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->spreadCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) + IF( ( hSpatParamRendCom->spreadCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set16_fx( hSpatParamRendCom->spreadCoherence_fx[i], 0, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->surroundingCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) + IF( ( hSpatParamRendCom->surroundingCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set16_fx( hSpatParamRendCom->surroundingCoherence_fx[i], 0, hSpatParamRendCom->num_freq_bands ); -#endif } } - ELSE IF ( params_flag == 2 ) + ELSE IF( EQ_16( params_flag, 2 ) ) { - IF ( ( hSpatParamRendCom->azimuth2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof(Word16 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->azimuth2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->elevation2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof(Word16 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->elevation2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->energy_ratio2 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->energy_ratio2_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - IF ( ( hSpatParamRendCom->energy_ratio2_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL ) + IF( ( hSpatParamRendCom->spreadCoherence2_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - IF ( ( hSpatParamRendCom->spreadCoherence2_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL ) + FOR( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } -#endif - - FOR ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - IF ( ( hSpatParamRendCom->azimuth2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == NULL ) + IF( ( hSpatParamRendCom->azimuth2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_s( hSpatParamRendCom->azimuth2[i], 0, hSpatParamRendCom->num_freq_bands ); + set16_fx( hSpatParamRendCom->azimuth2[i], 0, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->elevation2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof(Word16) ) ) == NULL ) + IF( ( hSpatParamRendCom->elevation2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_s( hSpatParamRendCom->elevation2[i], 0, hSpatParamRendCom->num_freq_bands ); + set16_fx( hSpatParamRendCom->elevation2[i], 0, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->energy_ratio2[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hSpatParamRendCom->energy_ratio2[i], 0.0f, hSpatParamRendCom->num_freq_bands ); - -#ifdef IVAS_FLOAT_FIXED - IF ( ( hSpatParamRendCom->energy_ratio2_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hSpatParamRendCom->energy_ratio2_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hSpatParamRendCom->energy_ratio2_fx[i], 0, hSpatParamRendCom->num_freq_bands ); - IF ( ( hSpatParamRendCom->spreadCoherence2_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) + IF( ( hSpatParamRendCom->spreadCoherence2_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set16_fx( hSpatParamRendCom->spreadCoherence2_fx[i], 0, hSpatParamRendCom->num_freq_bands ); -#endif } } return IVAS_ERR_OK; } - #endif @@ -507,8 +465,6 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( hSpatParamRendCom->elevation2 = NULL; hSpatParamRendCom->energy_ratio2_fx = NULL; hSpatParamRendCom->spreadCoherence2_fx = NULL; - /*TODO: to remove float*/ - hSpatParamRendCom->energy_ratio2 = NULL; } } @@ -981,20 +937,6 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->elevation = NULL; } - if (hSpatParamRendCom->energy_ratio1 != NULL) - { - for (i = 0; i < md_buffer_length; i++) - { - if (hSpatParamRendCom->energy_ratio1[i] != NULL) - { - free(hSpatParamRendCom->energy_ratio1[i]); - hSpatParamRendCom->energy_ratio1[i] = NULL; - } - } - free(hSpatParamRendCom->energy_ratio1); - hSpatParamRendCom->energy_ratio1 = NULL; - } - if (hSpatParamRendCom->energy_ratio1_fx != NULL) { for (i = 0; i < md_buffer_length; i++) @@ -1009,21 +951,6 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->energy_ratio1_fx = NULL; } - if (hSpatParamRendCom->diffuseness_vector != NULL) - { - for (i = 0; i < md_buffer_length; i++) - { - if (hSpatParamRendCom->diffuseness_vector[i] != NULL) - { - free(hSpatParamRendCom->diffuseness_vector[i]); - hSpatParamRendCom->diffuseness_vector[i] = NULL; - } - } - - free(hSpatParamRendCom->diffuseness_vector); - hSpatParamRendCom->diffuseness_vector = NULL; - } - if (hSpatParamRendCom->diffuseness_vector_fx != NULL) { for (i = 0; i < md_buffer_length; i++) @@ -1097,20 +1024,6 @@ void ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom->elevation2 = NULL; } - if (hSpatParamRendCom->energy_ratio2 != NULL) - { - for (i = 0; i < md_buffer_length; i++) - { - if (hSpatParamRendCom->energy_ratio2[i] != NULL) - { - free(hSpatParamRendCom->energy_ratio2[i]); - hSpatParamRendCom->energy_ratio2[i] = NULL; - } - } - free(hSpatParamRendCom->energy_ratio2); - hSpatParamRendCom->energy_ratio2 = NULL; - } - if (hSpatParamRendCom->energy_ratio2_fx != NULL) { for (i = 0; i < md_buffer_length; i++) @@ -4532,10 +4445,6 @@ void ivas_masa_init_stereotype_detection_fx( stereo_type_detect->subtract_power_y_smooth = 0.0f; stereo_type_detect->target_power_y_smooth = 0.0f; - stereo_type_detect->lr_total_bb_ratio_db = 0.0f; - stereo_type_detect->lr_total_hi_ratio_db = 0.0f; - stereo_type_detect->min_sum_total_ratio_db = 0.0f; - stereo_type_detect->subtract_target_ratio_db = 0.0f; /*--------------------------------------------*/ stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index a37504cb9..e205df6e0 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -64,8 +64,6 @@ static void TDREND_Clear_Update_flags_fx( #endif // IVAS_FLOAT_FIXED -static void angles_to_vec( const float radius, const float azimuth, const float elevation, float *vec ); - #ifdef IVAS_FLOAT_FIXED static void angles_to_vec_fx( const Word16 radius, /* i : radius */ @@ -73,6 +71,8 @@ static void angles_to_vec_fx( const Word32 elevation, /* i : Elevation angle */ Word32 *vec /* o : Pos/Dir vector */ ); +#else +static void angles_to_vec(const float radius, const float azimuth, const float elevation, float *vec); #endif /*---------------------------------------------------------------------* @@ -584,7 +584,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( { enableCombinedOrientation = hCombinedOrientationData->enableCombinedOrientation; Quaternions = hCombinedOrientationData->Quaternions; - Pos = hCombinedOrientationData->listenerPos; + Pos = hCombinedOrientationData->listenerPos; move16(); } FOR(ch = 0; ch < BINAURAL_CHANNELS; ch++) @@ -592,23 +592,23 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( p_reverb_signal_fx[ch] = reverb_signal_fx[ch]; } - subframe_length = output_frame / num_subframes; + subframe_length = idiv1616(output_frame, num_subframes); - c_indx = 0; + c_indx = 0; move16(); FOR(nS = 0; nS < num_src; nS++) { IF(!(ivas_format == MC_FORMAT && nS == lfe_idx)) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = output_fx[nS]; - hBinRendererTd->Sources[c_indx]->InputFrame_p_q = Q7; - hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; + hBinRendererTd->Sources[c_indx]->InputFrame_p_q = Q11; move16(); + hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; move16(); c_indx = add(c_indx, 1); } } FOR(subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++) { - IF(subframe_idx == ism_md_subframe_update) + IF(EQ_16(subframe_idx, ism_md_subframe_update)) { /* Update object position(s) */ IF((error = TDREND_Update_object_positions_fx(hBinRendererTd, num_src, ivas_format, hIsmMetaData)) != IVAS_ERR_OK) @@ -619,11 +619,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( /* Update the listener's location/orientation */ Word16 tmp_headRotEnabled; - - tmp_headRotEnabled = 0; - move16(); - - + tmp_headRotEnabled = 0; move16(); IF(enableCombinedOrientation != NULL) { tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; @@ -637,51 +633,26 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( IF(hReverb != NULL) { - Word16 i, j; - Word32 pcm_in_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 pcm_out_buff[BINAURAL_CHANNELS][L_FRAME48k]; - Word32 *pcm_in_fx[MAX_OUTPUT_CHANNELS]; - Word32 *pcm_out_fx[BINAURAL_CHANNELS]; - Word16 nchan_transport = audioCfg2channels(transport_config); - //exp = Q7; - move16(); - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - pcm_in_fx[i] = pcm_in_buff[i]; - } - FOR(i = 0; i < nchan_transport; i++) - { - - FOR(j = 0; j < ((subframe_idx + 1) * hReverb->full_block_size); j++) - { + Word16 i; - pcm_in_fx[i][j] = output_fx[i][j]; - } - } - FOR(i = 0; i < BINAURAL_CHANNELS; i++) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - pcm_out_fx[i] = pcm_out_buff[i]; + Scale_sig32(output_fx[i], L_FRAME48k, -4); } - FOR(i = 0; i < BINAURAL_CHANNELS; i++) - { - FOR(j = 0; j < (hReverb->full_block_size); j++) - { - pcm_out_fx[i][j] = p_reverb_signal_fx[i][j]; - } - } - IF((error = ivas_reverb_process_fx(hReverb, transport_config, 0, pcm_in_fx, pcm_out_fx, subframe_idx)) != IVAS_ERR_OK) + IF((error = ivas_reverb_process_fx(hReverb, transport_config, 0, output_fx, p_reverb_signal_fx, subframe_idx)) != IVAS_ERR_OK) { return error; } - FOR(i = 0; i < BINAURAL_CHANNELS; i++) - { - FOR(j = 0; j < (hReverb->full_block_size); j++) - { + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(output_fx[i], L_FRAME48k, 4); + } - p_reverb_signal_fx[i][subframe_idx * hReverb->full_block_size + j] = L_shl(pcm_out_fx[i][subframe_idx * hReverb->full_block_size + j], 2); - } + FOR( i = 0; i < BINAURAL_CHANNELS; ++i ) + { + Scale_sig32(p_reverb_signal_fx[i] + subframe_idx * hReverb->full_block_size, hReverb->full_block_size, 2); } } @@ -693,8 +664,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( /* Advance subframe pointer */ - c_indx = 0; - move16(); + c_indx = 0; move16(); FOR(nS = 0; nS < num_src; nS++) { IF(!(ivas_format == MC_FORMAT && nS == lfe_idx)) /* Skip LFE for MC */ @@ -794,10 +764,27 @@ ivas_error ivas_td_binaural_renderer_unwrap( if ( subframe_idx == ism_md_subframe_update ) { /* Update object position(s) */ +#ifdef IVAS_FLOAT_FIXED + FOR( Word16 i = 0; i < num_src; i++ ) + { + FOR( int j = 0; j < 3; j++ ) + { + IF( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == SBA_ISM_FORMAT ) + hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = L_shr( hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j], hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p - Q25 ); + } + IF( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == SBA_ISM_FORMAT ) + hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p = 25; + } + IF ( ( error = TDREND_Update_object_positions_fx( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = TDREND_Update_object_positions( hBinRendererTd, num_src, ivas_format, hIsmMetaData ) ) != IVAS_ERR_OK ) { return error; } +#endif // IVAS_FLOAT_FIXED } /* Update the listener's location/orientation */ @@ -908,9 +895,8 @@ ivas_error ivas_td_binaural_renderer_unwrap( { FOR( int j = 0; j < 3; j++ ) { - hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = float_to_fix( hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p[j], Q25 ); - //hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = L_shr( hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j], hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p - Q25 ); + hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = L_shr( hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j], hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p - Q25 ); } hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p = 25; } @@ -1184,6 +1170,10 @@ ivas_error TDREND_Update_object_positions_fx( angles_to_vec_fx( hIsmMetaData[nS]->radius_fx /*Q9*/, hIsmMetaData[nS]->azimuth_fx, hIsmMetaData[nS]->elevation_fx, Pos_fx ); angles_to_vec_fx( ONE_IN_Q14, hIsmMetaData[nS]->yaw_fx, hIsmMetaData[nS]->pitch_fx, Dir_fx ); + DirAtten_p->ConeInnerAngle_fx = DEG_360_IN_Q22; + DirAtten_p->ConeOuterAngle_fx = DEG_360_IN_Q22; + DirAtten_p->ConeOuterGain_fx = ONE_IN_Q30; + IF ( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) { return error; @@ -1222,8 +1212,7 @@ ivas_error TDREND_Update_object_positions_fx( return IVAS_ERR_OK; } -#endif - +#else /*---------------------------------------------------------------------* * TDREND_Update_object_positions() * @@ -1297,6 +1286,7 @@ ivas_error TDREND_Update_object_positions( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* * TDREND_Update_listener_orientation() @@ -1571,7 +1561,7 @@ ivas_error ivas_td_binaural_renderer_ext_fx( const Word32 output_Fs, /* i : output sampling rate */ const Word16 output_frame, /* i : output frame length */ Word32 output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ - Word16 exp + Word16 *exp ) { ISM_METADATA_FRAME hIsmMetaDataFrame; @@ -1582,35 +1572,24 @@ ivas_error ivas_td_binaural_renderer_ext_fx( IVAS_REND_AudioConfigType inConfigType; AUDIO_CONFIG transport_config; ivas_error error; -#if 1 - float *p_output[MAX_OUTPUT_CHANNELS]; - float output_fl[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word16 ch,j; - /*This intermediate conversion will be removed once the subfunctions are also converted to fixed*/ - for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) - { - for ( j = 0; j < L_FRAME48k ;j++) - { - output_fl[ch][j] = (float)output[ch][j]/(1<azimuth_fx = currentPos->azimuth_fx; - hIsmMetaData[0]->elevation_fx = currentPos->elevation_fx; -#endif // IVAS_FLOAT_FIXED - hIsmMetaData[0]->azimuth = currentPos->azimuth; - hIsmMetaData[0]->elevation = currentPos->elevation; - hIsmMetaData[0]->yaw = currentPos->yaw; - hIsmMetaData[0]->pitch = currentPos->pitch; - hIsmMetaData[0]->radius = currentPos->radius; - hIsmMetaData[0]->non_diegetic_flag = currentPos->non_diegetic_flag; + ivas_format = ISM_FORMAT;move16(); + num_src = 1; move16(); + transport_config = IVAS_AUDIO_CONFIG_ISM1; move16(); + hIsmMetaData[0] = &hIsmMetaDataFrame; move16(); + hIsmMetaData[0]->azimuth_fx = currentPos->azimuth_fx; move32(); + hIsmMetaData[0]->elevation_fx = currentPos->elevation_fx; move32(); + hIsmMetaData[0]->yaw_fx = currentPos->yaw_fx; move32(); + hIsmMetaData[0]->pitch_fx = currentPos->pitch_fx; move32(); + hIsmMetaData[0]->radius_fx = currentPos->radius_fx; move32(); + hIsmMetaData[0]->non_diegetic_flag = currentPos->non_diegetic_flag; move16(); } -#ifdef IVAS_FLOAT_FIXED_S - //Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; - FOR(Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - Scale_sig32(output[i], Q7 - (31 - exp), L_FRAME48k); - p_output_fx[i] = output[i]; - } - - Word16 subframe_length; Word16 num_subframes = (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); - subframe_length = output_frame / num_subframes; - -#if 1 - for ( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + for (Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++) { - Word16 idx = subframe_idx; + Word16 idx = subframe_idx; + Word16 pos_q = Q25; + IF((*hCombinedOrientationData)->listenerPos != NULL) + { + (*hCombinedOrientationData)->listenerPos[idx].x_fx = L_shr((*hCombinedOrientationData)->listenerPos[idx].x_fx, (*hCombinedOrientationData)->listenerPos[idx].q_fact - pos_q); + (*hCombinedOrientationData)->listenerPos[idx].y_fx = L_shr((*hCombinedOrientationData)->listenerPos[idx].y_fx, (*hCombinedOrientationData)->listenerPos[idx].q_fact - pos_q); + (*hCombinedOrientationData)->listenerPos[idx].z_fx = L_shr((*hCombinedOrientationData)->listenerPos[idx].z_fx, (*hCombinedOrientationData)->listenerPos[idx].q_fact - pos_q); + (*hCombinedOrientationData)->listenerPos[idx].q_fact = pos_q; + } + FOR(int i = 0; i < 3; i++) + { + pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = L_shr(pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], pTDRend->hBinRendererTd->Listener_p->Pos_q - pos_q); + pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; move16(); + } + } - IF( ( *hCombinedOrientationData )->Quaternions ) - { - float max_val = 0; - max_val = (float) max( max_val, fabs( ( *hCombinedOrientationData )->Quaternions[idx].w ) ); - max_val = (float) max( max_val, fabs( ( *hCombinedOrientationData )->Quaternions[idx].x ) ); - max_val = (float) max( max_val, fabs( ( *hCombinedOrientationData )->Quaternions[idx].y ) ); - max_val = (float) max( max_val, fabs( ( *hCombinedOrientationData )->Quaternions[idx].z ) ); - Word16 quat_q = Q_factor_L( max_val ); - ( *hCombinedOrientationData )->Quaternions[idx].w_fx = float_to_fix( ( *hCombinedOrientationData )->Quaternions[idx].w, quat_q ); - ( *hCombinedOrientationData )->Quaternions[idx].x_fx = float_to_fix( ( *hCombinedOrientationData )->Quaternions[idx].x, quat_q ); - ( *hCombinedOrientationData )->Quaternions[idx].y_fx = float_to_fix( ( *hCombinedOrientationData )->Quaternions[idx].y, quat_q ); - ( *hCombinedOrientationData )->Quaternions[idx].z_fx = float_to_fix( ( *hCombinedOrientationData )->Quaternions[idx].z, quat_q ); - } - Word16 pos_q = Q25; - IF((*hCombinedOrientationData)->listenerPos != NULL) - { - (*hCombinedOrientationData)->listenerPos[idx].x_fx = (Word32)float_to_fix((*hCombinedOrientationData)->listenerPos[idx].x, pos_q); - (*hCombinedOrientationData)->listenerPos[idx].y_fx = (Word32)float_to_fix((*hCombinedOrientationData)->listenerPos[idx].y, pos_q); - (*hCombinedOrientationData)->listenerPos[idx].z_fx = (Word32)float_to_fix((*hCombinedOrientationData)->listenerPos[idx].z, pos_q); - } - FOR(int i = 0; i < 3; i++) - { - pTDRend->hBinRendererTd->Listener_p->Front_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Front[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Up_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Up[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Right_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Right[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; - pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Pos[i], pTDRend->hBinRendererTd->Listener_p->Pos_q); - } - } -#endif - if ((error = ivas_td_binaural_renderer_unwrap_fx(hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, - ism_md_subframe_update_ext, p_output_fx, output_frame, (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs))) != IVAS_ERR_OK) + IF ((error = ivas_td_binaural_renderer_unwrap_fx(hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, + ism_md_subframe_update_ext, p_output_fx, output_frame, (Word16)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs))) != IVAS_ERR_OK) { return error; } - -#if 1 - for (int i = 0; i < 3; i++) - { - pTDRend->hBinRendererTd->Listener_p->Front[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Front_fx[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Up[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Up_fx[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Right[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Right_fx[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Pos[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], pTDRend->hBinRendererTd->Listener_p->Pos_q); - } - + +#if 0 //TO-BE-REMOVED for (Word16 subframe_idx = 0; subframe_idx < (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); subframe_idx++) { - if (subframe_idx == ism_md_subframe_update_ext) + if (subframe_idx == ism_md_subframe_update_ext) + { + Word16 i = 0; + FOR(Word16 ns = 0; ns < num_src; ns++) { - FOR(Word16 ns = 0; ns < num_src - 1; ns++) - { - fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Front_p_fx, pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Front_p, Q30, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); - fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Pos_p_fx, pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Pos_p, Q25, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); - } + if(ns != lfe_idx){ + fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Front_p_fx, pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Front_p, Q30, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); + fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx, pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p, pTDRend->hBinRendererTd->Sources[i]->SrcSpatial_p->q_Pos_p, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); + + i = add(i, 1); + } } + } } - exp = 31 - Q7; #endif - -#if 0 - FOR(Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++) + IF(hReverb != NULL) { - fixedToFloat_arrL(output_fx[i], output[i], Q7, L_FRAME48k); + *exp = sub(*exp, 2); } -#endif -#else - if ((error = ivas_td_binaural_renderer_unwrap(hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, - ism_md_subframe_update_ext, p_output, output_frame, (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs))) != IVAS_ERR_OK) - { - return error; - } -#if 1 - IF(hReverb != NULL) - { - exp = sub(exp, 2); - } - /*This intermediate conversion will be removed once the subfunctions are also converted to fixed*/ - for (ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) - { - for (j = 0; j < L_FRAME48k; j++) - { - output[ch][j] = (Word32)(output_fl[ch][j] * (1 << (exp))); - } - } -#endif -#endif pop_wmops(); return IVAS_ERR_OK; } -#endif +#else /*---------------------------------------------------------------------* * ivas_td_binaural_renderer_ext() * @@ -1783,6 +1701,7 @@ ivas_error ivas_td_binaural_renderer_ext( IVAS_REND_AudioConfigType inConfigType; AUDIO_CONFIG transport_config; ivas_error error; + float *p_output[MAX_OUTPUT_CHANNELS]; int16_t ch; for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) @@ -1827,98 +1746,18 @@ ivas_error ivas_td_binaural_renderer_ext( hIsmMetaData[0]->radius = currentPos->radius; hIsmMetaData[0]->non_diegetic_flag = currentPos->non_diegetic_flag; } -#ifdef IVAS_FLOAT_FIXED_s - Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; - FOR(Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - floatToFixed_arrL(output[i], output_fx[i], Q7, L_FRAME48k); - p_output_fx[i] = output_fx[i]; - } - - Word16 subframe_length; - Word16 num_subframes = (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); - subframe_length = output_frame / num_subframes; - -#if 1 - for (Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++) - { - Word16 idx = subframe_idx; - - IF((*hCombinedOrientationData)->Quaternions) { - float max_val = 0; - max_val = (float)max(max_val, fabs((*hCombinedOrientationData)->Quaternions[idx].w)); - max_val = (float)max(max_val, fabs((*hCombinedOrientationData)->Quaternions[idx].x)); - max_val = (float)max(max_val, fabs((*hCombinedOrientationData)->Quaternions[idx].y)); - max_val = (float)max(max_val, fabs((*hCombinedOrientationData)->Quaternions[idx].z)); - Word16 quat_q = Q_factor_L(max_val); - (*hCombinedOrientationData)->Quaternions[idx].w_fx = float_to_fix((*hCombinedOrientationData)->Quaternions[idx].w, quat_q); - (*hCombinedOrientationData)->Quaternions[idx].x_fx = float_to_fix((*hCombinedOrientationData)->Quaternions[idx].x, quat_q); - (*hCombinedOrientationData)->Quaternions[idx].y_fx = float_to_fix((*hCombinedOrientationData)->Quaternions[idx].y, quat_q); - (*hCombinedOrientationData)->Quaternions[idx].z_fx = float_to_fix((*hCombinedOrientationData)->Quaternions[idx].z, quat_q); - } - Word16 pos_q = Q25; - - IF((*hCombinedOrientationData)->listenerPos != NULL) - { - (*hCombinedOrientationData)->listenerPos[idx].x_fx = (Word32)float_to_fix((*hCombinedOrientationData)->listenerPos[idx].x, pos_q); - (*hCombinedOrientationData)->listenerPos[idx].y_fx = (Word32)float_to_fix((*hCombinedOrientationData)->listenerPos[idx].y, pos_q); - (*hCombinedOrientationData)->listenerPos[idx].z_fx = (Word32)float_to_fix((*hCombinedOrientationData)->listenerPos[idx].z, pos_q); - } - FOR(int i = 0; i < 3; i++) - { - pTDRend->hBinRendererTd->Listener_p->Front_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Front[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Up_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Up[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Right_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Right[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Pos_q = pos_q; - pTDRend->hBinRendererTd->Listener_p->Pos_fx[i] = float_to_fix(pTDRend->hBinRendererTd->Listener_p->Pos[i], pTDRend->hBinRendererTd->Listener_p->Pos_q); - } - } -#endif - if ((error = ivas_td_binaural_renderer_unwrap_fx(hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, - ism_md_subframe_update_ext, p_output_fx, output_frame, (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs))) != IVAS_ERR_OK) - { - return error; - } - -#if 1 - for (int i = 0; i < 3; i++) - { - pTDRend->hBinRendererTd->Listener_p->Front[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Front_fx[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Up[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Up_fx[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Right[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Right_fx[i], Q30); - pTDRend->hBinRendererTd->Listener_p->Pos[i] = fix_to_float(pTDRend->hBinRendererTd->Listener_p->Pos_fx[i], pTDRend->hBinRendererTd->Listener_p->Pos_q); - } - for (Word16 subframe_idx = 0; subframe_idx < (int16_t)((output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) / output_Fs); subframe_idx++) - { - if (subframe_idx == ism_md_subframe_update_ext) - { - FOR(Word16 ns = 0; ns < num_src; ns++) - { - fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Front_p_fx, pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Front_p, Q30, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); - fixedToFloat_arrL(pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Pos_p_fx, pTDRend->hBinRendererTd->Sources[ns]->SrcSpatial_p->Pos_p, Q25, 3 * SPAT_BIN_MAX_INPUT_CHANNELS); - } - } - } - FOR(Word16 i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - fixedToFloat_arrL(output_fx[i], output[i], Q7, L_FRAME48k); - } -#endif -#else if ( ( error = ivas_td_binaural_renderer_unwrap( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, *hCombinedOrientationData, ism_md_subframe_update_ext, p_output, output_frame, (int16_t) ( ( output_frame * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ) ) ) != IVAS_ERR_OK ) { return error; } -#endif pop_wmops(); return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * angles_to_vec() @@ -1941,7 +1780,7 @@ static void angles_to_vec_fx( vec[2] = L_mult( radius, getSineWord16R2( elevation_fx ) ); return; } -#endif // IVAS_FLOAT_FIXED +#else static void angles_to_vec( const float radius, /* i : radius */ @@ -1956,3 +1795,4 @@ static void angles_to_vec( return; } +#endif // IVAS_FLOAT_FIXED \ No newline at end of file diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 298a45c4d..fac68039a 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -75,7 +75,7 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( const Word16 SrcInd, /* i : Source index */ const Word32 *Vec_p /* i : Position vector */ ) -{ + { TDREND_SRC_SPATIAL_t *SrcSpatial_p; IF(GT_16(SrcInd, hBinRendererTd->MaxSrcInd)) @@ -85,7 +85,10 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( ELSE { SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; - + SrcSpatial_p->Pos_p_fx[0] = L_shr(SrcSpatial_p->Pos_p_fx[0], SrcSpatial_p->q_Pos_p - Q25); + SrcSpatial_p->Pos_p_fx[1] = L_shr(SrcSpatial_p->Pos_p_fx[1], SrcSpatial_p->q_Pos_p - Q25); + SrcSpatial_p->Pos_p_fx[2] = L_shr(SrcSpatial_p->Pos_p_fx[2], SrcSpatial_p->q_Pos_p - Q25); + SrcSpatial_p->q_Pos_p = Q25; IF(NE_32(SrcSpatial_p->Pos_p_fx[0] , Vec_p[0]) || NE_32(SrcSpatial_p->Pos_p_fx[1] , Vec_p[1]) || NE_32(SrcSpatial_p->Pos_p_fx[2] , Vec_p[2])) { Copy32(Vec_p, SrcSpatial_p->Pos_p_fx, 3); @@ -96,7 +99,7 @@ ivas_error TDREND_MIX_SRC_SetPos_fx( return IVAS_ERR_OK; } -#endif +#else ivas_error TDREND_MIX_SRC_SetPos( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const int16_t SrcInd, /* i : Source index */ @@ -122,6 +125,7 @@ ivas_error TDREND_MIX_SRC_SetPos( return IVAS_ERR_OK; } +#endif /*-------------------------------------------------------------------* @@ -156,8 +160,7 @@ ivas_error TDREND_MIX_SRC_SetDir_fx( } return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED - +#else ivas_error TDREND_MIX_SRC_SetDir( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const int16_t SrcInd, /* i : Source index */ @@ -184,6 +187,7 @@ ivas_error TDREND_MIX_SRC_SetDir( return IVAS_ERR_OK; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 59657b592..c9a125cae 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1206,7 +1206,7 @@ ivas_error ivas_td_binaural_renderer_ext_fx( const Word32 output_Fs, /* i : output sampling rate */ const Word16 output_frame, /* i : output frame length */ Word32 output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ - Word16 exp + Word16 *exp ); ivas_error ivas_td_binaural_open_unwrap_fx( diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 4bae85cf6..f699b4416 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -218,14 +218,15 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure int16_t **azimuth2; int16_t **elevation2; +#ifndef IVAS_FLOAT_FIXED float **diffuseness_vector; float **energy_ratio1; float **energy_ratio2; -#ifdef IVAS_FLOAT_FIXED +#else Word32 **diffuseness_vector_fx; Word16 q_diffuseness_vector; - Word32 **energy_ratio1_fx; - Word32 **energy_ratio2_fx; + Word32 **energy_ratio1_fx; /* Q30 */ + Word32 **energy_ratio2_fx; /* Q30 */ #endif #ifndef IVAS_FLOAT_FIXED @@ -506,10 +507,17 @@ typedef struct float subtract_power_y_smooth; float target_power_y_smooth; +#ifndef IVAS_FLOAT_FIXED float lr_total_bb_ratio_db; float lr_total_hi_ratio_db; float min_sum_total_ratio_db; float subtract_target_ratio_db; +#else + Word32 lr_total_bb_ratio_db_fx; /* Q21 */ + Word32 lr_total_hi_ratio_db_fx; /* Q21 */ + Word32 min_sum_total_ratio_db_fx; /* Q21 */ + Word32 subtract_target_ratio_db_fx; /* Q21 */ +#endif #ifdef IVAS_FLOAT_FIXED Word32 left_bb_power_fx; @@ -538,11 +546,6 @@ typedef struct Word16 q_subtract_power_y; Word16 q_subtract_power_y_smooth; Word16 q_target_power_y_smooth; - - Word32 lr_total_bb_ratio_db_fx; - Word32 lr_total_hi_ratio_db_fx; - Word32 min_sum_total_ratio_db_fx; - Word32 subtract_target_ratio_db_fx; // Q21 #endif int16_t counter; @@ -1834,8 +1837,10 @@ typedef struct { int16_t Updated; TDREND_PosType_t PosType; +#ifndef IVAS_FLOAT_FIXED float Pos_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; float Front_p[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; +#endif #ifdef IVAS_FLOAT_FIXED Word32 Pos_p_fx[3 * SPAT_BIN_MAX_INPUT_CHANNELS]; // Q25 Word16 q_Pos_p; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 92088eed9..09c3f0b80 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -162,7 +162,9 @@ typedef struct #endif pan_vector prev_pan_gains; int8_t firstFrameRendered; +#ifndef IVAS_FLOAT_FIXED float *bufferData; +#endif Word32 *bufferData_fx; Word16 nonDiegeticPan; float nonDiegeticPanGain; @@ -239,7 +241,9 @@ typedef struct Word32 nonDiegeticPanGain_fx; lfe_routing lfeRouting; Word32 *bufferData_fx; +#ifndef IVAS_FLOAT_FIXED float *bufferData; +#endif int16_t binauralDelaySmp; #ifndef IVAS_FLOAT_FIXED float nonDiegeticPanGain; @@ -281,7 +285,9 @@ typedef struct CREND_WRAPPER_HANDLE crendWrapper; rotation_gains rot_gains_prev; rotation_gains_fx rot_gains_prev_fx; +#ifndef IVAS_FLOAT_FIXED float *bufferData; +#endif Word32 *bufferData_fx; DIRAC_ANA_HANDLE hDirAC; } input_sba; @@ -2261,11 +2267,11 @@ static bool isIoConfigPairSupported( static ivas_error initIsmMasaRendering( input_ism *inputIsm, - const int32_t inSampleRate ) + const Word32 inSampleRate ) { ivas_error error; - if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) + IF ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { #ifdef IVAS_FLOAT_FIXED ivas_td_binaural_close_fx( &inputIsm->tdRendWrapper.hBinRendererTd ); @@ -2279,7 +2285,7 @@ static ivas_error initIsmMasaRendering( ivas_reverb_close( &inputIsm->hReverb ); - if ( ( error = ivas_omasa_ana_open( &inputIsm->hOMasa, inSampleRate, inputIsm->total_num_objects ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_omasa_ana_open( &inputIsm->hOMasa, inSampleRate, inputIsm->total_num_objects ) ) != IVAS_ERR_OK ) { return error; } @@ -2288,6 +2294,104 @@ static ivas_error initIsmMasaRendering( } +#ifdef IVAS_FLOAT_FIXED +static ivas_error setRendInputActiveIsm( + void *input, + const AUDIO_CONFIG inConfig, + const IVAS_REND_InputId id, + RENDER_CONFIG_DATA *hRendCfg ) +{ + ivas_error error; + rendering_context rendCtx; + AUDIO_CONFIG outConfig; + input_ism *inputIsm; + + inputIsm = (input_ism *) input; + rendCtx = inputIsm->base.ctx; + outConfig = *rendCtx.pOutConfig; + + IF ( !isIoConfigPairSupported( inConfig, outConfig ) ) + { + return IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED; + } + + IF ( ( error = allocateInputBaseBufferData_fx( &inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) + { + return error; + } + initRendInputBase_fx( &inputIsm->base, inConfig, id, rendCtx, inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ); + + inputIsm->firstFrameRendered = FALSE; + + inputIsm->currentPos = defaultObjectPosition(); + inputIsm->previousPos = defaultObjectPosition(); + inputIsm->crendWrapper = NULL; + inputIsm->hReverb = NULL; + inputIsm->tdRendWrapper = defaultTdRendWrapper(); + + initRotMatrix_fx( inputIsm->rot_mat_prev ); + + set_zero_fx( inputIsm->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); + + inputIsm->hOMasa = NULL; + + error = IVAS_ERR_OK; + + IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR) ) + { + IF ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, IVAS_AUDIO_CONFIG_7_1_4, outConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_MASA1) || EQ_16(outConfig , IVAS_AUDIO_CONFIG_MASA2) ) + { + IF ( ( error = initIsmMasaRendering( inputIsm, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; + Word16 num_src; + Word16 ivas_format = ( EQ_16( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) ? MC_FORMAT : ISM_FORMAT; + IF( ( error = ivas_td_binaural_open_ext_fx( &inputIsm->tdRendWrapper, inConfig, hRendCfg, NULL, *rendCtx.pOutSampleRate, SrcInd, &num_src ) ) != IVAS_ERR_OK ) + { + return error; + } + + Word16 nchan_rend = num_src; + IF( EQ_16( ivas_format, MC_FORMAT ) && NE_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + { + nchan_rend--; /* Skip LFE channel -- added to the others */ + } + FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) + { + TDREND_SRC_t *Src_p = inputIsm->tdRendWrapper.hBinRendererTd->Sources[SrcInd[nS]]; + IF( Src_p != NULL ) + { + IF( Src_p->SrcSpatial_p != NULL ) + { + Src_p->SrcSpatial_p->q_Pos_p = Q31; + } + TDREND_SRC_SPATIAL_t *SrcSpatial_p = inputIsm->tdRendWrapper.hBinRendererTd->Sources[nS]->SrcSpatial_p; + SrcSpatial_p->q_Pos_p = Q31; + } + } + + IF ( EQ_16(outConfig , IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB) ) + { + IF ( ( error = ivas_reverb_open_fx( &( inputIsm->hReverb ), outConfig, NULL, inputIsm->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac_fx, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + return IVAS_ERR_OK; +} +#else static ivas_error setRendInputActiveIsm( void *input, const AUDIO_CONFIG inConfig, @@ -2312,7 +2416,9 @@ static ivas_error setRendInputActiveIsm( { return error; } +#if 0 initRendInputBase( &inputIsm->base, inConfig, id, rendCtx, inputIsm->bufferData, MAX_BUFFER_LENGTH ); +#endif #ifdef IVAS_FLOAT_FIXED if ( ( error = allocateInputBaseBufferData_fx( &inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) { @@ -2419,7 +2525,37 @@ static ivas_error setRendInputActiveIsm( return IVAS_ERR_OK; } +#endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +static void clearInputIsm( + input_ism *inputIsm ) +{ + rendering_context rendCtx; + + rendCtx = inputIsm->base.ctx; + + freeInputBaseBufferData_fx( &inputIsm->base.inputBuffer.data_fx ); + + initRendInputBase_fx( &inputIsm->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); + + /* Free input's internal handles */ + ivas_rend_closeCrend( &inputIsm->crendWrapper ); + + ivas_reverb_close( &inputIsm->hReverb ); + + if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) + { + ivas_td_binaural_close_fx( &inputIsm->tdRendWrapper.hBinRendererTd ); + inputIsm->tdRendWrapper.hHrtfTD = NULL; + } + + + ivas_omasa_ana_close( &( inputIsm->hOMasa ) ); + + return; +} +#else static void clearInputIsm( input_ism *inputIsm ) { @@ -2454,6 +2590,7 @@ static void clearInputIsm( return; } +#endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED static void copyLsConversionMatrixToPanMatrix_fx( @@ -3848,15 +3985,10 @@ static ivas_error initMcBinauralRendering( { IF( Src_p->SrcSpatial_p != NULL ) { - FOR( Word16 nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) - { - fixedToFloat_arrL( Src_p->SrcSpatial_p->Pos_p_fx + nC * 3, Src_p->SrcSpatial_p->Pos_p + nC * 3, Q31, 3 ); - fixedToFloat_arrL( Src_p->SrcSpatial_p->Front_p_fx + nC * 3, Src_p->SrcSpatial_p->Front_p + nC * 3, Q30, 3 ); - } + Src_p->SrcSpatial_p->q_Pos_p = 31; } TDREND_SRC_SPATIAL_t *SrcSpatial_p = inputMc->tdRendWrapper.hBinRendererTd->Sources[nS]->SrcSpatial_p; - fixedToFloat_arrL( SrcSpatial_p->Pos_p_fx, SrcSpatial_p->Pos_p, Q31, 3 ); - fixedToFloat_arrL( SrcSpatial_p->Front_p_fx, SrcSpatial_p->Front_p, Q30, 3 ); + SrcSpatial_p->q_Pos_p = 31; } } #else @@ -4322,11 +4454,6 @@ static ivas_error setRendInputActiveMc( { return error; } - IF( ( error = allocateInputBaseBufferData( &inputMc->bufferData, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) - { - return error; - } - initRendInputBase( &inputMc->base, inConfig, id, rendCtx, inputMc->bufferData, MAX_BUFFER_LENGTH ); IF( ( error = allocateInputBaseBufferData_fx( &inputMc->bufferData_fx, MAX_BUFFER_LENGTH ) ) != IVAS_ERR_OK ) { @@ -4449,7 +4576,9 @@ static void clearInputMc( rendCtx = inputMc->base.ctx; freeMcLfeDelayBuffer_fx( &inputMc->lfeDelayBuffer_fx ); freeInputBaseBufferData_fx( &inputMc->bufferData_fx ); +#if 0 initRendInputBase( &inputMc->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); +#endif initRendInputBase_fx( &inputMc->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); /* Free input's internal handles */ @@ -5161,7 +5290,7 @@ ivas_error IVAS_REND_Open( const Word32 outputSampleRate, const AUDIO_CONFIG outConfig, const Word16 nonDiegeticPan, - const float nonDiegeticPanGain, + const Word32 nonDiegeticPanGain,/*Q31*/ const Word16 num_subframes ) { Word16 i; @@ -5186,7 +5315,7 @@ ivas_error IVAS_REND_Open( } *phIvasRend = (IVAS_REND_HANDLE) malloc( sizeof( struct IVAS_REND ) ); - if ( *phIvasRend == NULL ) + IF ( *phIvasRend == NULL ) { return IVAS_ERR_FAILED_ALLOC; } @@ -5206,7 +5335,7 @@ ivas_error IVAS_REND_Open( return error; } - if ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) + IF ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5218,77 +5347,69 @@ ivas_error IVAS_REND_Open( } /* Initialize external orientation data */ - if ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_external_orientation_open( &( hIvasRend->hExternalOrientationData ), num_subframes ) ) != IVAS_ERR_OK ) { return error; } /* Initilize combined orientation data */ - if ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_combined_orientation_open( &( hIvasRend->hCombinedOrientationData ), outputSampleRate, num_subframes ) ) != IVAS_ERR_OK ) { return error; } /* Initialize EFAP */ - if ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) + IF ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) { return error; } /* Initialize inputs */ - for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) + FOR ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) { - initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); -#ifdef IVAS_FLOAT_FIXED initRendInputBase_fx( &hIvasRend->inputsIsm[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); -#endif hIvasRend->inputsIsm[i].crendWrapper = NULL; hIvasRend->inputsIsm[i].hReverb = NULL; hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL; +#if 0 hIvasRend->inputsIsm[i].bufferData = NULL; +#endif hIvasRend->inputsIsm[i].nonDiegeticPan = nonDiegeticPan; -#ifndef IVAS_FLOAT_FIXED - hIvasRend->inputsIsm[i].nonDiegeticPanGain = nonDiegeticPanGain; -#else - hIvasRend->inputsIsm[i].nonDiegeticPanGain_fx = floatToFixed_32( nonDiegeticPanGain, Q31 ); -#endif // !IVAS_FLOAT_FIXED + hIvasRend->inputsIsm[i].nonDiegeticPanGain_fx = nonDiegeticPanGain; hIvasRend->inputsIsm[i].hOMasa = NULL; -#ifdef IVAS_FLOAT_FIXED hIvasRend->inputsIsm[i].bufferData_fx = NULL; -#endif } - for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + FOR ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { - initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + initRendInputBase_fx( &hIvasRend->inputsMc[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL; hIvasRend->inputsMc[i].crendWrapper = NULL; hIvasRend->inputsMc[i].hReverb = NULL; hIvasRend->inputsMc[i].tdRendWrapper.hBinRendererTd = NULL; +#if 0 hIvasRend->inputsMc[i].bufferData = NULL; +#endif hIvasRend->inputsMc[i].bufferData_fx = NULL; hIvasRend->inputsMc[i].lfeDelayBuffer_fx = NULL; hIvasRend->inputsMc[i].nonDiegeticPan = nonDiegeticPan; -#ifndef IVAS_FLOAT_FIXED - hIvasRend->inputsMc[i].lfeDelayBuffer = NULL; - hIvasRend->inputsMc[i].nonDiegeticPanGain = nonDiegeticPanGain; -#endif - Word32 temp = ( abs( (Word32) nonDiegeticPanGain ) ); - hIvasRend->inputsMc[i].nonDiegeticPanGain_fx = ( temp == 1 ) ? ( ( nonDiegeticPanGain < 0 ) ? L_negate( ONE_IN_Q31 ) : ONE_IN_Q31 ) : (Word32) ( nonDiegeticPanGain * ( ONE_IN_Q31 ) ); + hIvasRend->inputsMc[i].nonDiegeticPanGain_fx = nonDiegeticPanGain; hIvasRend->inputsMc[i].hMcMasa = NULL; } - for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) + FOR ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { - initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + initRendInputBase_fx( &hIvasRend->inputsSba[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); hIvasRend->inputsSba[i].crendWrapper = NULL; +#if 0 hIvasRend->inputsSba[i].bufferData = NULL; +#endif hIvasRend->inputsSba[i].bufferData_fx = NULL; hIvasRend->inputsSba[i].hDirAC = NULL; } - for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + FOR ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); @@ -8828,32 +8949,49 @@ static ivas_error rotateFrameSba( #endif - #ifdef IVAS_FLOAT_FIXED static ivas_error renderIsmToBinaural( - const input_ism *ismInput, + input_ism *ismInput, IVAS_REND_AudioBuffer outAudio ) { Word32 tmpTDRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; ivas_error error; Word16 ism_md_subframe_update_ext; - + Word16 i; + Word16 exp = *outAudio.pq_fact; push_wmops( "renderIsmToBinaural" ); /* Metadata Delay to sync with audio delay converted from ms to 5ms (1000/50/4) subframe index */ ism_md_subframe_update_ext = (Word16) roundf( ismInput->ism_metadata_delay_ms / ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) );/*To be cleaned up later*/ copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpTDRendBuffer ); +#if 1 + ismInput->currentPos.azimuth_fx = floatToFixed(ismInput->currentPos.azimuth, Q22); + ismInput->currentPos.elevation_fx = floatToFixed(ismInput->currentPos.elevation, Q22); + ismInput->currentPos.spread_fx = floatToFixed(ismInput->currentPos.spread, Q22); + ismInput->currentPos.yaw_fx = floatToFixed(ismInput->currentPos.yaw, Q22); + ismInput->currentPos.pitch_fx = floatToFixed(ismInput->currentPos.pitch, Q22); + ismInput->currentPos.radius_fx = float_to_fix16(ismInput->currentPos.radius, Q9); +#endif + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(tmpTDRendBuffer[i], L_FRAME48k, sub(11, exp)); + } IF ( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, - *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer ,*outAudio.pq_fact) ) != IVAS_ERR_OK ) + *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer , &exp) ) != IVAS_ERR_OK ) { return error; } + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(tmpTDRendBuffer[i], L_FRAME48k, -sub(11, exp)); + } + IF( ismInput->hReverb != NULL ) { - FOR ( int i = 0; i < outAudio.config.numChannels; i++ ) + FOR ( i = 0; i < outAudio.config.numChannels; i++ ) { - FOR ( int j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) + FOR ( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], 2 ); } } @@ -8865,7 +9003,7 @@ static ivas_error renderIsmToBinaural( } #else static ivas_error renderIsmToBinaural( - const input_ism *ismInput, + input_ism *ismInput, IVAS_REND_AudioBuffer outAudio ) { float tmpTDRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -8876,7 +9014,14 @@ static ivas_error renderIsmToBinaural( /* Metadata Delay to sync with audio delay converted from ms to 5ms (1000/50/4) subframe index */ ism_md_subframe_update_ext = (int16_t) roundf( ismInput->ism_metadata_delay_ms / ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) ); copyBufferTo2dArray( ismInput->base.inputBuffer, tmpTDRendBuffer ); - +#ifdef IVAS_FLOAT_FIXED + ismInput->currentPos.azimuth_fx = float_to_fix(ismInput->currentPos.azimuth, Q22); + ismInput->currentPos.elevation_fx = float_to_fix(ismInput->currentPos.elevation, Q22); + ismInput->currentPos.spread_fx = float_to_fix(ismInput->currentPos.spread, Q22); + ismInput->currentPos.yaw_fx = float_to_fix(ismInput->currentPos.yaw, Q22); + ismInput->currentPos.pitch_fx = float_to_fix(ismInput->currentPos.pitch, Q22); + ismInput->currentPos.radius_fx = float_to_fix(ismInput->currentPos.radius, Q9); +#endif if ( ( error = ivas_td_binaural_renderer_ext( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer ) ) != IVAS_ERR_OK ) { @@ -8889,7 +9034,6 @@ static ivas_error renderIsmToBinaural( return IVAS_ERR_OK; } - #endif // IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED @@ -9268,7 +9412,6 @@ static ivas_error renderIsmToBinauralRoom( return IVAS_ERR_OK; } #endif - #ifdef IVAS_FLOAT_FIXED static ivas_error renderIsmToBinauralReverb( input_ism *ismInput, @@ -9276,7 +9419,8 @@ static ivas_error renderIsmToBinauralReverb( { Word32 tmpRendBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; ivas_error error; - Word16 ism_md_subframe_update_ext; + Word16 ism_md_subframe_update_ext, i; + Word16 exp = *outAudio.pq_fact; push_wmops( "renderIsmToBinauralRoom" ); @@ -9284,17 +9428,34 @@ static ivas_error renderIsmToBinauralReverb( ism_md_subframe_update_ext = (Word16) roundf( ismInput->ism_metadata_delay_ms / ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) );/*ism_metadata_delay_ms :To be replaced later*/ copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpRendBuffer_fx ); +#if 1 + ismInput->currentPos.azimuth_fx = floatToFixed(ismInput->currentPos.azimuth, Q22); + ismInput->currentPos.elevation_fx = floatToFixed(ismInput->currentPos.elevation, Q22); + ismInput->currentPos.spread_fx = floatToFixed(ismInput->currentPos.spread, Q22); + ismInput->currentPos.yaw_fx = floatToFixed(ismInput->currentPos.yaw, Q22); + ismInput->currentPos.pitch_fx = floatToFixed(ismInput->currentPos.pitch, Q22); + ismInput->currentPos.radius_fx = float_to_fix16(ismInput->currentPos.radius, Q9); +#endif + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(tmpRendBuffer_fx[i], L_FRAME48k, sub(11, exp)); + } - IF ( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpRendBuffer_fx , *outAudio.pq_fact) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_td_binaural_renderer_ext_fx( &ismInput->tdRendWrapper, ismInput->base.inConfig, NULL, ismInput->base.ctx.pCombinedOrientationData, &ismInput->currentPos, ismInput->hReverb, ism_md_subframe_update_ext, *ismInput->base.ctx.pOutSampleRate, outAudio.config.numSamplesPerChannel, tmpRendBuffer_fx , &exp) ) != IVAS_ERR_OK ) { return error; } + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(tmpRendBuffer_fx[i], L_FRAME48k, -sub(11, exp)); + } + IF( ismInput->hReverb != NULL ) { - FOR ( int i = 0; i < outAudio.config.numChannels; i++ ) + FOR ( i = 0; i < outAudio.config.numChannels; i++ ) { - FOR ( int j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) + FOR ( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); } } @@ -9732,7 +9893,7 @@ static ivas_error renderInputIsm( { ivas_error error; IVAS_REND_AudioBuffer inAudio; - Word16 exp = 8; + Word16 exp = *outAudio.pq_fact; move16(); error = IVAS_ERR_OK; @@ -9747,34 +9908,31 @@ static ivas_error renderInputIsm( /* Apply input gain to new audio */ v_multc_fixed( inAudio.data_fx, ismInput->base.gain_fx, inAudio.data_fx, imult1616(inAudio.config.numSamplesPerChannel , inAudio.config.numChannels) ); + *outAudio.pq_fact -= 1; + exp = *outAudio.pq_fact; /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *ismInput->base.ctx.pCombinedOrientationData ); - scale_sig32( ismInput->base.inputBuffer.data_fx, imult1616( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ), 1 ); SWITCH ( getAudioConfigType( outConfig ) ) { case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: error = renderIsmToMc( ismInput, outAudio ); - exp = Q8; BREAK; case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: error = renderIsmToSba( ismInput, outConfig, outAudio ); - exp = Q8; BREAK; case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: switch ( outConfig ) { case IVAS_AUDIO_CONFIG_BINAURAL: error = renderIsmToBinaural( ismInput, outAudio ); - exp = *outAudio.pq_fact; BREAK; case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR: error = renderIsmToBinauralRoom( ismInput, outAudio, &exp ); BREAK; case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: error = renderIsmToBinauralReverb( ismInput, outAudio ); - exp = *outAudio.pq_fact; BREAK; default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; @@ -9953,7 +10111,7 @@ static ivas_error renderActiveInputsIsm( Word16 i; input_ism *pCurrentInput; ivas_error error; - Word16 input_q = *outAudio.pq_fact; + Word16 input_q = Q8; for ( i = 0, pCurrentInput = hIvasRend->inputsIsm; i < RENDERER_MAX_ISM_INPUTS; ++i, ++pCurrentInput ) { IF ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) @@ -9962,21 +10120,18 @@ static ivas_error renderActiveInputsIsm( continue; } + *outAudio.pq_fact = Q8; if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; } FOR(Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) { - outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( input_q , ( *outAudio.pq_fact ) ) ); + outAudio.data_fx[j] = L_shl( outAudio.data_fx[j], sub( sub(input_q,1) , ( *outAudio.pq_fact ) ) ); } - *outAudio.pq_fact = input_q; + *outAudio.pq_fact = sub(input_q,1); } - FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) - { - outAudio.data_fx[j] = L_shr( outAudio.data_fx[j], 1); - } -#if 1/*To be removed later when dependency on data is removed*/ +#if 0/*To be removed later when dependency on data is removed*/ FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel * outAudio.config.numChannels; ++j ) { outAudio.data[j] = fixedToFloat( outAudio.data_fx[j], input_q - 1 ); @@ -10197,16 +10352,19 @@ static ivas_error renderMcToBinaural( { copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer_fx ); + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(tmpRendBuffer_fx[i], L_FRAME48k, sub(11, exp)); + } IF( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, - 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer_fx, *outAudio.pq_fact ) ) != IVAS_ERR_OK ) + 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer_fx, &exp ) ) != IVAS_ERR_OK ) { return error; } - IF( mcInput->hReverb != NULL ) + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - exp = sub( *outAudio.pq_fact, 2 ); - move16(); + Scale_sig32(tmpRendBuffer_fx[i], L_FRAME48k, -sub(11, exp)); } } ELSE @@ -10399,16 +10557,22 @@ static ivas_error renderMcToBinauralRoom( { copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer ); + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) + { + Scale_sig32(tmpRendBuffer[i], L_FRAME48k, sub(11, exp)); + } + IF( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, - 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer, *outAudio.pq_fact ) ) != IVAS_ERR_OK ) + 0, *mcInput->base.ctx.pOutSampleRate, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer, &exp ) ) != IVAS_ERR_OK ) { return error; } - IF( mcInput->hReverb != NULL ) + + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - exp = sub( *outAudio.pq_fact, 2 ); - move16(); + Scale_sig32(tmpRendBuffer[i], L_FRAME48k, -sub(11, exp)); } + //*outAudio.pq_fact = exp; } ELSE { @@ -11003,6 +11167,7 @@ static ivas_error renderActiveInputsMc( CONTINUE; } + *outAudio.pq_fact = Q8; IF( ( error = renderInputMc( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; @@ -11635,6 +11800,7 @@ static ivas_error renderActiveInputsSba( /* Skip inactive inputs */ CONTINUE; } + *outAudio.pq_fact = Q8; IF( ( error = renderInputSba( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; @@ -11668,63 +11834,53 @@ static ivas_error renderActiveInputsSba( return IVAS_ERR_OK; } #endif + + #ifdef IVAS_FLOAT_FIXED static void copyMasaMetadataToDiracRenderer_fx( MASA_METADATA_FRAME *meta, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, - const int16_t maxBin ) + const Word16 maxBin ) { Word16 band, sf, bin; Word16 meta_write_index; - hSpatParamRendCom->numParametricDirections = meta->descriptive_meta.numberOfDirections + 1; - hSpatParamRendCom->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1; + hSpatParamRendCom->numParametricDirections = add( meta->descriptive_meta.numberOfDirections, 1 ); + hSpatParamRendCom->numSimultaneousDirections = add( meta->descriptive_meta.numberOfDirections, 1 ); FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + sf ) % hSpatParamRendCom->dirac_md_buffer_length; + meta_write_index = add( hSpatParamRendCom->dirac_bs_md_write_idx, sf ) % hSpatParamRendCom->dirac_md_buffer_length; FOR( band = 0; band < MASA_MAXIMUM_CODING_SUBBANDS; band++ ) { FOR( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1] && bin < maxBin; bin++ ) { - // hSpatParamRendCom->azimuth[meta_write_index][bin] = (Word16) L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ); - // hSpatParamRendCom->elevation[meta_write_index][bin] = (Word16) L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ); + hSpatParamRendCom->azimuth[meta_write_index][bin] = (Word16) meta->directional_meta[0].azimuth[sf][band]; + move16(); + hSpatParamRendCom->elevation[meta_write_index][bin] = (Word16) meta->directional_meta[0].elevation[sf][band]; + move16(); hSpatParamRendCom->energy_ratio1_fx[meta_write_index][bin] = meta->directional_meta[0].energy_ratio_fx[sf][band]; + move32(); hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][bin] = L_sub( ONE_IN_Q30, meta->directional_meta[0].energy_ratio_fx[sf][band] ); + move32(); hSpatParamRendCom->spreadCoherence_fx[meta_write_index][bin] = meta->directional_meta[0].spread_coherence_fx[sf][band]; + move16(); hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][bin] = meta->common_meta.surround_coherence_fx[sf][band]; -#if 0 // Tobe removed after masa the path is complete - hSpatParamRendCom->energy_ratio1[meta_write_index][bin] = (float) hSpatParamRendCom->energy_ratio1_fx[meta_write_index][bin] / ONE_IN_Q30; - hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] = (float) hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][bin] / ONE_IN_Q30; - hSpatParamRendCom->spreadCoherence[meta_write_index][bin] = (float) hSpatParamRendCom->spreadCoherence_fx[meta_write_index][bin] / ONE_IN_Q15; - hSpatParamRendCom->surroundingCoherence[meta_write_index][bin] = (float) hSpatParamRendCom->surroundingCoherence_fx[meta_write_index][bin] / ONE_IN_Q15; -#else - hSpatParamRendCom->azimuth[meta_write_index][bin] = (int16_t) meta->directional_meta[0].azimuth[sf][band]; - hSpatParamRendCom->elevation[meta_write_index][bin] = (int16_t) meta->directional_meta[0].elevation[sf][band]; - hSpatParamRendCom->energy_ratio1[meta_write_index][bin] = meta->directional_meta[0].energy_ratio[sf][band]; - hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] = 1.0f - meta->directional_meta[0].energy_ratio[sf][band]; - -#endif + move16(); - IF( hSpatParamRendCom->numSimultaneousDirections == 2 ) + IF( EQ_16( hSpatParamRendCom->numSimultaneousDirections, 2 ) ) { - // hSpatParamRendCom->azimuth2[meta_write_index][bin] = (Word16) L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ); - // hSpatParamRendCom->elevation2[meta_write_index][bin] = (Word16) L_shr( meta->directional_meta[1].elevation[sf][band], Q22 ); + hSpatParamRendCom->azimuth2[meta_write_index][bin] = (Word16) meta->directional_meta[1].azimuth[sf][band]; + move16(); + hSpatParamRendCom->elevation2[meta_write_index][bin] = (Word16) meta->directional_meta[1].elevation[sf][band]; + move16(); hSpatParamRendCom->energy_ratio2_fx[meta_write_index][bin] = meta->directional_meta[1].energy_ratio_fx[sf][band]; + move32(); hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][bin] = L_sub( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][bin], meta->directional_meta[1].energy_ratio_fx[sf][band] ); + move32(); hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][bin] = meta->directional_meta[1].spread_coherence_fx[sf][band]; -#if 0 // Tobe removed after the masa path is complete - hSpatParamRendCom->energy_ratio2[meta_write_index][bin] = (float) hSpatParamRendCom->energy_ratio2_fx[meta_write_index][bin] / ONE_IN_Q30; - hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] = (float) hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][bin] / ONE_IN_Q30; - hSpatParamRendCom->spreadCoherence2[meta_write_index][bin] = (float) hSpatParamRendCom->spreadCoherence2_fx[meta_write_index][bin] / ONE_IN_Q15; -#else - hSpatParamRendCom->azimuth2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].azimuth[sf][band]; - hSpatParamRendCom->elevation2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].elevation[sf][band]; - hSpatParamRendCom->energy_ratio2[meta_write_index][bin] = meta->directional_meta[1].energy_ratio[sf][band]; - hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] -= meta->directional_meta[1].energy_ratio[sf][band]; - -#endif + move16(); } } } @@ -11778,6 +11934,8 @@ static void copyMasaMetadataToDiracRenderer( return; } #endif + + #ifdef IVAS_FLOAT_FIXED static void renderMasaToMasa( input_masa *masaInput, @@ -12215,6 +12373,9 @@ static ivas_error renderActiveInputsMasa( continue; } +#ifdef IVAS_FLOAT_FIXED + *outAudio.pq_fact = Q8; +#endif // IVAS_FLOAT_FIXED if ( ( error = renderInputMasa( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; @@ -12746,7 +12907,7 @@ static ivas_error getSamplesInternal( return error; } - IF( NE_32( hIvasRend->inputsSba[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsMc[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) + IF( NE_32( hIvasRend->inputsSba[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsMc[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID )|| NE_32( hIvasRend->inputsIsm[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID )) { #ifndef DISABLE_LIMITER Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); @@ -13315,10 +13476,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - hDirACRend->proto_frame_f = NULL; #if 1 /*TODO :To be removed later(after dependecy on buffer_energyis completely removed)*/ - hDirACRend->proto_frame_f_fx = NULL; + hDirACRend->proto_frame_f = NULL; #endif + hDirACRend->proto_frame_f_fx = NULL; } ELSE { @@ -13340,7 +13501,6 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( hDirACRend->buffer_energy = NULL; #endif hDirACRend->buffer_energy_fx = NULL; - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) @@ -14519,24 +14679,11 @@ static void intermidiate_ext_dirac_render( floatToFixed_arrL(output_f_flt[i], output_f[i], q_cldfb, L_FRAME48k); } - for(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++){ - for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[slot_idx]][i] = floatToFixed( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[slot_idx]][i], Q30 ); - } - } for(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++){ IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) { - IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) - { - floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); - } hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); } else { @@ -14552,15 +14699,11 @@ static void intermidiate_ext_dirac_render( { hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); } ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ { hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); } } @@ -14568,8 +14711,6 @@ static void intermidiate_ext_dirac_render( { hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); } } } @@ -14616,18 +14757,6 @@ static void intermidiate_ext_dirac_render( floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); } - IF( hDirACRend->masa_stereo_type_detect ) - { - IF( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db == -INFINITY ) - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = MIN_32; - } - ELSE - { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db, Q21 ); - } - } - floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); if ( hDirACRend->proto_signal_decorr_on == 1 ) { @@ -14764,8 +14893,6 @@ static void intermidiate_ext_dirac_render( fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); IF( hDirACRend->masa_stereo_type_detect != NULL ) { - hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx, Q21 ); - hDirACRend->masa_stereo_type_detect->target_power_y_smooth = fixedToFloat( hDirACRend->masa_stereo_type_detect->target_power_y_smooth_fx, hDirACRend->masa_stereo_type_detect->q_target_power_y_smooth ); hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); hDirACRend->masa_stereo_type_detect->subtract_power_y = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index 95a6dbfd5..3d6cac982 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -133,6 +133,16 @@ typedef enum _IVAS_REND_COMPLEXITY_LEVEL /* Functions to be called before rendering */ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_REND_Open( + IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ + const Word32 outputSampleRate, /* i : output sampling rate */ + const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ + const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ + const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain */ + const Word16 num_subframes /* i : number of subframes */ +); +#else ivas_error IVAS_REND_Open( IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ const int32_t outputSampleRate, /* i : output sampling rate */ @@ -141,6 +151,7 @@ ivas_error IVAS_REND_Open( const float nonDiegeticPanGain, /* i : non-diegetic panning gain */ const int16_t num_subframes /* i : number of subframes */ ); +#endif // IVAS_FLOAT_FIXED /* Note: this will reset custom LFE routings set for any MC input */ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( @@ -253,6 +264,7 @@ ivas_error IVAS_REND_FeedInputAudio_fx( const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); + #endif ivas_error IVAS_REND_FeedInputObjectMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ -- GitLab