From f10960543d34823d1aa9daf857970ccc5df1b87e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 17 Feb 2024 14:45:23 +0530 Subject: [PATCH] ivas_dec_dec_config, ivas_dec_rend_config and sub-funcs conv to fxd [x] Ftf changes for ivas_dec_dec_config, ivas_dec_rend_config and sub-functions --- lib_com/cnst.h | 1 + lib_com/ivas_dirac_com.c | 330 +++- lib_com/ivas_prot.h | 12 + lib_com/ivas_prot_fx.h | 23 + lib_com/ivas_sba_config.c | 9 +- lib_com/ivas_spar_com.c | 1 + lib_dec/ivas_dirac_dec.c | 1514 +++++++++++++++--- lib_dec/ivas_init_dec.c | 17 +- lib_dec/ivas_masa_dec.c | 7 + lib_dec/ivas_mc_param_dec.c | 2 +- lib_dec/ivas_mct_dec.c | 27 +- lib_dec/ivas_sba_dec.c | 9 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 30 +- lib_rend/ivas_dirac_decorr_dec.c | 83 +- lib_rend/ivas_dirac_output_synthesis_dec.c | 874 +++++++++- lib_rend/ivas_dirac_rend.c | 710 +++++++- lib_rend/ivas_prot_rend.h | 72 + lib_rend/ivas_rom_rend.c | 12 + lib_rend/ivas_rom_rend.h | 7 + lib_rend/ivas_stat_rend.h | 85 +- lib_rend/lib_rend.c | 10 +- 21 files changed, 3363 insertions(+), 472 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 637fdea38..f80119e69 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -732,6 +732,7 @@ enum #define CLDFB_OVRLP_MIN_SLOTS 3 /* CLDFB resampling - minimize processing to minimum required for transition frame ACELP->TCX/HQ */ #define INV_CLDFB_BANDWIDTH ( 1.f / 800.f ) #define INV_CLDFB_BANDWIDTH_Q31 ( 2684355l ) +#define CLDFB_BANDWIDTH 800 #define L_FILT_2OVER3 12 #define L_FILT_2OVER3_LP 3 diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index d1576eb8f..fe20ce7cb 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" #include "prot_fx1.h" #include "prot_fx2.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local function prototypes @@ -97,6 +98,135 @@ Word16 ivas_get_hodirac_flag_fx( * * DirAC Configuration function; used also in MASA decoder *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_config_fx( + void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ + const Word16 enc_dec /* i : encoder or decoder flag */ +) +{ + IVAS_FORMAT ivas_format; + Word16 sba_order; + Word16 *element_mode; + Word32 ivas_total_brate; + DIRAC_CONFIG_DATA_HANDLE hConfig; + IVAS_QMETADATA_HANDLE hQMetaData; + Word32 Fs; + Word16 *band_grouping; + ivas_error error; + Word16 spar_dirac_split_band; + IVAS_FB_MIXER_HANDLE hFbMdft; + Word16 *dirac_to_spar_md_bands; + + error = IVAS_ERR_OK; + + IF ( EQ_16(enc_dec , ENC)) + { + ivas_format = ((Encoder_Struct *)st_ivas)->hEncoderConfig->ivas_format; + element_mode = &((Encoder_Struct *)st_ivas)->hEncoderConfig->element_mode_init; + sba_order = ((Encoder_Struct *)st_ivas)->sba_analysis_order; + ivas_total_brate = ((Encoder_Struct *)st_ivas)->hEncoderConfig->ivas_total_brate; + Fs = ((Encoder_Struct *)st_ivas)->hEncoderConfig->input_Fs; + band_grouping = ((Encoder_Struct *)st_ivas)->hDirAC->band_grouping; + hConfig = ((Encoder_Struct *)st_ivas)->hDirAC->hConfig; + hQMetaData = ((Encoder_Struct *)st_ivas)->hQMetaData; + IF (((Encoder_Struct *)st_ivas)->hSpar != NULL) + { + hFbMdft = ((Encoder_Struct *)st_ivas)->hSpar->hFbMixer; + dirac_to_spar_md_bands = ((Encoder_Struct *)st_ivas)->hSpar->dirac_to_spar_md_bands; + } + ELSE + { + hFbMdft = NULL; + dirac_to_spar_md_bands = NULL; + } + } + ELSE + { + ivas_format = ((Decoder_Struct *)st_ivas)->ivas_format; + element_mode = &((Decoder_Struct *)st_ivas)->element_mode_init; + sba_order = ((Decoder_Struct *)st_ivas)->sba_analysis_order; + ivas_total_brate = ((Decoder_Struct *)st_ivas)->hDecoderConfig->ivas_total_brate; + Fs = ((Decoder_Struct *)st_ivas)->hDecoderConfig->output_Fs; + band_grouping = ((Decoder_Struct *)st_ivas)->hDirAC->band_grouping; + hConfig = ((Decoder_Struct *)st_ivas)->hDirAC->hConfig; + hQMetaData = ((Decoder_Struct *)st_ivas)->hQMetaData; + IF (((Decoder_Struct *)st_ivas)->hSpar != NULL) + { + hFbMdft = ((Decoder_Struct *)st_ivas)->hSpar->hFbMixer; + dirac_to_spar_md_bands = ((Decoder_Struct *)st_ivas)->hSpar->dirac_to_spar_md_bands; + } + ELSE + { + hFbMdft = NULL; + dirac_to_spar_md_bands = NULL; + } + ((Decoder_Struct *)st_ivas)->hDirAC->hFbMdft = hFbMdft; + } + + IF (ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) + { + hConfig->nbands = IVAS_MAX_NUM_BANDS; + + spar_dirac_split_band = s_min(IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND); + + IF (ivas_get_hodirac_flag(ivas_total_brate, sba_order))//add call after merge of 100861_dirac_dec + { + spar_dirac_split_band = 0; + } + } + ELSE + { + hConfig->nbands = 5; + spar_dirac_split_band = 0; + } + hConfig->enc_param_start_band = 0; + hConfig->dec_param_estim = FALSE; + IF (ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) /* skip for MASA decoder */ + { + IF ((error = ivas_dirac_sba_config_fx(hQMetaData, element_mode, ivas_total_brate, sba_order, hConfig->nbands - spar_dirac_split_band, + ivas_format)) != IVAS_ERR_OK) + { + return error; + } + + IF (hQMetaData != NULL) + { + IF (enc_dec == ENC) + { + hConfig->nbands = hQMetaData->q_direction[0].cfg.nbands; + } + hConfig->enc_param_start_band = add(hQMetaData->q_direction[0].cfg.start_band , spar_dirac_split_band); + } + + hConfig->dec_param_estim = TRUE; + IF (hConfig->dec_param_estim == TRUE) + { + hConfig->enc_param_start_band = spar_dirac_split_band; + } + + IF (ivas_get_hodirac_flag(ivas_total_brate, sba_order)) + { + hConfig->dec_param_estim = FALSE; + hConfig->enc_param_start_band = 0; + + set_c((int8_t *)hQMetaData->twoDirBands, (int8_t)1, hQMetaData->q_direction[0].cfg.nbands); + hQMetaData->numTwoDirBands = (uint8_t)hQMetaData->q_direction[0].cfg.nbands; + } + } + + IF (ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) + { + //100861_dirac_dec + ivas_dirac_config_bands(band_grouping, IVAS_MAX_NUM_BANDS, (Word16)(Fs * INV_CLDFB_BANDWIDTH + 0.5f), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft); + } + ELSE + { + ivas_dirac_config_bands(band_grouping, hConfig->nbands, (Word16)(Fs * INV_CLDFB_BANDWIDTH + 0.5f), NULL, 0, 0, hFbMdft); + } + + return error; +} +#endif ivas_error ivas_dirac_config( void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ @@ -388,7 +518,7 @@ void ivas_dirac_config_bands_fx( { Word16 step = DIRAC_LOW_BANDRES_STEP; Word16 reduced_band; - for ( band = enc_param_start_band + 2, reduced_band = enc_param_start_band + 1; band <= DIRAC_MAX_NBANDS; band += step, reduced_band++ ) + for ( band = add(enc_param_start_band , 2), reduced_band = add(enc_param_start_band , 1); band <= DIRAC_MAX_NBANDS; band = add(band, step), reduced_band++ ) { band_grouping[reduced_band] = band_grouping[band]; } @@ -433,81 +563,248 @@ void ivas_dirac_config_bands_fx( * Return maximum SBA DirAC metadata bit-budget and nominal bit-budget *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_get_dirac_sba_max_md_bits_fx( + const Word32 sba_total_brate, + Word16 *bits_frame_nominal, + Word16 *metadata_max_bits, + Word16 *qmetadata_max_bit_req, + const Word16 nbands, + IVAS_FORMAT ivas_format ) +{ + IF ( sba_total_brate <= IVAS_13k2 ) + { + *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; + *metadata_max_bits = 70; + } + ELSE IF ( sba_total_brate <= IVAS_16k4 ) + { + *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; + *metadata_max_bits = 80; + } + ELSE IF ( sba_total_brate <= IVAS_24k4 ) + { + *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; + *metadata_max_bits = 103; + /* OSBA needs an additional 2-bits safety margin to avoid acelp crashes */ + IF ( ivas_format == SBA_ISM_FORMAT ) + { + ( *metadata_max_bits ) = sub((*metadata_max_bits), 3); + } + } + ELSE IF ( sba_total_brate <= IVAS_32k ) + { + *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC; + *metadata_max_bits = 214; + } + ELSE IF ( sba_total_brate <= IVAS_48k ) + { + *bits_frame_nominal = IVAS_48k / FRAMES_PER_SEC; + *metadata_max_bits = 240; + } + ELSE IF ( sba_total_brate <= IVAS_64k ) + { + *bits_frame_nominal = IVAS_64k / FRAMES_PER_SEC; + *metadata_max_bits = 200; + } + ELSE IF ( sba_total_brate <= IVAS_80k ) + { + *bits_frame_nominal = IVAS_80k / FRAMES_PER_SEC; + *metadata_max_bits = 200; + } + ELSE IF ( sba_total_brate <= IVAS_96k ) + { + *bits_frame_nominal = IVAS_96k / FRAMES_PER_SEC; + *metadata_max_bits = 200; + } + ELSE IF ( sba_total_brate <= IVAS_128k ) + { + *bits_frame_nominal = IVAS_128k / FRAMES_PER_SEC; + *metadata_max_bits = 250; + } + ELSE + { + //*bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC ); + Word16 tmp_exp = 0, tmp; + tmp = BASOP_Util_Divide3232_Scale(sba_total_brate, FRAMES_PER_SEC, &tmp_exp); + *bits_frame_nominal = shr(tmp, 15 - tmp_exp); + *metadata_max_bits = MAX16B; /* no limit */ + } + Word32 var1 = L_mult0(*metadata_max_bits, nbands); + Word16 exp = 0; + Word16 var2 = BASOP_Util_Divide3232_Scale(var1, 5, &exp); + Word32 var2_32 = L_deposit_h(var2); + Word32 var4 = var2_32; + + Word16 exp_res = 0; + IF (var1 % 5 != 0) { + var4 = BASOP_Util_Add_Mant32Exp(var2_32, exp, ONE_IN_Q30, 1, &exp_res); + } + *metadata_max_bits = extract_l(L_min(MAX16B, L_shr(var4, 14))); + *qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA >> 1; + + return; +} +#endif + void ivas_get_dirac_sba_max_md_bits( const int32_t sba_total_brate, int16_t *bits_frame_nominal, int16_t *metadata_max_bits, int16_t *qmetadata_max_bit_req, const int16_t nbands, - IVAS_FORMAT ivas_format ) + IVAS_FORMAT ivas_format) { - if ( sba_total_brate <= IVAS_13k2 ) + if (sba_total_brate <= IVAS_13k2) { *bits_frame_nominal = ACELP_9k60 / FRAMES_PER_SEC; *metadata_max_bits = 70; } - else if ( sba_total_brate <= IVAS_16k4 ) + else if (sba_total_brate <= IVAS_16k4) { *bits_frame_nominal = ACELP_13k20 / FRAMES_PER_SEC; *metadata_max_bits = 80; } - else if ( sba_total_brate <= IVAS_24k4 ) + else if (sba_total_brate <= IVAS_24k4) { *bits_frame_nominal = ACELP_16k40 / FRAMES_PER_SEC; *metadata_max_bits = 103; /* OSBA needs an additional 2-bits safety margin to avoid acelp crashes */ - if ( ivas_format == SBA_ISM_FORMAT ) + if (ivas_format == SBA_ISM_FORMAT) { - ( *metadata_max_bits ) -= 3; + (*metadata_max_bits) -= 3; } } - else if ( sba_total_brate <= IVAS_32k ) + else if (sba_total_brate <= IVAS_32k) { *bits_frame_nominal = ACELP_32k / FRAMES_PER_SEC; *metadata_max_bits = 214; } - else if ( sba_total_brate <= IVAS_48k ) + else if (sba_total_brate <= IVAS_48k) { *bits_frame_nominal = IVAS_48k / FRAMES_PER_SEC; *metadata_max_bits = 240; } - else if ( sba_total_brate <= IVAS_64k ) + else if (sba_total_brate <= IVAS_64k) { *bits_frame_nominal = IVAS_64k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - else if ( sba_total_brate <= IVAS_80k ) + else if (sba_total_brate <= IVAS_80k) { *bits_frame_nominal = IVAS_80k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - else if ( sba_total_brate <= IVAS_96k ) + else if (sba_total_brate <= IVAS_96k) { *bits_frame_nominal = IVAS_96k / FRAMES_PER_SEC; *metadata_max_bits = 200; } - else if ( sba_total_brate <= IVAS_128k ) + else if (sba_total_brate <= IVAS_128k) { *bits_frame_nominal = IVAS_128k / FRAMES_PER_SEC; *metadata_max_bits = 250; } else { - *bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC ); + *bits_frame_nominal = (int16_t)(sba_total_brate / FRAMES_PER_SEC); *metadata_max_bits = MAX16B; /* no limit */ } - *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( (float) *metadata_max_bits * nbands / 5 ) ); + *metadata_max_bits = (int16_t)min((float)MAX16B, ceilf((float)*metadata_max_bits * nbands / 5)); *qmetadata_max_bit_req = QMETADATA_MAXBIT_REQ_SBA >> 1; return; } - /*------------------------------------------------------------------------- * ivas_dirac_sba_config() * * DirAC Configuration function for SBA *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_sba_config_fx( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + Word16 *element_mode, /* i/o: element mode of the core coder */ + Word32 sba_total_brate, /* i : SBA total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 nbands /* i : number of frequency bands */ + , + IVAS_FORMAT ivas_format) +{ + Word16 nbands_coded; + Word16 hodirac_flag; + ivas_error error; + + Word32 tmp1 = IVAS_192k; + Word32 tmp2 = SPAR_DIRAC_SPLIT_START_BAND; + Word16 exp = 0; + Word16 tmp3 = BASOP_Util_Divide3232_Scale(tmp1, tmp2, &exp); + Word32 res = L_shr(L_deposit_h(tmp3), 31 - exp); + + error = IVAS_ERR_OK; + hQMetaData->is_masa_ivas_format = 0; + hodirac_flag = ivas_get_hodirac_flag(sba_total_brate, sba_order);//implemented on 100861_dirac_dec + + /* map the bitrate for SID frame */ + IF (EQ_32(sba_total_brate , IVAS_SID_5k2)) + { + IF (EQ_16(*element_mode , IVAS_SCE)) + { + sba_total_brate = ACELP_24k40; + } + ELSE + { + sba_total_brate = ACELP_48k; + } + } + + ivas_set_qmetadata_maxbit_req(hQMetaData, SBA_FORMAT); + + IF (LE_32(sba_total_brate , IVAS_16k4)) + { + hQMetaData->useLowerRes = 1; + } + ELSE + { + hQMetaData->useLowerRes = 0; + } + + nbands_coded = nbands; + + IF (LE_32(sba_total_brate , res)) + { + hQMetaData->useLowerBandRes = 1; + Word16 tmp = nbands % 2; + nbands_coded = add(shr(nbands, 1) , tmp); + } + ELSE + { + hQMetaData->useLowerBandRes = 0; + IF (hodirac_flag == 0) + { + nbands_coded = nbands - 1; /* always combine the last two bands */ + } + } + + { + Word16 no_dirs = 1; + IF (hodirac_flag) + { + no_dirs = 2; + } + + IF ((error = ivas_qmetadata_allocate_memory(hQMetaData, nbands_coded, no_dirs, 0)) != IVAS_ERR_OK)//WIP + { + return error; + } + } + + ivas_get_dirac_sba_max_md_bits_fx(sba_total_brate, &hQMetaData->bits_frame_nominal, &hQMetaData->metadata_max_bits, &hQMetaData->qmetadata_max_bit_req, hQMetaData->q_direction[0].cfg.nbands, + ivas_format); + + return error; +} +#endif ivas_error ivas_dirac_sba_config( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -584,7 +881,6 @@ ivas_error ivas_dirac_sba_config( return error; } - /*------------------------------------------------------------------------- * computeDirectionVectors() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 70ae03053..5aa7794b1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3634,6 +3634,14 @@ int16_t ivas_sba_get_order( const int16_t sba_planar /* i : SBA planar flag */ ); +#ifdef IVAS_FLOAT_FIXED +Word16 ivas_sba_get_order_fx( + const Word16 nb_channels, /* i : Number of ambisonic channels */ + const Word16 sba_planar /* i : SBA planar flag */ +); + +#endif + /*! r: Ambisonic (SBA) order used for analysis and coding */ int16_t ivas_sba_get_analysis_order( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -3849,6 +3857,10 @@ void generate_masking_noise_lb_dirac( ); #ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_close_fx( + DIRAC_DEC_HANDLE *hDirAC_out +); + void ivas_dirac_dec_set_md_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nCldfbTs /* i : number of CLDFB time slots */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ce448c575..e0e873bda 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1090,4 +1090,27 @@ void stereo_dft_dmx_out_reset_fx( STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ ); +void ivas_get_dirac_sba_max_md_bits_fx( + const Word32 sba_total_brate, + Word16 *bits_frame_nominal, + Word16 *metadata_max_bits, + Word16 *qmetadata_max_bit_req, + const Word16 nbands, + IVAS_FORMAT ivas_format); + +ivas_error ivas_dirac_sba_config_fx( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + Word16 *element_mode, /* i/o: element mode of the core coder */ + Word32 sba_total_brate, /* i : SBA total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 nbands /* i : number of frequency bands */ + , + IVAS_FORMAT ivas_format); + +ivas_error ivas_dirac_config_fx( + void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ + const Word16 enc_dec /* i : encoder or decoder flag */ +); #endif + + diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 6f9941de3..6679ad3b3 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -115,7 +115,6 @@ void ivas_sba_config( } #ifdef IVAS_FLOAT_FIXED -/*not tested*/ void ivas_sba_config_fx( const Word32 sba_total_brate, /* i : SBA total bitrate */ Word16 sba_order, /* i : Ambisonic (SBA) order */ @@ -133,11 +132,11 @@ void ivas_sba_config_fx( } ELSE IF( LT_16( sba_order, 0 ) ) { - sba_order = ivas_sba_get_order( nb_channels, sba_planar ); + sba_order = ivas_sba_get_order_fx( nb_channels, sba_planar ); } ELSE IF( LT_16( nb_channels, 0 ) ) { - nb_channels = ivas_sba_get_nchan_fx( sba_order, sba_planar ); + nb_channels = (Word16)ivas_sba_get_nchan_fx( sba_order, sba_planar ); } ELSE { @@ -225,7 +224,7 @@ Word16 ivas_sba_get_order_fx( } ELSE { - sba_order = sub( Sqrt16( nb_channels, &exp ), MAX16B); // 15 - exp + sba_order = sub( Sqrt16( nb_channels, &exp ), MAX16B ); // 15 - exp assert( ( EQ_16( mult( add( sba_order, 1 ), add( sba_order, 1 ) ), nb_channels ) ) && "Number of channels not supported in SBA!" ); } @@ -301,7 +300,7 @@ Word16 ivas_sba_get_nchan_fx( } ELSE { - nb_channels = mult(add(sba_order , 1) , (sba_order + 1)); + nb_channels = mult0(add(sba_order , 1) , add(sba_order , 1)); } return (nb_channels); diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 11bb7f932..5f5fc4b9e 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1880,6 +1880,7 @@ void ivas_dirac_dec_get_response( * * Block Q of 29 is maintained * calculate reponse, 1 degree resolution + * Input azimuth and elevation are expected in Q0 *------------------------------------------------------------------------*/ void ivas_dirac_dec_get_response_fixed( diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 96c53e8eb..f018c1198 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -55,7 +55,63 @@ /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_dirac_dec_config_internal_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +) +{ + DIRAC_DEC_HANDLE hDirAC; + ivas_error error; + DIRAC_CONFIG_FLAG flag_config; + + flag_config = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + error = IVAS_ERR_OK; + + hDirAC = NULL; + + IF (flag_config == DIRAC_RECONFIGURE) + { + hDirAC = st_ivas->hDirAC; + } + ELSE IF (flag_config == DIRAC_OPEN) + { + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + IF ((hDirAC = (DIRAC_DEC_HANDLE)malloc(sizeof(DIRAC_DEC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); + } + + IF ((hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE)malloc(sizeof(DIRAC_CONFIG_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n")); + } + + st_ivas->hDirAC = hDirAC; + } + + /*-----------------------------------------------------------------* + * DirAC main configuration + *-----------------------------------------------------------------*/ + + IF ((error = ivas_dirac_config((void *)st_ivas, DEC)) != IVAS_ERR_OK) + { + return error; + } + + IF (flag_config == DIRAC_OPEN) + { + hDirAC->spar_to_dirac_write_idx = (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) ? DELAY_DIRAC_PARAM_DEC_SFR : 0; + hDirAC->dithering_seed = DIRAC_DITH_SEED; + st_ivas->hDirAC = hDirAC; + } + return error; +} +#else static ivas_error ivas_dirac_dec_config_internal( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ @@ -111,68 +167,837 @@ static ivas_error ivas_dirac_dec_config_internal( return error; } +#endif - -static ivas_error ivas_dirac_rend_config( +#ifdef IVAS_FLOAT_FIXED +static ivas_error ivas_dirac_rend_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ - const int16_t dec_param_estim_old ) + const Word16 dec_param_estim_old ) { DIRAC_DEC_HANDLE hDirAC; - int16_t nchan_out_woLFE; - int16_t nchan_transport; - int16_t nchan_transport_old; - int16_t num_outputs_dir_old; - int16_t num_outputs_diff_old; - int16_t num_protos_diff_old; + Word16 nchan_out_woLFE; + Word16 nchan_transport; + Word16 nchan_transport_old; + Word16 num_outputs_dir_old; + Word16 num_outputs_diff_old; + Word16 num_protos_diff_old; + /*Todo: remove float code*/ float *proto_frame_f_old; - int16_t proto_signal_decorr_on_old; +#ifdef IVAS_FLOAT_FIXED + Word16 *proto_frame_f_old_fx; +#endif + Word16 proto_signal_decorr_on_old; uint16_t i, j, k; - float ls_azimuth[MAX_OUTPUT_CHANNELS]; - float ls_elevation[MAX_OUTPUT_CHANNELS]; + Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; + Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; int32_t output_Fs, ivas_total_brate; ivas_error error; - int16_t nchan_transport_orig; - int16_t hodirac_flag; + Word16 nchan_transport_orig; + Word16 hodirac_flag; DIRAC_CONFIG_FLAG flag_config; DIRAC_REND_HANDLE hDirACRend; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; #ifdef IVAS_FLOAT_FIXED - Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; - Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; - FOR ( i = 0; i < MAX_OUTPUT_CHANNELS; i++) { - ls_azimuth[i] = 0.0f; - ls_elevation[i] = 0.0f; + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { ls_azimuth_fx[i] = 0; ls_elevation_fx[i] = 0; } #endif - flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + flag_config = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; + error = IVAS_ERR_OK; + + hDirACRend = NULL; + output_Fs = st_ivas->hDecoderConfig->output_Fs; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ); + + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) + { + hDirACRend = st_ivas->hDirACRend; + } + ELSE IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + IF( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) ); + } + + nchan_transport_old = 0; + } + + nchan_transport_old = 0; + num_outputs_dir_old = 0; + num_outputs_diff_old = 0; + num_protos_diff_old = 0; + + nchan_transport_orig = st_ivas->nchan_transport; + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + } + + nchan_transport = st_ivas->nchan_transport; + IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + nchan_transport = 1; + } + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + { + Word16 tmp1, tmp2, tmp3; + ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); + } + + /*-----------------------------------------------------------------* + * output setup: for parametric binaural renderer, use output setup, otherwise internal setup + *-----------------------------------------------------------------*/ + + hDirACRend->hOutSetup = st_ivas->hIntSetup; + nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; + + IF( hDirACRend->hOutSetup.ls_azimuth_fx != NULL && hDirACRend->hOutSetup.ls_elevation != NULL ) + { + Copy32( hDirACRend->hOutSetup.ls_azimuth_fx, ls_azimuth_fx, nchan_out_woLFE ); + Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE ); + } + + IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, negate( (Word16) 1 ) ) ) + { + hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ + IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + { + hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; + } + } + + ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) ) + { + Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); + Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); + } + + IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) + { + /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ + hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 ); + nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; + Copy32( &ls_azimuth_fx[add( hDirACRend->hOutSetup.separateChannelIndex, 1 )], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); + Copy32( &ls_elevation_fx[add( hDirACRend->hOutSetup.separateChannelIndex, 1 )], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); + } + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + + st_ivas->nchan_transport = nchan_transport_orig; + + IF( GT_16( nchan_transport_orig, 2 ) && hDirACRend->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && !hodirac_flag ) + { + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + hDirACRend->panningConf = DIRAC_PANNING_VBAP; + } + ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) + { + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; + hDirACRend->panningConf = DIRAC_PANNING_HOA3; + nchan_out_woLFE = 1; + } + ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) + { + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + hDirACRend->panningConf = DIRAC_PANNING_VBAP; + } + ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_32( st_ivas->nchan_transport, 1 ) ) + { + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; + hDirACRend->panningConf = DIRAC_PANNING_HOA3; + } + ELSE + { + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; + hDirACRend->panningConf = DIRAC_PANNING_HOA3; + } + + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { +#ifdef TRUE + /*TODO : remove float code*/ + if ( ( hDirACRend->frequency_axis = (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( hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands ); +#endif + IF( ( hDirACRend->frequency_axis_fx = (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( hDirACRend->frequency_axis_fx, 0, hSpatParamRendCom->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis_fx( hDirACRend->frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands ); + + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + hDirACRend->frequency_axis[i] = (float) hDirACRend->frequency_axis_fx[i]; + } + } + + IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) && EQ_16( nchan_transport, 2 ) ) + { + IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect == NULL ) || EQ_16( flag_config, DIRAC_OPEN ) ) + { + IF( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + ivas_masa_init_stereotype_detection_fx( hDirACRend->masa_stereo_type_detect ); + } + ELSE + { + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL ) + { + free( hDirACRend->masa_stereo_type_detect ); + } + hDirACRend->masa_stereo_type_detect = NULL; + } + + hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */ + + /*-----------------------------------------------------------------* + * (re)configure sub-modules + *-----------------------------------------------------------------*/ + + /* prototype signal computation */ + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) + { + num_outputs_dir_old = hDirACRend->num_outputs_dir; + num_outputs_diff_old = hDirACRend->num_outputs_diff; + num_protos_diff_old = hDirACRend->num_protos_diff; + } + + /* allocate output setup related arrays */ + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) + { + /* Directional and diffuses components in output LS format */ + hDirACRend->num_outputs_diff = nchan_out_woLFE; + hDirACRend->num_outputs_dir = nchan_out_woLFE; + } + ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + /* Directional and diffuses components in SHD */ + /* Diffuseness components up to 1st order */ + hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); + } + ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) + { + hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; + hDirACRend->num_outputs_dir = nchan_out_woLFE; + } + ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + { + hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ + } + ELSE + { + assert( 0 && "DirAC: not existing synthesis methods!" ); + } + + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + num_outputs_dir_old = hDirACRend->num_outputs_dir; + IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + num_outputs_diff_old = hDirACRend->num_outputs_diff; + IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + + IF( NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) ) + { + free( hDirACRend->proto_index_dir ); + IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir ); + + IF( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) ) + { + free( hDirACRend->proto_index_diff ); + IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + set16_fx( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff ); + + hDirACRend->sba_map_tc = sba_map_tc; + + IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + { + IF( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) ) + { + hDirACRend->sba_map_tc = sba_map_tc_512; + } + } + + IF( EQ_16( nchan_transport, 1 ) ) + { + hDirACRend->num_protos_ambi = 1; + hDirACRend->num_protos_dir = 1; + hDirACRend->num_protos_diff = 1; + } + ELSE IF( EQ_16( nchan_transport, 2 ) ) + { + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + hDirACRend->num_protos_ambi = 2; + hDirACRend->num_protos_diff = 1; + hDirACRend->num_protos_dir = 2; + hDirACRend->proto_index_dir[1] = 1; + } + ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) + { + /* Following the foa rendering for code compatibility */ + hDirACRend->num_protos_ambi = 2; + hDirACRend->num_protos_dir = 2; + hDirACRend->num_protos_diff = 3; + hDirACRend->proto_index_dir[0] = 0; + hDirACRend->proto_index_diff[0] = 0; + } + ELSE + { + hDirACRend->num_protos_ambi = 2; + hDirACRend->num_protos_diff = 3; + + FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) + { + IF( GT_32( ls_azimuth_fx[k], 0 ) ) + { + hDirACRend->proto_index_diff[k] = 1; + } + ELSE IF( LT_32( ls_azimuth_fx[k], 0 ) ) + { + hDirACRend->proto_index_diff[k] = 2; + } + ELSE + { + hDirACRend->proto_index_diff[k] = 0; + } + } + + IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) + { + hDirACRend->num_protos_dir = 3; + Copy( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE ); + } + ELSE + { + hDirACRend->num_protos_dir = 2; + hDirACRend->proto_index_dir[1] = 1; + } + } + } + ELSE /* nchan_transport > 2 */ + { + hDirACRend->num_protos_ambi = 4; + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) + { + hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff; + FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) + { + hDirACRend->proto_index_diff[k] = k; + } + + hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir; + FOR( k = 0; k < hDirACRend->num_outputs_dir; k++ ) + { + hDirACRend->proto_index_dir[k] = k; + } + } + ELSE + { + hDirACRend->num_protos_diff = 1; + hDirACRend->num_protos_dir = nchan_transport; + + FOR( k = 0; k < s_min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ ) + { + IF( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir ) + { + hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k; + } + } + } + } + + /* direct/diffuse responses */ + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { +#ifdef TRUE + /*Todo : to clean up float code*/ + IF( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } +#endif + IF( ( hDirACRend->diffuse_response_function_fx = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + /* reallocate static memory */ + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) ) + { +#ifdef TRUE + /*Todo : Remove float code*/ + free( hDirACRend->diffuse_response_function ); + hDirACRend->diffuse_response_function = NULL; + IF( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } +#endif + free( hDirACRend->diffuse_response_function_fx ); + hDirACRend->diffuse_response_function_fx = NULL; + IF( ( hDirACRend->diffuse_response_function_fx = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) ) + { + initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config ); + + FOR( i = 0; i < hDirACRend->num_outputs_dir; i++ ) + { + hDirACRend->diffuse_response_function[i] = fix16_to_float( hDirACRend->diffuse_response_function_fx[i], 15 ); + } + } + ELSE + { + initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID ); + + FOR( i = 0; i < hDirACRend->num_outputs_dir; i++ ) + { + hDirACRend->diffuse_response_function[i] = fix16_to_float( hDirACRend->diffuse_response_function_fx[i], 15 ); + } + } + + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) + { +#ifdef TRUE + /*TODO : to remove float code*/ + if ( EQ_16( flag_config, DIRAC_OPEN ) ) + { + if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + else if ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder && ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) + { + free( hDirACRend->hoa_encoder ); + hDirACRend->hoa_encoder = NULL; + if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + set_f( hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff ); +#endif + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder && ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) + { + free( hDirACRend->hoa_encoder_fx ); + hDirACRend->hoa_encoder_fx = NULL; + IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff ); + + compute_hoa_encoder_mtx_fx( ls_azimuth_fx, ls_elevation_fx, hDirACRend->hoa_encoder_fx, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); + FOR( i = 0; i < nchan_out_woLFE * hDirACRend->num_outputs_diff; i++ ) + { + hDirACRend->hoa_encoder[i] = fix_to_float( hDirACRend->hoa_encoder_fx[i], Q29 ); + } + } + ELSE + { +#ifdef TRUE + /*todo: clean up float code*/ + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder ) + { + free( hDirACRend->hoa_encoder ); + } + hDirACRend->hoa_encoder = NULL; +#endif + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx ) + { + free( hDirACRend->hoa_encoder_fx ); + } + hDirACRend->hoa_encoder_fx = NULL; + } + + /* VBAP */ + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + st_ivas->hVBAPdata = NULL; + } + + IF( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) + { + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) + { + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); + } + IF( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + { + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) + { + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); + } + hDirACRend->hoa_decoder = NULL; + } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) + { + vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); + } + + /* HOA panning/dec */ + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + hDirACRend->hoa_decoder = NULL; + IF( ( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( GT_16( nchan_transport, 2 ) ) ) + { + IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) + { + IF( st_ivas->hoa_dec_mtx != NULL ) + { + free( st_ivas->hoa_dec_mtx ); + st_ivas->hoa_dec_mtx = NULL; + } + IF( ( error = ivas_sba_get_hoa_dec_matrix( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } + + hDirACRend->hoa_decoder = st_ivas->hoa_dec_mtx; + } + } + } + + /* decorrelation */ + proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0; + hDirACRend->proto_signal_decorr_on = 1; + IF( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) ) + { + /*switch off decorrelation for 4 transport channels*/ + hDirACRend->proto_signal_decorr_on = 0; + } + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + { + hDirACRend->proto_signal_decorr_on = 0; + } + + IF( ( EQ_16( flag_config, DIRAC_OPEN && hDirACRend->proto_signal_decorr_on ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) + { + /*WIP*/ + IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) + { + /*WIP*/ + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) + { + IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + /* close and reopen the decorrelator */ + /*WIP*/ + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + /*WIP*/ + IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* output synthesis */ + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + } + ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) + { + ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); + + IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + } + + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; + } + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + /*TODO : remove float code*/ + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) + { + free( hDirACRend->proto_frame_f_fx ); + free( hDirACRend->proto_frame_f ); + } + hDirACRend->proto_frame_f_fx = NULL; + hDirACRend->proto_frame_f = NULL; + } + ELSE + { + IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) + { + IF( ( hDirACRend->proto_frame_f_fx = (Word16 *) malloc( sizeof( Word16 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + { + proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; + free( proto_frame_f_old_fx ); + IF( ( hDirACRend->proto_frame_f_fx = (Word16 *) malloc( sizeof( Word16 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } +#ifdef TRUE + /*Todo : to remove float code*/ + if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) + { + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) + { + proto_frame_f_old = hDirACRend->proto_frame_f; + free( proto_frame_f_old ); + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } +#endif + } + + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + hDirACRend->buffer_energy_fx = NULL; + hDirACRend->buffer_energy = NULL; + } + + IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) + { + hDirACRend->index_buffer_intensity = 0; + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set16_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } + IF( hDirACRend->buffer_energy_fx == NULL ) + { + IF( ( hDirACRend->buffer_energy_fx = (Word16 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + set16_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); +#ifdef TRUE + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + if ( ( hDirACRend->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); + } + } + if ( hDirACRend->buffer_energy == NULL ) + { + if ( ( hDirACRend->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + set_f( hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); +#endif + } + ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) + { + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) + { + free( hDirACRend->buffer_intensity_real_fx[i][j] ); + } + hDirACRend->buffer_intensity_real_fx[i][j] = NULL; + } + } + IF( hDirACRend->buffer_energy_fx != NULL ) + { + free( hDirACRend->buffer_energy_fx ); + hDirACRend->buffer_energy_fx = NULL; + } +#ifdef TRUE + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j] ) + { + free( hDirACRend->buffer_intensity_real[i][j] ); + } + hDirACRend->buffer_intensity_real[i][j] = NULL; + } + } + if ( hDirACRend->buffer_energy != NULL ) + { + free( hDirACRend->buffer_energy ); + hDirACRend->buffer_energy = NULL; + } +#endif + } + /* output synthesis */ + ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); + + /* Allocate stack memory */ + IF( NE_16( flag_config, DIRAC_OPEN ) ) + { + ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); + } + IF( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + st_ivas->hDirACRend = hDirACRend; + } + + return error; +} +#endif + +static ivas_error ivas_dirac_rend_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + const int16_t dec_param_estim_old) +{ + DIRAC_DEC_HANDLE hDirAC; + int16_t nchan_out_woLFE; + int16_t nchan_transport; + int16_t nchan_transport_old; + int16_t num_outputs_dir_old; + int16_t num_outputs_diff_old; + int16_t num_protos_diff_old; + float *proto_frame_f_old; + int16_t proto_signal_decorr_on_old; + uint16_t i, j, k; + float ls_azimuth[MAX_OUTPUT_CHANNELS]; + float ls_elevation[MAX_OUTPUT_CHANNELS]; + int32_t output_Fs, ivas_total_brate; + ivas_error error; + int16_t nchan_transport_orig; + int16_t hodirac_flag; + DIRAC_CONFIG_FLAG flag_config; + DIRAC_REND_HANDLE hDirACRend; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + flag_config = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; error = IVAS_ERR_OK; hDirACRend = NULL; output_Fs = st_ivas->hDecoderConfig->output_Fs; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); + hodirac_flag = ivas_get_hodirac_flag(ivas_total_brate, st_ivas->sba_analysis_order); hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; - if ( flag_config == DIRAC_RECONFIGURE ) + if (flag_config == DIRAC_RECONFIGURE) { hDirACRend = st_ivas->hDirACRend; } - else if ( flag_config == DIRAC_OPEN ) + else if (flag_config == DIRAC_OPEN) { /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL ) + if ((hDirACRend = (DIRAC_REND_HANDLE)malloc(sizeof(DIRAC_REND_DATA))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n")); } nchan_transport_old = 0; @@ -184,20 +1009,20 @@ static ivas_error ivas_dirac_rend_config( num_protos_diff_old = 0; nchan_transport_orig = st_ivas->nchan_transport; - if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + if (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) { - st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->nchan_transport = ivas_sba_get_nchan_metadata(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate); } nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 ) + if (st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2) { nchan_transport = 1; } - if ( flag_config == DIRAC_RECONFIGURE && ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ) + if (flag_config == DIRAC_RECONFIGURE && (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT)) { int16_t tmp1, tmp2, tmp3; - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); + ivas_sba_config(ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3); } /*-----------------------------------------------------------------* @@ -207,33 +1032,33 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->hOutSetup = st_ivas->hIntSetup; nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - if ( hDirACRend->hOutSetup.ls_azimuth != NULL && hDirACRend->hOutSetup.ls_elevation != NULL ) + if (hDirACRend->hOutSetup.ls_azimuth != NULL && hDirACRend->hOutSetup.ls_elevation != NULL) { - mvr2r( hDirACRend->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE ); - mvr2r( hDirACRend->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE ); + mvr2r(hDirACRend->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE); + mvr2r(hDirACRend->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE); } - if ( hDirACRend->hOutSetup.ambisonics_order == -1 ) + if (hDirACRend->hOutSetup.ambisonics_order == -1) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ - if ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_STEREO ) + if (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_STEREO) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; } } - else if ( hDirACRend->hOutSetup.ambisonics_order >= SBA_FOA_ORDER ) + else if (hDirACRend->hOutSetup.ambisonics_order >= SBA_FOA_ORDER) { - mvr2r( ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); - mvr2r( ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); + mvr2r(ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS); + mvr2r(ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS); } - if ( hDirACRend->hOutSetup.separateChannelEnabled && ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_2 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_4 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1_4 || ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) + if (hDirACRend->hOutSetup.separateChannelEnabled && (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_2 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_5_1_4 || hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_7_1_4 || (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found))) { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE--; nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - mvr2r( &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex ); - mvr2r( &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex ); + mvr2r(&ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex); + mvr2r(&ls_elevation[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex); } /*-----------------------------------------------------------------* @@ -242,23 +1067,23 @@ static ivas_error ivas_dirac_rend_config( st_ivas->nchan_transport = nchan_transport_orig; - if ( nchan_transport_orig > 2 && hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag ) + if (nchan_transport_orig > 2 && hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; hDirACRend->panningConf = DIRAC_PANNING_VBAP; } - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO ) + else if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA) && hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; hDirACRend->panningConf = DIRAC_PANNING_HOA3; nchan_out_woLFE = 1; } - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) + else if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA) && hDirACRend->hOutSetup.is_loudspeaker_setup) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; hDirACRend->panningConf = DIRAC_PANNING_VBAP; } - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) + else if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT) && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; hDirACRend->panningConf = DIRAC_PANNING_HOA3; @@ -269,43 +1094,32 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->panningConf = DIRAC_PANNING_HOA3; } - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { - if ( ( hDirACRend->frequency_axis = (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( hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands ); - -#ifdef IVAS_FLOAT_FIXED - Word16 *frequency_axis_fx = (Word16 *) malloc(hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ); - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands ); - - FOR ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++) + if ((hDirACRend->frequency_axis = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) { - hDirACRend->frequency_axis[i] = ( float ) frequency_axis_fx[i]; + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } -#else - ivas_dirac_dec_get_frequency_axis( hDirACRend->frequency_axis, output_Fs, hSpatParamRendCom->num_freq_bands ); -#endif + set_f(hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands); + ivas_dirac_dec_get_frequency_axis(hDirACRend->frequency_axis, output_Fs, hSpatParamRendCom->num_freq_bands); } - if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2 ) + if ((st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA) && hDirACRend->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2) { - if ( ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN ) + if ((flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect == NULL) || flag_config == DIRAC_OPEN) { - if ( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) + if ((hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *)malloc(sizeof(MASA_STEREO_TYPE_DETECT))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect ); + ivas_masa_init_stereotype_detection(hDirACRend->masa_stereo_type_detect); } else { - if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect != NULL ) + if (flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect != NULL) { - free( hDirACRend->masa_stereo_type_detect ); + free(hDirACRend->masa_stereo_type_detect); } hDirACRend->masa_stereo_type_detect = NULL; } @@ -316,8 +1130,8 @@ static ivas_error ivas_dirac_rend_config( * (re)configure sub-modules *-----------------------------------------------------------------*/ - /* prototype signal computation */ - if ( flag_config == DIRAC_RECONFIGURE ) + /* prototype signal computation */ + if (flag_config == DIRAC_RECONFIGURE) { num_outputs_dir_old = hDirACRend->num_outputs_dir; num_outputs_diff_old = hDirACRend->num_outputs_diff; @@ -325,94 +1139,94 @@ static ivas_error ivas_dirac_rend_config( } /* allocate output setup related arrays */ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS) { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; hDirACRend->num_outputs_dir = nchan_out_woLFE; } - else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) { /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ - hDirACRend->num_outputs_diff = ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ); - hDirACRend->num_outputs_dir = ivas_sba_get_nchan( hDirACRend->hOutSetup.ambisonics_order, 0 ); + hDirACRend->num_outputs_diff = (min(hDirACRend->hOutSetup.ambisonics_order, 1) + 1) * (min(hDirACRend->hOutSetup.ambisonics_order, 1) + 1); + hDirACRend->num_outputs_dir = ivas_sba_get_nchan(hDirACRend->hOutSetup.ambisonics_order, 0); } - else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; hDirACRend->num_outputs_dir = nchan_out_woLFE; } - else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) { hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ } else { - assert( 0 && "DirAC: not existing synthesis methods!" ); + assert(0 && "DirAC: not existing synthesis methods!"); } - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { num_outputs_dir_old = hDirACRend->num_outputs_dir; - if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL ) + if ((hDirACRend->proto_index_dir = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_dir)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } num_outputs_diff_old = hDirACRend->num_outputs_diff; - if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL ) + if ((hDirACRend->proto_index_diff = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_diff)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - if ( hDirACRend->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) + if (hDirACRend->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE) { - free( hDirACRend->proto_index_dir ); - if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL ) + free(hDirACRend->proto_index_dir); + if ((hDirACRend->proto_index_dir = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_dir)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - set_s( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir ); + set_s(hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir); - if ( hDirACRend->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE ) + if (hDirACRend->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE) { - free( hDirACRend->proto_index_diff ); - if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL ) + free(hDirACRend->proto_index_diff); + if ((hDirACRend->proto_index_diff = (int16_t *)malloc(sizeof(int16_t) * hDirACRend->num_outputs_diff)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - set_s( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff ); + set_s(hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff); hDirACRend->sba_map_tc = sba_map_tc; - if ( ( st_ivas->ivas_format == SBA_FORMAT ) || ( st_ivas->ivas_format == SBA_ISM_FORMAT ) ) + if ((st_ivas->ivas_format == SBA_FORMAT) || (st_ivas->ivas_format == SBA_ISM_FORMAT)) { - if ( st_ivas->sba_order > SBA_FOA_ORDER && ivas_total_brate >= IVAS_512k ) + if (st_ivas->sba_order > SBA_FOA_ORDER && ivas_total_brate >= IVAS_512k) { hDirACRend->sba_map_tc = sba_map_tc_512; } } - if ( nchan_transport == 1 ) + if (nchan_transport == 1) { hDirACRend->num_protos_ambi = 1; hDirACRend->num_protos_dir = 1; hDirACRend->num_protos_diff = 1; } - else if ( nchan_transport == 2 ) + else if (nchan_transport == 2) { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) { hDirACRend->num_protos_ambi = 2; hDirACRend->num_protos_diff = 1; hDirACRend->num_protos_dir = 2; hDirACRend->proto_index_dir[1] = 1; } - else if ( hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO ) + else if (hDirACRend->hOutSetup.output_config == IVAS_AUDIO_CONFIG_MONO) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; @@ -426,13 +1240,13 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->num_protos_ambi = 2; hDirACRend->num_protos_diff = 3; - for ( k = 0; k < hDirACRend->num_outputs_diff; k++ ) + for (k = 0; k < hDirACRend->num_outputs_diff; k++) { - if ( ls_azimuth[k] > 0.0f ) + if (ls_azimuth[k] > 0.0f) { hDirACRend->proto_index_diff[k] = 1; } - else if ( ls_azimuth[k] < 0.0f ) + else if (ls_azimuth[k] < 0.0f) { hDirACRend->proto_index_diff[k] = 2; } @@ -442,10 +1256,10 @@ static ivas_error ivas_dirac_rend_config( } } - if ( hDirACRend->hOutSetup.is_loudspeaker_setup ) + if (hDirACRend->hOutSetup.is_loudspeaker_setup) { hDirACRend->num_protos_dir = 3; - mvs2s( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE ); + mvs2s(hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE); } else { @@ -457,16 +1271,16 @@ static ivas_error ivas_dirac_rend_config( else /* nchan_transport > 2 */ { hDirACRend->num_protos_ambi = 4; - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS) { hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff; - for ( k = 0; k < hDirACRend->num_outputs_diff; k++ ) + for (k = 0; k < hDirACRend->num_outputs_diff; k++) { hDirACRend->proto_index_diff[k] = k; } hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir; - for ( k = 0; k < hDirACRend->num_outputs_dir; k++ ) + for (k = 0; k < hDirACRend->num_outputs_dir; k++) { hDirACRend->proto_index_dir[k] = k; } @@ -476,9 +1290,9 @@ static ivas_error ivas_dirac_rend_config( hDirACRend->num_protos_diff = 1; hDirACRend->num_protos_dir = nchan_transport; - for ( k = 0; k < min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ ) + for (k = 0; k < min(hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir); k++) { - if ( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir ) + if (hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir) { hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k; } @@ -487,88 +1301,73 @@ static ivas_error ivas_dirac_rend_config( } /* direct/diffuse responses */ - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { - if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) + if ((hDirACRend->diffuse_response_function = (float *)malloc(sizeof(float) * hDirACRend->num_outputs_dir)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } /* reallocate static memory */ - else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->num_outputs_dir != num_outputs_dir_old ) + else if (flag_config == DIRAC_RECONFIGURE && hDirACRend->num_outputs_dir != num_outputs_dir_old) { - free( hDirACRend->diffuse_response_function ); + free(hDirACRend->diffuse_response_function); hDirACRend->diffuse_response_function = NULL; - if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) + if ((hDirACRend->diffuse_response_function = (float *)malloc(sizeof(float) * hDirACRend->num_outputs_dir)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - if ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) + if ((hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS) || (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) || (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO)) { - initDiffuseResponses( hDirACRend->diffuse_response_function, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, - hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config ); + initDiffuseResponses(hDirACRend->diffuse_response_function, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config); } else { - initDiffuseResponses( hDirACRend->diffuse_response_function, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA, - hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID ); + initDiffuseResponses(hDirACRend->diffuse_response_function, hDirACRend->num_outputs_dir, IVAS_AUDIO_CONFIG_FOA, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, IVAS_AUDIO_CONFIG_INVALID); } - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) { - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { - if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ((hDirACRend->hoa_encoder = (float *)malloc(nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder && ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) + else if (flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder && (hDirACRend->num_outputs_diff != num_outputs_diff_old)) { - free( hDirACRend->hoa_encoder ); + free(hDirACRend->hoa_encoder); hDirACRend->hoa_encoder = NULL; - if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ((hDirACRend->hoa_encoder = (float *)malloc(nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - set_f( hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff ); - compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirACRend->hoa_encoder, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); + set_f(hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff); + compute_hoa_encoder_mtx(ls_azimuth, ls_elevation, hDirACRend->hoa_encoder, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order); } else { - if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder ) + if (flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder) { - free( hDirACRend->hoa_encoder ); + free(hDirACRend->hoa_encoder); } hDirACRend->hoa_encoder = NULL; } /* VBAP */ - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { st_ivas->hVBAPdata = NULL; } - if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) + if (hDirACRend->panningConf == DIRAC_PANNING_VBAP) { -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++) { - ls_azimuth_fx[i] = float_to_fix(ls_azimuth[i], Q22); - ls_elevation_fx[i] = float_to_fix(ls_elevation[i], Q22); - } - if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) - { - vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); - } - - if ( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if (flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL) { vbap_free_data(&(st_ivas->hVBAPdata)); @@ -578,43 +1377,34 @@ static ivas_error ivas_dirac_rend_config( { return error; } -#endif } - else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + else if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) { - if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) + if (flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL) { -#ifdef IVAS_FLOAT_FIXED - vbap_free_data_fx(&(st_ivas->hVBAPdata)); -#else - vbap_free_data( &( st_ivas->hVBAPdata ) ); -#endif + vbap_free_data(&(st_ivas->hVBAPdata)); } hDirACRend->hoa_decoder = NULL; } - else if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) + else if (flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL) { -#ifdef IVAS_FLOAT_FIXED - vbap_free_data_fx(&(st_ivas->hVBAPdata)); -#else - vbap_free_data( &( st_ivas->hVBAPdata ) ); -#endif + vbap_free_data(&(st_ivas->hVBAPdata)); } /* HOA panning/dec */ - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { hDirACRend->hoa_decoder = NULL; - if ( ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) || st_ivas->ivas_format == SBA_FORMAT || ( nchan_transport > 2 ) ) + if ((hDirACRend->panningConf == DIRAC_PANNING_HOA3) || st_ivas->ivas_format == SBA_FORMAT || (nchan_transport > 2)) { - if ( hDirACRend->hOutSetup.is_loudspeaker_setup ) + if (hDirACRend->hOutSetup.is_loudspeaker_setup) { - if ( st_ivas->hoa_dec_mtx != NULL ) + if (st_ivas->hoa_dec_mtx != NULL) { - free( st_ivas->hoa_dec_mtx ); + free(st_ivas->hoa_dec_mtx); st_ivas->hoa_dec_mtx = NULL; } - if ( ( error = ivas_sba_get_hoa_dec_matrix( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + if ((error = ivas_sba_get_hoa_dec_matrix(hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order)) != IVAS_ERR_OK) { return error; } @@ -625,39 +1415,39 @@ static ivas_error ivas_dirac_rend_config( } /* decorrelation */ - proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0; + proto_signal_decorr_on_old = (flag_config == DIRAC_RECONFIGURE) ? hDirACRend->proto_signal_decorr_on : 0; hDirACRend->proto_signal_decorr_on = 1; - if ( ( nchan_transport > 2 ) && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) ) + if ((nchan_transport > 2) && (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS)) { /*switch off decorrelation for 4 transport channels*/ hDirACRend->proto_signal_decorr_on = 0; } - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) { hDirACRend->proto_signal_decorr_on = 0; } - if ( ( flag_config == DIRAC_OPEN && hDirACRend->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) + if ((flag_config == DIRAC_OPEN && hDirACRend->proto_signal_decorr_on) || (flag_config == DIRAC_RECONFIGURE && (hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old))) { - if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + if ((error = ivas_dirac_dec_decorr_open(&(hDirACRend->h_freq_domain_decorr_ap_params), &(hDirACRend->h_freq_domain_decorr_ap_state), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs)) != IVAS_ERR_OK) { return error; } } - else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) + else if (flag_config == DIRAC_RECONFIGURE && (!hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old)) { - ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + ivas_dirac_dec_decorr_close(&hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state); } - else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) + else if (flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old) { - if ( nchan_transport != nchan_transport_old || hDirACRend->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) + if (nchan_transport != nchan_transport_old || hDirACRend->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE) { /* close and reopen the decorrelator */ - ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + ivas_dirac_dec_decorr_close(&hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state); - if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + if ((error = ivas_dirac_dec_decorr_open(&(hDirACRend->h_freq_domain_decorr_ap_params), &(hDirACRend->h_freq_domain_decorr_ap_state), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs)) != IVAS_ERR_OK) { return error; } @@ -665,26 +1455,26 @@ static ivas_error ivas_dirac_rend_config( } /* output synthesis */ - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { - if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + if ((ivas_dirac_dec_output_synthesis_open(hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag)) != IVAS_ERR_OK) { return error; } hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; } - else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) ) + else if ((flag_config == DIRAC_RECONFIGURE) && ((nchan_transport != nchan_transport_old) || (hDirACRend->num_outputs_diff != num_outputs_diff_old))) { - ivas_dirac_dec_output_synthesis_close( hDirACRend ); + ivas_dirac_dec_output_synthesis_close(hDirACRend); - if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + if ((ivas_dirac_dec_output_synthesis_open(hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag)) != IVAS_ERR_OK) { return error; } hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; } - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) { hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; } @@ -693,97 +1483,97 @@ static ivas_error ivas_dirac_rend_config( * memory allocation *-----------------------------------------------------------------*/ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) { - if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f ) + if (flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f) { - free( hDirACRend->proto_frame_f ); + free(hDirACRend->proto_frame_f); } hDirACRend->proto_frame_f = NULL; } else { - if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) + if (flag_config == DIRAC_OPEN || (flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL)) { - if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + if ((hDirACRend->proto_frame_f = (float *)malloc(sizeof(float) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) + else if (flag_config == DIRAC_RECONFIGURE && (hDirACRend->num_protos_diff != num_protos_diff_old)) { proto_frame_f_old = hDirACRend->proto_frame_f; - free( proto_frame_f_old ); - if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + free(proto_frame_f_old); + if ((hDirACRend->proto_frame_f = (float *)malloc(sizeof(float) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands)) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } } - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { hDirACRend->buffer_energy = NULL; } - if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) + if ((flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE) || (flag_config == DIRAC_RECONFIGURE && (hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE))) { hDirACRend->index_buffer_intensity = 0; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + for (i = 0; i < DIRAC_NUM_DIMS; i++) { - for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + for (j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++) { - if ( ( hDirACRend->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + if ((hDirACRend->buffer_intensity_real[i][j] = (float *)malloc(CLDFB_NO_CHANNELS_MAX * sizeof(float))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } - set_f( hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f(hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX); } } - if ( hDirACRend->buffer_energy == NULL ) + if (hDirACRend->buffer_energy == NULL) { - if ( ( hDirACRend->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + if ((hDirACRend->buffer_energy = (float *)malloc(DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof(float))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n")); } } - set_f( hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); + set_f(hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX); } - else if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) + else if ((flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE) || (flag_config == DIRAC_RECONFIGURE && (hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE))) { - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + for (i = 0; i < DIRAC_NUM_DIMS; i++) { - for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + for (j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++) { - if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j] ) + if (flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j]) { - free( hDirACRend->buffer_intensity_real[i][j] ); + free(hDirACRend->buffer_intensity_real[i][j]); } hDirACRend->buffer_intensity_real[i][j] = NULL; } } - if ( hDirACRend->buffer_energy != NULL ) + if (hDirACRend->buffer_energy != NULL) { - free( hDirACRend->buffer_energy ); + free(hDirACRend->buffer_energy); hDirACRend->buffer_energy = NULL; } } /* output synthesis */ - ivas_dirac_dec_output_synthesis_init( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); + ivas_dirac_dec_output_synthesis_init(hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag); /* Allocate stack memory */ - if ( flag_config != DIRAC_OPEN ) + if (flag_config != DIRAC_OPEN) { - ivas_dirac_free_mem( &( hDirACRend->stack_mem ) ); + ivas_dirac_free_mem(&(hDirACRend->stack_mem)); } - if ( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) + if ((error = ivas_dirac_alloc_mem(hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &(hDirACRend->stack_mem), hodirac_flag)) != IVAS_ERR_OK) { return error; } - if ( flag_config == DIRAC_OPEN ) + if (flag_config == DIRAC_OPEN) { st_ivas->hDirACRend = hDirACRend; } @@ -791,52 +1581,51 @@ static ivas_error ivas_dirac_rend_config( return error; } - /*------------------------------------------------------------------------- * ivas_dirac_dec_config() * * Open or reconfigure decoder DirAC/MASA handle *-------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ ) { ivas_error error; - int32_t output_Fs; - int16_t hodirac_flag; - int16_t sparfoa_flag; + Word32 output_Fs; + Word16 hodirac_flag; + Word16 sparfoa_flag; DIRAC_CONFIG_FLAG dec_config_flag; DIRAC_CONFIG_FLAG rend_config_flag; DIRAC_CONFIG_FLAG common_rend_config_flag; - int16_t need_dirac_rend; - int16_t need_parambin; - int16_t dec_param_estim_old; - int16_t dec_param_estim_new; + Word16 need_dirac_rend; + Word16 need_parambin; + Word16 dec_param_estim_old; + Word16 dec_param_estim_new; error = IVAS_ERR_OK; /* Solve and setup flags for inits */ - dec_config_flag = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + dec_config_flag = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; output_Fs = st_ivas->hDecoderConfig->output_Fs; - hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; sparfoa_flag = 0; - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) + IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) { sparfoa_flag = 1; } - if ( ( error = ivas_dirac_dec_config_internal( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) { return error; } /* This is required for parambin */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + IF( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; } @@ -846,24 +1635,24 @@ ivas_error ivas_dirac_dec_config( /* Setup renderers and meta */ /* First, free everything if in reconfig and not the active renderer */ need_parambin = 0; - switch ( st_ivas->renderer_type ) + SWITCH( st_ivas->renderer_type ) { case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: case RENDERER_STEREO_PARAMETRIC: need_parambin = 1; - break; + BREAK; default: need_parambin = 0; } - if ( !need_parambin ) + IF( !need_parambin ) { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } need_dirac_rend = 0; - switch ( st_ivas->renderer_type ) + SWITCH( st_ivas->renderer_type ) { case RENDERER_DIRAC: case RENDERER_BINAURAL_FASTCONV: @@ -873,84 +1662,105 @@ ivas_error ivas_dirac_dec_config( case RENDERER_OSBA_AMBI: case RENDERER_OSBA_LS: need_dirac_rend = 1; - break; + BREAK; default: need_dirac_rend = 0; } - if ( !need_dirac_rend ) + IF( !need_dirac_rend ) { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_rend_close_fx( &st_ivas->hDirACRend ); +#else ivas_dirac_rend_close( &st_ivas->hDirACRend ); +#endif } - if ( !sparfoa_flag ) + IF( !sparfoa_flag ) { common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, + st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) { return error; } - - if ( need_dirac_rend ) +#endif + IF( need_dirac_rend ) { rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_rend_config( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) { return error; } +#endif } - if ( need_parambin ) + IF( need_parambin ) { - if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) + IF( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) { - if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + /*WIP*/ + IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } } - if ( st_ivas->hDiracDecBin == NULL ) + IF( st_ivas->hDiracDecBin == NULL ) { - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + /*WIP*/ + IF( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ - if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) + IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) { - ivas_dirac_dec_decorr_close( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); + ivas_dirac_dec_decorr_close( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); // done } - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) { return error; } - if ( !st_ivas->hDiracDecBin->useTdDecorr ) + IF( !st_ivas->hDiracDecBin->useTdDecorr ) { - if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL ) + IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL ) { float frequency_axis[CLDFB_NO_CHANNELS_MAX]; - #ifdef IVAS_FLOAT_FIXED Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); - for (int i = 0; i < st_ivas->hSpatParamRendCom->num_freq_bands; i++) { - frequency_axis[i] = ( float ) frequency_axis_fx[i]; + FOR( int i = 0; i < st_ivas->hSpatParamRendCom->num_freq_bands; i++ ) + { + frequency_axis[i] = (float) frequency_axis_fx[i]; } #else ivas_dirac_dec_get_frequency_axis( frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); #endif - if ( ( error = ivas_dirac_dec_decorr_open( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, frequency_axis, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + /*WIP*/ + IF( ( error = ivas_dirac_dec_decorr_open( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, frequency_axis, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -969,8 +1779,166 @@ ivas_error ivas_dirac_dec_config( return error; } +#else +ivas_error ivas_dirac_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +) +{ + ivas_error error; + int32_t output_Fs; + int16_t hodirac_flag; + int16_t sparfoa_flag; + DIRAC_CONFIG_FLAG dec_config_flag; + DIRAC_CONFIG_FLAG rend_config_flag; + DIRAC_CONFIG_FLAG common_rend_config_flag; + int16_t need_dirac_rend; + int16_t need_parambin; + int16_t dec_param_estim_old; + int16_t dec_param_estim_new; + + error = IVAS_ERR_OK; + + /* Solve and setup flags for inits */ + dec_config_flag = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + hodirac_flag = ivas_get_hodirac_flag(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order); + dec_param_estim_old = (dec_config_flag == DIRAC_RECONFIGURE) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; + + sparfoa_flag = 0; + if (st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag) + { + sparfoa_flag = 1; + } + + if ((error = ivas_dirac_dec_config_internal(st_ivas, dec_config_flag)) != IVAS_ERR_OK) + { + return error; + } + + /* This is required for parambin */ + if (st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC) + { + st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; + } + + dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim; + + /* Setup renderers and meta */ + /* First, free everything if in reconfig and not the active renderer */ + need_parambin = 0; + switch (st_ivas->renderer_type) + { + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + case RENDERER_STEREO_PARAMETRIC: + need_parambin = 1; + break; + default: + need_parambin = 0; + } + + if (!need_parambin) + { + ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); + } + + need_dirac_rend = 0; + switch (st_ivas->renderer_type) + { + case RENDERER_DIRAC: + case RENDERER_BINAURAL_FASTCONV: + case RENDERER_BINAURAL_FASTCONV_ROOM: + case RENDERER_SBA_LINEAR_ENC: + case RENDERER_SBA_LINEAR_DEC: + case RENDERER_OSBA_AMBI: + case RENDERER_OSBA_LS: + need_dirac_rend = 1; + break; + default: + need_dirac_rend = 0; + } + + if (!need_dirac_rend) + { + ivas_dirac_rend_close(&st_ivas->hDirACRend); + } + + if (!sparfoa_flag) + { + common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; + if ((error = ivas_spat_hSpatParamRendCom_config(&st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, + st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0)) != IVAS_ERR_OK) + { + return error; + } + + if (need_dirac_rend) + { + rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; + if ((error = ivas_dirac_rend_config(st_ivas, rend_config_flag, dec_param_estim_old)) != IVAS_ERR_OK) + { + return error; + } + } + + if (need_parambin) + { + if (st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC) + { + if ((error = ivas_dirac_dec_binaural_copy_hrtfs(&st_ivas->hHrtfParambin)) != IVAS_ERR_OK) + { + return error; + } + } + + if (st_ivas->hDiracDecBin == NULL) + { + if ((error = ivas_dirac_dec_init_binaural_data(st_ivas, st_ivas->hHrtfParambin)) != IVAS_ERR_OK) + { + return error; + } + } + else + { + /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ + if (st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !(st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0)) + { + ivas_dirac_dec_decorr_close(&st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state); + } + + if ((error = ivas_td_decorr_reconfig_dec(st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &(st_ivas->hDiracDecBin->hTdDecorr), &(st_ivas->hDiracDecBin->useTdDecorr))) != IVAS_ERR_OK) + { + return error; + } + + if (!st_ivas->hDiracDecBin->useTdDecorr) + + { + if (st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL) + { + float frequency_axis[CLDFB_NO_CHANNELS_MAX]; + + ivas_dirac_dec_get_frequency_axis(frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands); + if ((error = ivas_dirac_dec_decorr_open(&(st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params), &(st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, frequency_axis, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs)) != IVAS_ERR_OK) + { + return error; + } + } + } + + st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor(st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate); + } + } + } + return error; +} +#endif + /*------------------------------------------------------------------------- * ivas_dirac_dec_close() * @@ -1002,7 +1970,32 @@ void ivas_dirac_dec_close( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_close_fx( + DIRAC_DEC_HANDLE *hDirAC_out) +{ + DIRAC_DEC_HANDLE hDirAC; + + IF (hDirAC_out == NULL || *hDirAC_out == NULL) + { + return; + } + + hDirAC = *hDirAC_out; + + /* Config & CLDFB */ + IF (hDirAC->hConfig != NULL) + { + free(hDirAC->hConfig); + hDirAC->hConfig = NULL; + } + + free(*hDirAC_out); + *hDirAC_out = NULL; + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_read_BS() * @@ -2027,7 +3020,6 @@ void ivas_qmetadata_to_dirac( * * Set metadata index mapping for DirAC *------------------------------------------------------------------------*/ - #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_set_md_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 51f1e97b6..d51bfb8cd 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -150,8 +150,11 @@ ivas_error ivas_dec_setup( { /* set Ambisonic (SBA) order used for analysis and coding */ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); +#ifdef IVAS_FLOAT_FIXED0 + ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); +#else + ivas_sba_config(ivas_total_brate, st_ivas->sba_analysis_order, -1, &(st_ivas->nchan_transport), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init); +#endif } } ELSE IF ( st_ivas->ivas_format == MASA_FORMAT ) @@ -2393,9 +2396,15 @@ void ivas_destroy_dec( } ELSE { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); + ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); +#else ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); + ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close(&(st_ivas->hDirAC)); +#endif } /* SPAR handle */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index fc74a9d27..bed7a08a6 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -3341,10 +3341,17 @@ ivas_error ivas_masa_dec_reconfigure_fx( IF( st_ivas->hDirAC != NULL ) { /* close all unnecessary parametric decoding and rendering */ +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); + ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); + ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); +#else ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); +#endif } } /* possible reconfigure is done later */ diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index e4affbed3..661b03ac6 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -896,7 +896,7 @@ ivas_error ivas_param_mc_dec_reconfig( Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx(frequency_axis_fx, output_Fs, hParamMC->num_freq_bands); - for (Word16 i = 0; i < hParamMC->num_freq_bands; i++) { + for ( i = 0; i < hParamMC->num_freq_bands; i++) { frequency_axis[i] = ( float ) frequency_axis_fx[i]; } #else diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 304839f00..6edf496e0 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1052,16 +1052,19 @@ static ivas_error ivas_mc_dec_reconfig( #else ivas_masa_dec_close( &( st_ivas->hMasa ) ); #endif - ivas_qmetadata_close( &st_ivas->hQMetaData ); + ivas_qmetadata_close( &st_ivas->hQMetaData ); if ( st_ivas->hDirAC != NULL ) { - ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); #ifdef IVAS_FLOAT_FIXED + ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); vbap_free_data_fx(&(st_ivas->hVBAPdata)); #else + ivas_dirac_rend_close(&(st_ivas->hDirACRend)); + ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close(&(st_ivas->hDirAC)); vbap_free_data( &( st_ivas->hVBAPdata ) ); #endif } @@ -1170,12 +1173,15 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->hDirAC != NULL ) { - ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); #ifdef IVAS_FLOAT_FIXED + ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); + ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); vbap_free_data_fx(&(st_ivas->hVBAPdata)); #else + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close(&(st_ivas->hDirAC)); vbap_free_data( &( st_ivas->hVBAPdata ) ); #endif } @@ -1438,11 +1444,14 @@ static ivas_error ivas_mc_dec_reconfig( else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL ) { ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); + #ifdef IVAS_FLOAT_FIXED + ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); vbap_free_data_fx(&(st_ivas->hVBAPdata)); #else + ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close(&(st_ivas->hDirAC)); vbap_free_data( &( st_ivas->hVBAPdata ) ); #endif } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index e577fdd77..0354ef5fa 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -457,12 +457,15 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->renderer_type == RENDERER_DISABLE ) { - ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); #ifdef IVAS_FLOAT_FIXED + ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); + ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); vbap_free_data_fx(&(st_ivas->hVBAPdata)); #else + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close(&(st_ivas->hDirAC)); vbap_free_data( &( st_ivas->hVBAPdata ) ); #endif } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index da9d95c80..93d52a9b0 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -319,7 +319,35 @@ ivas_error ivas_dirac_dec_init_binaural_data( * * Close parametric binaural renderer *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_close_binaural_data( + DIRAC_DEC_BIN_HANDLE *hBinaural /* i/o: decoder DirAC binaural data handle */ +) +{ + + IF (hBinaural == NULL || *hBinaural == NULL) + { + return; + } + + IF ((*hBinaural)->hReverb != NULL) + { + /*TODO : remove the float buffers being freed*/ + ivas_binaural_reverb_close(&((*hBinaural)->hReverb)); + } + + ivas_td_decorr_dec_close(&((*hBinaural)->hTdDecorr)); + IF ((*hBinaural)->h_freq_domain_decorr_ap_params != NULL) + { + ivas_dirac_dec_decorr_close(&(*hBinaural)->h_freq_domain_decorr_ap_params, &(*hBinaural)->h_freq_domain_decorr_ap_state); + } + + free(*hBinaural); + *hBinaural = NULL; + return; +} +#else void ivas_dirac_dec_close_binaural_data( DIRAC_DEC_BIN_HANDLE *hBinaural /* i/o: decoder DirAC binaural data handle */ ) @@ -346,7 +374,7 @@ void ivas_dirac_dec_close_binaural_data( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_binaural_copy_hrtfs() * diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index 0240eb7ea..b81c21c2b 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -610,7 +610,7 @@ void ivas_dirac_dec_decorr_process( void ivas_dirac_dec_decorr_close( HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, - HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state ) + HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state) { DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; @@ -618,12 +618,12 @@ void ivas_dirac_dec_decorr_close( * check input handles *-----------------------------------------------------------------*/ - if ( ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL ) + if (ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL) { return; } - if ( *ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL ) + if (*ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL) { return; } @@ -632,17 +632,17 @@ void ivas_dirac_dec_decorr_close( * free onset filter arrays *-----------------------------------------------------------------*/ - dirac_onset_detection_state = &( *ph_freq_domain_decorr_ap_state )->h_onset_detection_power_state; + dirac_onset_detection_state = &(*ph_freq_domain_decorr_ap_state)->h_onset_detection_power_state; - if ( dirac_onset_detection_state->onset_detector_1 != NULL ) + if (dirac_onset_detection_state->onset_detector_1 != NULL) { - free( dirac_onset_detection_state->onset_detector_1 ); + free(dirac_onset_detection_state->onset_detector_1); dirac_onset_detection_state->onset_detector_1 = NULL; } - if ( dirac_onset_detection_state->onset_detector_2 != NULL ) + if (dirac_onset_detection_state->onset_detector_2 != NULL) { - free( dirac_onset_detection_state->onset_detector_2 ); + free(dirac_onset_detection_state->onset_detector_2); dirac_onset_detection_state->onset_detector_2 = NULL; } @@ -650,87 +650,86 @@ void ivas_dirac_dec_decorr_close( * memory deallocation *-----------------------------------------------------------------*/ - /* free decorrelation buffer */ - if ( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer != NULL ) + /* free decorrelation buffer */ + if ((*ph_freq_domain_decorr_ap_state)->decorr_buffer != NULL) { - free( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer ); - ( *ph_freq_domain_decorr_ap_state )->decorr_buffer = NULL; + free((*ph_freq_domain_decorr_ap_state)->decorr_buffer); + (*ph_freq_domain_decorr_ap_state)->decorr_buffer = NULL; } /* free ducker smoothed direct energy buffer */ - if ( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth != NULL ) + if ((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth != NULL) { - free( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth ); - ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth = NULL; + free((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth); + (*ph_freq_domain_decorr_ap_state)->direct_energy_smooth = NULL; } /* free ducker smoothed reverb energy buffer */ - if ( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth != NULL ) + if ((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth != NULL) { - free( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth ); - ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth = NULL; + free((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth); + (*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth = NULL; } /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->pre_delay != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->pre_delay != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->pre_delay ); - ( *ph_freq_domain_decorr_ap_params )->pre_delay = NULL; + free((*ph_freq_domain_decorr_ap_params)->pre_delay); + (*ph_freq_domain_decorr_ap_params)->pre_delay = NULL; } /* free filter length param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->filter_length != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->filter_length != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->filter_length ); - ( *ph_freq_domain_decorr_ap_params )->filter_length = NULL; + free((*ph_freq_domain_decorr_ap_params)->filter_length); + (*ph_freq_domain_decorr_ap_params)->filter_length = NULL; } /* free filter coeff param buffers */ - if ( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real ); - ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real = NULL; + free((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real); + (*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real = NULL; } /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real ); - ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real = NULL; + free((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real); + (*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real = NULL; } /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag ); - ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag = NULL; + free((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag); + (*ph_freq_domain_decorr_ap_params)->phase_coeff_imag = NULL; } /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->phase_coeff_real != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real ); - ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real = NULL; + free((*ph_freq_domain_decorr_ap_params)->phase_coeff_real); + (*ph_freq_domain_decorr_ap_params)->phase_coeff_real = NULL; } /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands != NULL ) + if ((*ph_freq_domain_decorr_ap_params)->split_frequency_bands != NULL) { - free( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands ); - ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands = NULL; + free((*ph_freq_domain_decorr_ap_params)->split_frequency_bands); + (*ph_freq_domain_decorr_ap_params)->split_frequency_bands = NULL; } /* free pointers to state and parameter structs */ - free( *ph_freq_domain_decorr_ap_params ); + free(*ph_freq_domain_decorr_ap_params); *ph_freq_domain_decorr_ap_params = NULL; - free( *ph_freq_domain_decorr_ap_state ); + free(*ph_freq_domain_decorr_ap_state); *ph_freq_domain_decorr_ap_state = NULL; return; } - /*------------------------------------------------------------------------- * Local functions *------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 097063a8b..b46b66616 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -43,15 +43,20 @@ #include "ivas_rom_com.h" #include "ivas_rom_dec.h" #include "wmc_auto.h" - +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx1.h" /* Function prototypes */ +#include "prot_fx2.h" /* Function prototypes */ +#endif /*------------------------------------------------------------------------- * Local constants *------------------------------------------------------------------------*/ #define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ #define DIRAC_ALPHA_MAX 0.1f +#define DIRAC_ALPHA_MAX_Q15 3276 #define DIRAC_AVG_LENGTH_SYNTH_MS_FAST 10 #define DIRAC_ALPHA_MAX_FAST 0.12f +#define DIRAC_ALPHA_MAX_FAST_Q15 3932 #define DIRECTION_SMOOTHNESS_ALPHA 0.01f @@ -71,6 +76,9 @@ static void computeTargetPSDs_diffuse_with_onsets( const int16_t num_channels, c static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, const float maxAlpha, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, const int32_t output_Fs ); +#ifdef IVAS_FLOAT_FIXED +static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const int16_t averaging_length_ms, const Word16 maxAlpha_fx, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, Word16 *frequency_axis_fx, const int32_t output_Fs); +#endif static void spreadCoherencePanningHoa( const int16_t azimuth, const int16_t elevation, const float spreadCoh, float *direct_response, const int16_t num_channels_dir, const int16_t ambisonics_order ); static void spreadCoherencePanningVbap( const int16_t azimuth, const int16_t elevation, const float spreadCoh, float *direct_response, const int16_t num_channels_dir, const VBAP_HANDLE hVBAPdata ); @@ -83,8 +91,10 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +extern Word16 find_guarded_bits_fx(Word32 n); -ivas_error ivas_dirac_dec_output_synthesis_open( +ivas_error ivas_dirac_dec_output_synthesis_open_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ RENDERER_TYPE renderer_type, /* i : renderer type */ @@ -95,9 +105,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open( { int16_t idx, ch_idx; int16_t size; - float tmp; uint16_t num_diffuse_responses; float temp_alpha_synthesis[CLDFB_NO_CHANNELS_MAX]; + Word16 tmp_fx; + Word16 temp_alpha_synthesis_fx[CLDFB_NO_CHANNELS_MAX]; /* pointers to structs for allocation */ DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); @@ -111,11 +122,11 @@ ivas_error ivas_dirac_dec_output_synthesis_open( assert( hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1 ); assert( hDirACRend->diffuse_response_function != NULL ); - if ( hDirACRend->proto_signal_decorr_on ) + IF ( hDirACRend->proto_signal_decorr_on ) { dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr; } - else + ELSE { dirac_output_synthesis_params->max_band_decorr = 0; } @@ -125,72 +136,115 @@ ivas_error ivas_dirac_dec_output_synthesis_open( *-----------------------------------------------------------------*/ dirac_output_synthesis_state->diffuse_responses_square = NULL; - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + dirac_output_synthesis_state->diffuse_responses_square_fx = NULL; + + IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( 2 * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->diffuse_responses_square_fx = (Word16 *)malloc(2 * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } - else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + ELSE IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->diffuse_responses_square_fx = (Word16 *)malloc(hDirACRend->hOutSetup.nchan_out_woLFE * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } /* prototype power buffers */ dirac_output_synthesis_state->proto_power_smooth_prev = NULL; - if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + dirac_output_synthesis_state->proto_power_smooth_prev_fx = NULL; + + IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->proto_power_smooth_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } - if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) + IF ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx = (Word16 *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } - else + ELSE { + /*TODO : remove float code*/ dirac_output_synthesis_state->proto_power_diff_smooth_prev = NULL; + dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx = NULL; } /* buffer length and interpolator */ + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_params->interpolator = (float *) malloc( JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_params->interpolator_fx = (Word16 *)malloc(JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + /* target PSD buffers */ - if ( hodirac_flag ) + IF ( hodirac_flag ) { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; } - else + ELSE { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF ((dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx = (Word16 *)malloc(size * sizeof(Word16))) == NULL) { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + /*TODO : remove float code*/ dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx = NULL; + IF ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx = (Word16 *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } - else + ELSE { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -210,34 +264,74 @@ ivas_error ivas_dirac_dec_output_synthesis_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } + IF ((dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + + IF(hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) + { + IF((dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + ELSE + { + IF((dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } } /* direct and diffuse gain buffers */ + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF( ( dirac_output_synthesis_state->gains_dir_prev_fx = (Word16 *) malloc( size * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->gains_diff_prev_fx = (Word16 *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } - else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) + ELSE IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->gains_diff_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } } - else + ELSE { + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + IF ((dirac_output_synthesis_state->gains_diff_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } /*-----------------------------------------------------------------* @@ -245,32 +339,358 @@ ivas_error ivas_dirac_dec_output_synthesis_open( *-----------------------------------------------------------------*/ /* compute alpha */ - if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { - computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs ); + computeAlphaSynthesis_fx(temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX_Q15, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis_fx, output_Fs); + + for (int k = 0; k < hSpatParamRendCom->num_freq_bands; k++) { + temp_alpha_synthesis[k] = fix16_to_float(temp_alpha_synthesis_fx[k], 15); + } + + /*TODO : remove float code*/ if ( ( dirac_output_synthesis_params->alpha_synthesis = (float *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas ); - computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs ); - if ( ( dirac_output_synthesis_params->alpha_synthesis_fast = (float *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( float ) ) ) == NULL ) + IF((dirac_output_synthesis_params->alpha_synthesis_fx = (Word16 *)malloc(dirac_output_synthesis_params->numAlphas * sizeof(Word16))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); } - mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast ); + Copy(temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fx, dirac_output_synthesis_params->numAlphas); - if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + for (int k = 1; k < hSpatParamRendCom->num_freq_bands; k++) { + hDirACRend->frequency_axis_fx[k] = float_to_fix16(hDirACRend->frequency_axis[k], 0); + } + computeAlphaSynthesis_fx( temp_alpha_synthesis_fx, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST_Q15, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands , hDirACRend->frequency_axis_fx, output_Fs); + for (int k = 0; k < hSpatParamRendCom->num_freq_bands; k++) { + temp_alpha_synthesis[k] = fix16_to_float(temp_alpha_synthesis_fx[k], 15); + } + + IF ((dirac_output_synthesis_params->alpha_synthesis_fast_fx = (Word16 *)malloc(dirac_output_synthesis_params->numAlphasFast * sizeof(Word16))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); } - if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + Copy(temp_alpha_synthesis_fx, dirac_output_synthesis_params->alpha_synthesis_fast_fx, dirac_output_synthesis_params->numAlphasFast); + + IF((dirac_output_synthesis_state->reference_power_smooth_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(Word16))) == NULL) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + IF((dirac_output_synthesis_state->direction_smoothness_prev_fx = (Word16 *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + set16_fx(dirac_output_synthesis_state->reference_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands); + set16_fx(dirac_output_synthesis_state->direction_smoothness_prev_fx, 0, hSpatParamRendCom->num_freq_bands); + + /*TODO : remove float code*/ + if ((dirac_output_synthesis_params->alpha_synthesis_fast = (float *)malloc(dirac_output_synthesis_params->numAlphasFast * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + mvr2r(temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast); + + if ((dirac_output_synthesis_state->reference_power_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + if ((dirac_output_synthesis_state->direction_smoothness_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + set_zero(dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands); + set_zero(dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands); + } + ELSE + { + dirac_output_synthesis_params->alpha_synthesis = NULL; + dirac_output_synthesis_params->alpha_synthesis_fast = NULL; + dirac_output_synthesis_state->reference_power_smooth_prev = NULL; + dirac_output_synthesis_state->direction_smoothness_prev = NULL; +#ifdef IVAS_FLOAT_FIXED + dirac_output_synthesis_params->alpha_synthesis_fx = NULL; + dirac_output_synthesis_params->alpha_synthesis_fast_fx = NULL; + dirac_output_synthesis_state->reference_power_smooth_prev_fx = NULL; + dirac_output_synthesis_state->direction_smoothness_prev_fx = NULL; +#endif + } + + /* compute interpolator */ + FOR (idx = 1; idx <= JBM_CLDFB_SLOTS_IN_SUBFRAME; ++idx) + { + dirac_output_synthesis_params->interpolator[idx - 1] = (float)idx / (float)JBM_CLDFB_SLOTS_IN_SUBFRAME; + Word16 tmp_exp = 0; + dirac_output_synthesis_params->interpolator_fx[idx - 1] = BASOP_Util_Divide1616_Scale(idx , JBM_CLDFB_SLOTS_IN_SUBFRAME, &tmp_exp); + /*TODO : Remove float code*/ + dirac_output_synthesis_params->interpolator[idx - 1] = me2f_16(dirac_output_synthesis_params->interpolator_fx[idx - 1] , tmp_exp); + } + + /* prepare diffuse response function */ + IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + num_diffuse_responses = 2; + } + ELSE + { + num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE; + } + + IF (dirac_output_synthesis_state->diffuse_responses_square_fx != NULL) + { + FOR (ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx) + { + /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ + tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; + + dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = mult(tmp_fx , tmp_fx); + /*TODO : remove floating code*/ + dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = fix16_to_float(dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] , 15); + } + } + + + IF (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + Word16 diff_compensation_order; + Word32 diff_nrg_total_fx, diff_nrg_fx, diff_nrg_trans_fx, diff_nrg_decorr_fx; + + diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/ + diff_compensation_order = s_min(diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order); + + diff_nrg_total_fx = 0; + diff_nrg_trans_fx = 0; + diff_nrg_decorr_fx = 0; + + Word16 gaurd_bits = find_guarded_bits_fx((diff_compensation_order + 1) * (diff_compensation_order + 1)); + FOR (ch_idx = 0; ch_idx < (diff_compensation_order + 1) * (diff_compensation_order + 1); ch_idx++) + { + diff_nrg_fx = L_shr(L_mult0(hDirACRend->diffuse_response_function_fx[ch_idx], hDirACRend->diffuse_response_function_fx[ch_idx]), gaurd_bits);//Q30 - gaurd_bits + + diff_nrg_total_fx = L_add(diff_nrg_total_fx, diff_nrg_fx); + + /* is it a transport channel?*/ + IF (ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0) + { + diff_nrg_trans_fx = L_add(diff_nrg_trans_fx, diff_nrg_fx); + } + /* is it a decorrelated or transport channel?*/ + IF (ch_idx < hDirACRend->num_outputs_diff) + { + diff_nrg_decorr_fx = L_add(diff_nrg_decorr_fx, diff_nrg_fx); + } + } + Word16 exp_1 = 0, exp_2 = 0; + dirac_output_synthesis_params->diffuse_compensation_factor_fx = BASOP_Util_Divide3232_Scale(diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1); + /*TODO : remove float code*/ + dirac_output_synthesis_params->diffuse_compensation_factor = me2f_16(dirac_output_synthesis_params->diffuse_compensation_factor_fx , exp_1); + + dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = BASOP_Util_Divide3232_Scale(diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2); + /*TODO : remove float code*/ + dirac_output_synthesis_params->diffuse_compensation_factor_decorr = me2f_16(dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx , exp_2); + + } + ELSE + { + dirac_output_synthesis_params->diffuse_compensation_factor_fx = 0; + dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = 0; + /*TODO : remove float code*/ + dirac_output_synthesis_params->diffuse_compensation_factor = 0.f; + dirac_output_synthesis_params->diffuse_compensation_factor_decorr = 0.f; + } + + return IVAS_ERR_OK; +} +#endif + +ivas_error ivas_dirac_dec_output_synthesis_open( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + RENDERER_TYPE renderer_type, /* i : renderer type */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +) +{ + int16_t idx, ch_idx; + int16_t size; + float tmp; + uint16_t num_diffuse_responses; + float temp_alpha_synthesis[CLDFB_NO_CHANNELS_MAX]; + + /* pointers to structs for allocation */ + DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &(hDirACRend->h_output_synthesis_psd_params); + DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &(hDirACRend->h_output_synthesis_psd_state); + + /* check / set input parameters */ + assert(hSpatParamRendCom->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!"); + assert(hDirACRend->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!"); + assert(hDirACRend->num_outputs_diff > 0); + assert(hSpatParamRendCom->slot_size > 0); + assert(hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1); + assert(hDirACRend->diffuse_response_function != NULL); + + if (hDirACRend->proto_signal_decorr_on) + { + dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr; + } + else + { + dirac_output_synthesis_params->max_band_decorr = 0; + } + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + dirac_output_synthesis_state->diffuse_responses_square = NULL; + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + { + if ((dirac_output_synthesis_state->diffuse_responses_square = (float *)malloc(2 * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + else if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD) + { + if ((dirac_output_synthesis_state->diffuse_responses_square = (float *)malloc(hDirACRend->hOutSetup.nchan_out_woLFE * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + + /* prototype power buffers */ + dirac_output_synthesis_state->proto_power_smooth_prev = NULL; + if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD) + { + if ((dirac_output_synthesis_state->proto_power_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + if (dirac_output_synthesis_params->max_band_decorr > 0 && (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD)) + { + if ((dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + else + { + dirac_output_synthesis_state->proto_power_diff_smooth_prev = NULL; + } + + /* buffer length and interpolator */ + if ((dirac_output_synthesis_params->interpolator = (float *)malloc(JBM_CLDFB_SLOTS_IN_SUBFRAME * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + + /* target PSD buffers */ + if (hodirac_flag) + { + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; + } + else + { + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + } + if ((dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *)malloc(size * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; + if ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + else + { + if ((dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD) + { + if ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + else + { + if ((dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + } + + /* direct and diffuse gain buffers */ + if ((dirac_output_synthesis_state->gains_dir_prev = (float *)malloc(size * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + if ((dirac_output_synthesis_state->gains_diff_prev = (float *)malloc(dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + else if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO) + { + if ((dirac_output_synthesis_state->gains_diff_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + else + { + if ((dirac_output_synthesis_state->gains_diff_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + } + + /*-----------------------------------------------------------------* + * prepare processing parameters + *-----------------------------------------------------------------*/ + + /* compute alpha */ + if (!(renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD)) + { + computeAlphaSynthesis(temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs); + if ((dirac_output_synthesis_params->alpha_synthesis = (float *)malloc(dirac_output_synthesis_params->numAlphas * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + mvr2r(temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas); + + computeAlphaSynthesis(temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs); + if ((dirac_output_synthesis_params->alpha_synthesis_fast = (float *)malloc(dirac_output_synthesis_params->numAlphasFast * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + mvr2r(temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast); + + if ((dirac_output_synthesis_state->reference_power_smooth_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); + } + if ((dirac_output_synthesis_state->direction_smoothness_prev = (float *)malloc(hSpatParamRendCom->num_freq_bands * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n")); } - set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands ); - set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands ); + set_zero(dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands); + set_zero(dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands); } else { @@ -281,13 +701,13 @@ ivas_error ivas_dirac_dec_output_synthesis_open( } /* compute interpolator */ - for ( idx = 1; idx <= JBM_CLDFB_SLOTS_IN_SUBFRAME; ++idx ) + for (idx = 1; idx <= JBM_CLDFB_SLOTS_IN_SUBFRAME; ++idx) { - dirac_output_synthesis_params->interpolator[idx - 1] = (float) idx / (float) JBM_CLDFB_SLOTS_IN_SUBFRAME; + dirac_output_synthesis_params->interpolator[idx - 1] = (float)idx / (float)JBM_CLDFB_SLOTS_IN_SUBFRAME; } /* prepare diffuse response function */ - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) { num_diffuse_responses = 2; } @@ -296,9 +716,9 @@ ivas_error ivas_dirac_dec_output_synthesis_open( num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE; } - if ( dirac_output_synthesis_state->diffuse_responses_square != NULL ) + if (dirac_output_synthesis_state->diffuse_responses_square != NULL) { - for ( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx ) + for (ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx) { /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ tmp = hDirACRend->diffuse_response_function[ch_idx]; @@ -307,28 +727,28 @@ ivas_error ivas_dirac_dec_output_synthesis_open( } } - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) { int16_t diff_compensation_order; float diff_nrg_total, diff_nrg, diff_nrg_trans, diff_nrg_decorr; diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/ - diff_compensation_order = min( diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order ); + diff_compensation_order = min(diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order); diff_nrg_total = 0; diff_nrg_trans = 0; diff_nrg_decorr = 0; - for ( ch_idx = 0; ch_idx < ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ); ch_idx++ ) + for (ch_idx = 0; ch_idx < (diff_compensation_order + 1) * (diff_compensation_order + 1); ch_idx++) { diff_nrg = hDirACRend->diffuse_response_function[ch_idx] * hDirACRend->diffuse_response_function[ch_idx]; diff_nrg_total += diff_nrg; /* is it a transport channel?*/ - if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) + if (ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0) { diff_nrg_trans += diff_nrg; } /* is it a decorrelated or transport channel?*/ - if ( ch_idx < hDirACRend->num_outputs_diff ) + if (ch_idx < hDirACRend->num_outputs_diff) { diff_nrg_decorr += diff_nrg; } @@ -345,7 +765,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open( return IVAS_ERR_OK; } - /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_init() * @@ -423,6 +842,128 @@ void ivas_dirac_dec_output_synthesis_init( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_output_synthesis_init_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const Word16 nchan_out_woLFE, /* i : number of output audio channels without LFE */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ +) +{ + Word16 size; + + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; + DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; + + h_dirac_output_synthesis_params = &(hDirACRend->h_output_synthesis_psd_params); + h_dirac_output_synthesis_state = &(hDirACRend->h_output_synthesis_psd_state); + + /*-----------------------------------------------------------------* + * init outputSynthesisPSD_Init + *-----------------------------------------------------------------*/ + + /* initialize buffers */ + if (h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL) + { + set_zero(h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + } + + if (hodirac_flag) + { + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; + } + else + { + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + } + set_zero(h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size); + + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + set_zero(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + } + else if (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD) + { + set_zero(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff); + } + else + { + set_zero(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + } + + if (h_dirac_output_synthesis_state->proto_power_smooth_prev != NULL) + { + set_zero(h_dirac_output_synthesis_state->proto_power_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir); + } + set_zero(h_dirac_output_synthesis_state->gains_dir_prev, size); + + if (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + set_zero(h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + } + else + { + set_zero(h_dirac_output_synthesis_state->gains_diff_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + } + + if (h_dirac_output_synthesis_state->proto_power_diff_smooth_prev != NULL) + { + set_zero(h_dirac_output_synthesis_state->proto_power_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE); + } + +#ifdef IVAS_FLOAT_FIXED + IF (h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx != NULL) + { + set16_fx(h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + } + + IF (hodirac_flag) + { + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; + } + ELSE + { + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; + } + set16_fx(h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx, 0, size); + + IF (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + set16_fx(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + } + ELSE IF (hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD) + { + set16_fx(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff); + } + ELSE + { + set16_fx(h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + } + + IF (h_dirac_output_synthesis_state->proto_power_smooth_prev_fx != NULL) + { + set16_fx(h_dirac_output_synthesis_state->proto_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir); + } + set16_fx(h_dirac_output_synthesis_state->gains_dir_prev_fx, 0, size); + + IF (hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + set16_fx(h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff); + } + ELSE + { + set16_fx(h_dirac_output_synthesis_state->gains_diff_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir); + } + + IF (h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx != NULL) + { + set16_fx(h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE); + } +#endif + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_close() @@ -524,7 +1065,181 @@ void ivas_dirac_dec_output_synthesis_close( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_output_synthesis_close_fx( + DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */ +) +{ + /* pointers to structs for allocation */ + DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &(hDirACRend->h_output_synthesis_psd_params); + DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &(hDirACRend->h_output_synthesis_psd_state); + + /*-----------------------------------------------------------------* + * memory deallocation + *-----------------------------------------------------------------*/ + + /* free interpolator */ + if ((dirac_output_synthesis_params)->interpolator != NULL) + { + free((dirac_output_synthesis_params)->interpolator); + (dirac_output_synthesis_params)->interpolator = NULL; + } + + /* free alpha */ + if ((dirac_output_synthesis_params)->alpha_synthesis != NULL) + { + free((dirac_output_synthesis_params)->alpha_synthesis); + (dirac_output_synthesis_params)->alpha_synthesis = NULL; + } + if ((dirac_output_synthesis_params)->alpha_synthesis_fast != NULL) + { + free((dirac_output_synthesis_params)->alpha_synthesis_fast); + (dirac_output_synthesis_params)->alpha_synthesis_fast = NULL; + } + + if ((dirac_output_synthesis_state)->reference_power_smooth_prev != NULL) + { + free((dirac_output_synthesis_state)->reference_power_smooth_prev); + (dirac_output_synthesis_state)->reference_power_smooth_prev = NULL; + } + + if ((dirac_output_synthesis_state)->direction_smoothness_prev != NULL) + { + free((dirac_output_synthesis_state)->direction_smoothness_prev); + (dirac_output_synthesis_state)->direction_smoothness_prev = NULL; + } + + if ((dirac_output_synthesis_state)->diffuse_responses_square != NULL) + { + free((dirac_output_synthesis_state)->diffuse_responses_square); + (dirac_output_synthesis_state)->diffuse_responses_square = NULL; + } + + /* free power buffers */ + if ((dirac_output_synthesis_state)->proto_power_smooth_prev != NULL) + { + free((dirac_output_synthesis_state)->proto_power_smooth_prev); + (dirac_output_synthesis_state)->proto_power_smooth_prev = NULL; + } + + if ((dirac_output_synthesis_state)->proto_power_diff_smooth_prev != NULL) + { + free((dirac_output_synthesis_state)->proto_power_diff_smooth_prev); + (dirac_output_synthesis_state)->proto_power_diff_smooth_prev = NULL; + } + + /* free target power buffers */ + if ((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev != NULL) + { + free((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev); + (dirac_output_synthesis_state)->cy_auto_dir_smooth_prev = NULL; + } + if ((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev != NULL) + { + free((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev); + (dirac_output_synthesis_state)->cy_cross_dir_smooth_prev = NULL; + } + if ((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev != NULL) + { + free((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev); + (dirac_output_synthesis_state)->cy_auto_diff_smooth_prev = NULL; + } + + /* free gain buffers */ + if ((dirac_output_synthesis_state)->gains_dir_prev != NULL) + { + free((dirac_output_synthesis_state)->gains_dir_prev); + (dirac_output_synthesis_state)->gains_dir_prev = NULL; + } + if ((dirac_output_synthesis_state)->gains_diff_prev != NULL) + { + free((dirac_output_synthesis_state)->gains_diff_prev); + (dirac_output_synthesis_state)->gains_diff_prev = NULL; + } + +#ifdef IVAS_FLOAT_FIXED + /* free interpolator */ + IF ((dirac_output_synthesis_params)->interpolator_fx != NULL) + { + free((dirac_output_synthesis_params)->interpolator_fx); + (dirac_output_synthesis_params)->interpolator_fx = NULL; + } + + /* free alpha */ + IF ((dirac_output_synthesis_params)->alpha_synthesis_fx != NULL) + { + free((dirac_output_synthesis_params)->alpha_synthesis_fx); + (dirac_output_synthesis_params)->alpha_synthesis_fx = NULL; + } + IF ((dirac_output_synthesis_params)->alpha_synthesis_fast_fx != NULL) + { + free((dirac_output_synthesis_params)->alpha_synthesis_fast_fx); + (dirac_output_synthesis_params)->alpha_synthesis_fast_fx = NULL; + } + + IF ((dirac_output_synthesis_state)->reference_power_smooth_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->reference_power_smooth_prev_fx); + (dirac_output_synthesis_state)->reference_power_smooth_prev_fx = NULL; + } + + IF ((dirac_output_synthesis_state)->direction_smoothness_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->direction_smoothness_prev_fx); + (dirac_output_synthesis_state)->direction_smoothness_prev_fx = NULL; + } + + IF ((dirac_output_synthesis_state)->diffuse_responses_square_fx != NULL) + { + free((dirac_output_synthesis_state)->diffuse_responses_square_fx); + (dirac_output_synthesis_state)->diffuse_responses_square_fx = NULL; + } + + /* free power buffers */ + IF ((dirac_output_synthesis_state)->proto_power_smooth_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->proto_power_smooth_prev_fx); + (dirac_output_synthesis_state)->proto_power_smooth_prev_fx = NULL; + } + + IF ((dirac_output_synthesis_state)->proto_power_diff_smooth_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->proto_power_diff_smooth_prev_fx); + (dirac_output_synthesis_state)->proto_power_diff_smooth_prev_fx = NULL; + } + + /* free target power buffers */ + IF ((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->cy_auto_dir_smooth_prev_fx); + (dirac_output_synthesis_state)->cy_auto_dir_smooth_prev_fx = NULL; + } + IF ((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->cy_cross_dir_smooth_prev_fx); + (dirac_output_synthesis_state)->cy_cross_dir_smooth_prev_fx = NULL; + } + IF ((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->cy_auto_diff_smooth_prev_fx); + (dirac_output_synthesis_state)->cy_auto_diff_smooth_prev_fx = NULL; + } + /* free gain buffers */ + IF ((dirac_output_synthesis_state)->gains_dir_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->gains_dir_prev_fx); + (dirac_output_synthesis_state)->gains_dir_prev_fx = NULL; + } + IF ((dirac_output_synthesis_state)->gains_diff_prev_fx != NULL) + { + free((dirac_output_synthesis_state)->gains_diff_prev_fx); + (dirac_output_synthesis_state)->gains_diff_prev_fx = NULL; + } +#endif + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_process_slot() * @@ -2420,6 +3135,64 @@ static void computeTargetPSDs_diffuse_with_onsets( return; } +#ifdef IVAS_FLOAT_FIXED +static void computeAlphaSynthesis_fx(Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs) +{ + Word16 k; + Word16 avg_length_f_ms_fx; + + /* check input pointer */ + IF (alpha_synthesis_fx == NULL) + { + return; + } + + IF (averaging_length_ms == 0) + { + set16_fx(alpha_synthesis_fx, MAX16B, num_freq_bands); + } + ELSE + { + FOR (k = 0; k < num_freq_bands; k++) + { + Word16 faxis_idx = s_max(k, 1); + //avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); + Word16 tmp_exp = 0; + Word16 tmp_1 = BASOP_Util_Divide1616_Scale(averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp); + Word16 tmp_2 = mult(tmp_1, 1000);//15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) + avg_length_f_ms_fx = tmp_2; + + + Word32 tmp_3 = Mpy_32_16_1(output_Fs, avg_length_f_ms_fx);//0 - tmp_exp - 15 (Q-fac) + Word16 tmp_exp_3 = 0; + Word16 tmp_4 = BASOP_Util_Divide3232_Scale(tmp_3 , 1000, &tmp_exp_3); + Word16 tmp_exp_4 = tmp_exp_3 + (31 + tmp_exp + 15 ) - 31; + Word16 tmp_exp_5 = 0; + Word16 tmp_5 = BASOP_Util_Divide1616_Scale(slot_size , tmp_4, &tmp_exp_5); + Word16 res_exp = tmp_exp_5 + 15 - tmp_exp_4; + + Word16 flag = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(tmp_5), res_exp, 1, 31); + IF (flag == -1) { + alpha_synthesis_fx[k] = shr(tmp_5, negate(res_exp)); //q15 + } + ELSE { + alpha_synthesis_fx[k] = MAX16B; + } + + Word16 flag2 = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(alpha_synthesis_fx[k]), 0, L_deposit_h(maxAlpha_fx), 0); + IF (flag2 == 0 || flag2 == 1) + { + alpha_synthesis_fx[k] = maxAlpha_fx; + *numAlphas = k + 1; + break; + } + } + } + + return; +} +#endif + static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, @@ -2428,29 +3201,29 @@ static void computeAlphaSynthesis( const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, - const int32_t output_Fs ) + const int32_t output_Fs) { int16_t k; float avg_length_f_ms; /* check input pointer */ - if ( alpha_synthesis == NULL ) + if (alpha_synthesis == NULL) { return; } - if ( averaging_length_ms == 0 ) + if (averaging_length_ms == 0) { - set_f( alpha_synthesis, 1.0f, num_freq_bands ); + set_f(alpha_synthesis, 1.0f, num_freq_bands); } else { - for ( k = 0; k < num_freq_bands; k++ ) + for (k = 0; k < num_freq_bands; k++) { - int16_t faxis_idx = max( k, 1 ); - avg_length_f_ms = 1000.f * (float) averaging_length_ms / fabsf( frequency_axis[faxis_idx] ); - alpha_synthesis[k] = min( (float) slot_size / ( avg_length_f_ms * (float) output_Fs / 1000.f ), 1.0f ); - if ( alpha_synthesis[k] >= maxAlpha ) + int16_t faxis_idx = max(k, 1); + avg_length_f_ms = 1000.f * (float)averaging_length_ms / fabsf(frequency_axis[faxis_idx]); + alpha_synthesis[k] = min((float)slot_size / (avg_length_f_ms * (float)output_Fs / 1000.f), 1.0f); + if (alpha_synthesis[k] >= maxAlpha) { alpha_synthesis[k] = maxAlpha; *numAlphas = k + 1; @@ -2462,6 +3235,7 @@ static void computeAlphaSynthesis( return; } + static void spreadCoherencePanningHoa( const int16_t azimuth, const int16_t elevation, diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 36c0b13df..9c8655153 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -388,19 +388,19 @@ ivas_error ivas_dirac_allocate_parameters_fx( * * *-------------------------------------------------------------------------*/ - -ivas_error ivas_spat_hSpatParamRendCom_config( +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_spat_hSpatParamRendCom_config_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ - const int16_t dec_param_estim_flag, + const Word16 dec_param_estim_flag, const IVAS_FORMAT ivas_format, const MC_MODE mc_mode, - const int32_t output_Fs, - const int16_t hodirac_flag, - const int16_t masa_ext_rend_flag ) + const Word32 output_Fs, + const Word16 hodirac_flag, + const Word16 masa_ext_rend_flag ) { ivas_error error; - int16_t map_idx; + Word16 map_idx; DIRAC_CONFIG_FLAG flag_config; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -409,17 +409,17 @@ ivas_error ivas_spat_hSpatParamRendCom_config( hSpatParamRendCom = NULL; - if ( flag_config == DIRAC_RECONFIGURE ) + IF( flag_config == DIRAC_RECONFIGURE ) { hSpatParamRendCom = *hSpatParamRendCom_out; } - else if ( flag_config == DIRAC_OPEN ) + ELSE IF( flag_config == DIRAC_OPEN ) { /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - 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 meta\n" ) ); } @@ -427,16 +427,28 @@ ivas_error ivas_spat_hSpatParamRendCom_config( *hSpatParamRendCom_out = hSpatParamRendCom; } - if ( flag_config == DIRAC_OPEN ) + Word16 tmp1, tmp2, var1, var2; + + Word16 exp_tmp1 = 0; + tmp1 = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &exp_tmp1 ); + Word16 exp_tmp2 = 0; + tmp2 = BASOP_Util_Divide1616_Scale( tmp1, CLDFB_NO_COL_MAX, &exp_tmp2 ); + exp_tmp2 = exp_tmp2 + ( exp_tmp1 - 15 ); + Word16 exp_tmp3 = 0; + + IF( flag_config == DIRAC_OPEN ) { - hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); - 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->slot_size = shr( tmp2, 15 - exp_tmp2 ); // exp_tmp2 + set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; hSpatParamRendCom->subframes_rendered = 0; hSpatParamRendCom->slots_rendered = 0; 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 ); + var1 = BASOP_Util_Divide3232_Scale(output_Fs, CLDFB_BANDWIDTH, &exp_tmp3); + var2 = shl(1, 15 - exp_tmp3 - 1 ); + hSpatParamRendCom->num_freq_bands = shr(add(var1, var2), 15 - exp_tmp3); hSpatParamRendCom->numSimultaneousDirections = 0; hSpatParamRendCom->numParametricDirections = 0; hSpatParamRendCom->numIsmDirections = 0; @@ -446,9 +458,9 @@ ivas_error ivas_spat_hSpatParamRendCom_config( * set input parameters *-----------------------------------------------------------------*/ - if ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && flag_config == DIRAC_RECONFIGURE ) + IF( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && flag_config == DIRAC_RECONFIGURE ) { - if ( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL ) + IF( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL ) { #ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) @@ -459,38 +471,191 @@ ivas_error ivas_spat_hSpatParamRendCom_config( return error; } } - else if ( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL ) + ELSE IF( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL ) { #ifdef IVAS_FLOAT_FIXED - ivas_dirac_deallocate_parameters_fx(hSpatParamRendCom, 2); + ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom, 2 ); #else ivas_dirac_deallocate_parameters( hSpatParamRendCom, 2 ); #endif } } - if ( flag_config == DIRAC_OPEN ) + IF( flag_config == DIRAC_OPEN ) + { + hSpatParamRendCom->dirac_md_buffer_length = 0; + hSpatParamRendCom->dirac_bs_md_write_idx = 0; + hSpatParamRendCom->dirac_read_idx = 0; + IF( mc_mode == MC_MODE_MCMASA || masa_ext_rend_flag == 1 ) + { + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + + set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) + { + hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; + } + } + ELSE IF( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + { + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; + hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; + + set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) + { + hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; + } + } + ELSE + { + Word16 num_slots_in_subfr; + num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + hSpatParamRendCom->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ); + hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; + hSpatParamRendCom->dirac_read_idx = 0; + + set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ ) + { + hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; + } + } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + + IF( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && hodirac_flag ) ) + { +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + } + ELSE + { + hSpatParamRendCom->azimuth2 = NULL; + hSpatParamRendCom->elevation2 = NULL; + hSpatParamRendCom->energy_ratio2_fx = NULL; + hSpatParamRendCom->spreadCoherence2_fx = NULL; + /*TODO: to remove float*/ + hSpatParamRendCom->energy_ratio2 = NULL; + hSpatParamRendCom->spreadCoherence2 = NULL; + } + } + + return error; +} +#else +ivas_error ivas_spat_hSpatParamRendCom_config( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + const int16_t dec_param_estim_flag, + const IVAS_FORMAT ivas_format, + const MC_MODE mc_mode, + const int32_t output_Fs, + const int16_t hodirac_flag, + const int16_t masa_ext_rend_flag) +{ + ivas_error error; + int16_t map_idx; + DIRAC_CONFIG_FLAG flag_config; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + flag_config = (flag_config_inp == DIRAC_RECONFIGURE_MODE) ? DIRAC_RECONFIGURE : flag_config_inp; + error = IVAS_ERR_OK; + + hSpatParamRendCom = NULL; + + if (flag_config == DIRAC_RECONFIGURE) + { + hSpatParamRendCom = *hSpatParamRendCom_out; + } + else if (flag_config == DIRAC_OPEN) + { + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + 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 meta\n")); + } + + *hSpatParamRendCom_out = hSpatParamRendCom; + } + + if (flag_config == DIRAC_OPEN) + { + hSpatParamRendCom->slot_size = (int16_t)((output_Fs / FRAMES_PER_SEC) / CLDFB_NO_COL_MAX); + 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; + hSpatParamRendCom->slots_rendered = 0; + 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); + hSpatParamRendCom->numSimultaneousDirections = 0; + hSpatParamRendCom->numParametricDirections = 0; + hSpatParamRendCom->numIsmDirections = 0; + } + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + + if ((ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT) && flag_config == DIRAC_RECONFIGURE) + { + if (hodirac_flag && hSpatParamRendCom->azimuth2 == NULL) + { + if ((error = ivas_dirac_allocate_parameters(hSpatParamRendCom, 2)) != IVAS_ERR_OK) + { + return error; + } + } + else if (!hodirac_flag && hSpatParamRendCom->azimuth2 != NULL) + { + ivas_dirac_deallocate_parameters(hSpatParamRendCom, 2); + } + } + + if (flag_config == DIRAC_OPEN) { hSpatParamRendCom->dirac_md_buffer_length = 0; hSpatParamRendCom->dirac_bs_md_write_idx = 0; hSpatParamRendCom->dirac_read_idx = 0; - if ( mc_mode == MC_MODE_MCMASA || masa_ext_rend_flag == 1 ) + if (mc_mode == MC_MODE_MCMASA || masa_ext_rend_flag == 1) { hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; - set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) + set_s(hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME); + for (map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++) { hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; } } - else if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + else if (ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT) { hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; - set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) + set_s(hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME); + for (map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++) { hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; } @@ -499,12 +664,12 @@ ivas_error ivas_spat_hSpatParamRendCom_config( { int16_t num_slots_in_subfr; num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - hSpatParamRendCom->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ); + hSpatParamRendCom->dirac_md_buffer_length = (MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR); hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; hSpatParamRendCom->dirac_read_idx = 0; - set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ ) + set_s(hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME); + for (map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++) { hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; } @@ -534,16 +699,12 @@ ivas_error ivas_spat_hSpatParamRendCom_config( hSpatParamRendCom->elevation2 = NULL; hSpatParamRendCom->energy_ratio2 = NULL; hSpatParamRendCom->spreadCoherence2 = NULL; -#ifdef IVAS_FLOAT_FIXED - hSpatParamRendCom->energy_ratio2_fx = NULL; - hSpatParamRendCom->spreadCoherence2_fx = NULL; -#endif } } return error; } - +#endif /*------------------------------------------------------------------------- * ivas_spat_hSpatParamRendCom_close() @@ -558,13 +719,8 @@ void ivas_spat_hSpatParamRendCom_close( { return; } -#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 ); *hSpatParamRendCom_out = NULL; @@ -572,12 +728,146 @@ void ivas_spat_hSpatParamRendCom_close( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_spat_hSpatParamRendCom_close_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out) +{ + IF (hSpatParamRendCom_out == NULL || *hSpatParamRendCom_out == NULL) + { + return; + } + ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 1); + ivas_dirac_deallocate_parameters_fx(*hSpatParamRendCom_out, 2); + + free(*hSpatParamRendCom_out); + *hSpatParamRendCom_out = NULL; + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_rend_close() * * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_rend_close_fx( + DIRAC_REND_HANDLE *hDirACRend_out) +{ + Word16 i, j; + DIRAC_REND_HANDLE hDirACRend; + + IF (hDirACRend_out == NULL || *hDirACRend_out == NULL) + { + return; + } + + hDirACRend = *hDirACRend_out; + + /* close Output synthesis sub-module */ +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_dec_output_synthesis_close_fx(hDirACRend); +#else + ivas_dirac_dec_output_synthesis_close(hDirACRend); +#endif + + /* close Decorrelator sub-module */ + IF (hDirACRend->proto_signal_decorr_on) + { + ivas_dirac_dec_decorr_close(&hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state); + } + + /* Params */ + + /* free frequency axis buffer */ + IF (hDirACRend->frequency_axis != NULL) + { + free(hDirACRend->frequency_axis); + hDirACRend->frequency_axis = NULL; + } +#ifdef IVAS_FLOAT_FIXED + IF(hDirACRend->frequency_axis_fx != NULL) + { + free(hDirACRend->frequency_axis_fx); + hDirACRend->frequency_axis_fx = NULL; + } + IF(hDirACRend->diffuse_response_function_fx != NULL) + { + free(hDirACRend->diffuse_response_function_fx); + hDirACRend->diffuse_response_function_fx = NULL; + } + IF(hDirACRend->hoa_encoder_fx != NULL) + { + free(hDirACRend->hoa_encoder_fx); + hDirACRend->hoa_encoder_fx = NULL; + } +#endif + IF (hDirACRend->diffuse_response_function != NULL) + { + free(hDirACRend->diffuse_response_function); + hDirACRend->diffuse_response_function = NULL; + } + + IF (hDirACRend->hoa_encoder != NULL) + { + free(hDirACRend->hoa_encoder); + hDirACRend->hoa_encoder = NULL; + } + + /* prototype indexing */ + IF (hDirACRend->proto_index_dir != NULL) + { + free(hDirACRend->proto_index_dir); + hDirACRend->proto_index_dir = NULL; + } + + IF (hDirACRend->proto_index_diff != NULL) + { + free(hDirACRend->proto_index_diff); + hDirACRend->proto_index_dir = NULL; + } + + /* States */ + + /* free prototype signal buffers */ + IF (hDirACRend->proto_frame_f != NULL) + { + free(hDirACRend->proto_frame_f); + hDirACRend->proto_frame_f = NULL; + } + + FOR (i = 0; i < DIRAC_NUM_DIMS; i++) + { + FOR (j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++) + { + IF (hDirACRend->buffer_intensity_real[i][j] != NULL) + { + free(hDirACRend->buffer_intensity_real[i][j]); + hDirACRend->buffer_intensity_real[i][j] = NULL; + } + } + } + IF (hDirACRend->buffer_energy != NULL) + { + free(hDirACRend->buffer_energy); + hDirACRend->buffer_energy = NULL; + } + + IF (hDirACRend->masa_stereo_type_detect != NULL) + { + free(hDirACRend->masa_stereo_type_detect); + hDirACRend->masa_stereo_type_detect = NULL; + } + ivas_dirac_free_mem_fx(&(hDirACRend->stack_mem)); + + free(*hDirACRend_out); + *hDirACRend_out = NULL; + + return; +} + +#endif void ivas_dirac_rend_close( DIRAC_REND_HANDLE *hDirACRend_out ) @@ -675,7 +965,6 @@ void ivas_dirac_rend_close( return; } - /*------------------------------------------------------------------------- * ivas_dirac_deallocate_parameters() * @@ -934,6 +1223,7 @@ void ivas_dirac_deallocate_parameters_fx( return; } #endif + void ivas_dirac_deallocate_parameters( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ const int16_t params_flag /* i : set of parameters flag */ @@ -1316,6 +1606,70 @@ ivas_error ivas_dirac_alloc_mem( * * *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_free_mem_fx( + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem) +{ + IF (hDirAC_mem->cy_auto_dir_smooth != NULL) + { + free(hDirAC_mem->cy_auto_dir_smooth); + } + IF (hDirAC_mem->proto_power_smooth != NULL) + { + free(hDirAC_mem->proto_power_smooth); + } + IF (hDirAC_mem->proto_power_diff_smooth != NULL) + { + free(hDirAC_mem->proto_power_diff_smooth); + } + IF (hDirAC_mem->direct_responses_square != NULL) + { + free(hDirAC_mem->direct_responses_square); + } + IF (hDirAC_mem->frame_dec_f != NULL) + { + free(hDirAC_mem->frame_dec_f); + } + IF (hDirAC_mem->cy_cross_dir_smooth != NULL) + { + free(hDirAC_mem->cy_cross_dir_smooth); + } + IF (hDirAC_mem->cy_auto_diff_smooth != NULL) + { + free(hDirAC_mem->cy_auto_diff_smooth); + } + IF (hDirAC_mem->direct_responses != NULL) + { + free(hDirAC_mem->direct_responses); + } + IF (hDirAC_mem->proto_direct_buffer_f != NULL) + { + free(hDirAC_mem->proto_direct_buffer_f); + } + IF (hDirAC_mem->proto_diffuse_buffer_f != NULL) + { + free(hDirAC_mem->proto_diffuse_buffer_f); + } + IF (hDirAC_mem->direct_power_factor != NULL) + { + free(hDirAC_mem->direct_power_factor); + } + IF (hDirAC_mem->diffuse_power_factor != NULL) + { + free(hDirAC_mem->diffuse_power_factor); + } + IF (hDirAC_mem->reference_power != NULL) + { + free(hDirAC_mem->reference_power); + } + IF (hDirAC_mem->onset_filter != NULL) + { + free(hDirAC_mem->onset_filter); + } + + return; +} +#endif void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) @@ -1380,33 +1734,51 @@ void ivas_dirac_free_mem( return; } - /*------------------------------------------------------------------------- * compute_hoa_encoder_mtx() * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void compute_hoa_encoder_mtx_fx( + const Word32 *azimuth, + const Word32 *elevation, + Word32 *response_fx, + const int16_t num_responses, + const int16_t ambisonics_order ) +{ + Word16 k, num_sh; + + num_sh = (Word16)ivas_sba_get_nchan_fx( ambisonics_order, 0 ); + FOR( k = 0; k < num_responses; k++ ) + { + ivas_dirac_dec_get_response_fixed( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order ); // Q29 + } + + return; +} +#endif + void compute_hoa_encoder_mtx( const float *azimuth, const float *elevation, float *response, const int16_t num_responses, - const int16_t ambisonics_order ) + const int16_t ambisonics_order) { int16_t k, num_sh; + + num_sh = ivas_sba_get_nchan(ambisonics_order, 0); - num_sh = ivas_sba_get_nchan( ambisonics_order, 0 ); - - for ( k = 0; k < num_responses; k++ ) + for (k = 0; k < num_responses; k++) { - ivas_dirac_dec_get_response( (const int16_t) azimuth[k], (const int16_t) elevation[k], &response[k * num_sh], ambisonics_order ); + ivas_dirac_dec_get_response((const int16_t)azimuth[k], (const int16_t)elevation[k], &response[k * num_sh], ambisonics_order); } return; } - /*------------------------------------------------------------------------- * ivas_dirac_dec_get_frequency_axis() * @@ -1466,55 +1838,55 @@ void initDiffuseResponses( const int16_t ambisonics_order, const IVAS_FORMAT ivas_format, int16_t *num_ele_spk_no_diffuse_rendering, - const AUDIO_CONFIG transport_config ) + const AUDIO_CONFIG transport_config) { int16_t i, l, k, idx, num_horizontal_speakers; *num_ele_spk_no_diffuse_rendering = 0; - if ( output_config == IVAS_AUDIO_CONFIG_MONO ) + if (output_config == IVAS_AUDIO_CONFIG_MONO) { diffuse_response_function[0] = 1.0f; - diffuse_response_function[1] = inv_sqrt( 3.0f ); + diffuse_response_function[1] = inv_sqrt(3.0f); } - else if ( !( output_config == IVAS_AUDIO_CONFIG_FOA || output_config == IVAS_AUDIO_CONFIG_HOA2 || output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) + else if (!(output_config == IVAS_AUDIO_CONFIG_FOA || output_config == IVAS_AUDIO_CONFIG_HOA2 || output_config == IVAS_AUDIO_CONFIG_HOA3)) { /* set diffuse response function */ - if ( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_5_1_4 ) + if (ivas_format == MC_FORMAT && (transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1) && output_config == IVAS_AUDIO_CONFIG_5_1_4) { num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; - mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers ); - set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); + mvr2r(diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers); + set_zero(&diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; } - else if ( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_7_1_4 ) + else if (ivas_format == MC_FORMAT && (transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1) && output_config == IVAS_AUDIO_CONFIG_7_1_4) { num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; - set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers ); - set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); + set_f(diffuse_response_function, sqrtf(1.f / ((float)num_horizontal_speakers)), num_horizontal_speakers); + set_zero(&diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1 && num_channels == 5 ) + else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && output_config == IVAS_AUDIO_CONFIG_5_1 && num_channels == 5) { - mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); + mvr2r(diffuse_response_CICP6, diffuse_response_function, num_channels); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1_2 && num_channels == 7 ) + else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && output_config == IVAS_AUDIO_CONFIG_5_1_2 && num_channels == 7) { - mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); + mvr2r(diffuse_response_CICP14, diffuse_response_function, num_channels); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) + else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && (output_config == IVAS_AUDIO_CONFIG_5_1_4) && (num_channels == 9)) { - mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); + mvr2r(diffuse_response_CICP16, diffuse_response_function, num_channels); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + else if ((ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT) && (output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM)) { - if ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) + if (transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1) { /* Detect loudspeakers with elevation */ - for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ ) + for (i = 0, num_horizontal_speakers = 0; i < num_channels; i++) { - if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f ) + if (fabsf(hOutSetup.ls_elevation[i]) <= 5.f) { num_horizontal_speakers++; diffuse_response_function[i] = 1.f; @@ -1526,37 +1898,37 @@ void initDiffuseResponses( } } /* Diffuse only to horizontal plane if enough loudspeakers */ - if ( num_horizontal_speakers > 2 ) + if (num_horizontal_speakers > 2) { - for ( i = 0; i < num_channels; i++ ) + for (i = 0; i < num_channels; i++) { - diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers ); + diffuse_response_function[i] *= sqrtf(1.f / (float)num_horizontal_speakers); } } else { *num_ele_spk_no_diffuse_rendering = 0; - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f(diffuse_response_function, sqrtf(1.f / (float)num_channels), num_channels); } } else { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f(diffuse_response_function, sqrtf(1.f / (float)num_channels), num_channels); } } else { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f(diffuse_response_function, sqrtf(1.f / (float)num_channels), num_channels); } } else { idx = 0; - for ( l = 0; l <= ambisonics_order; l++ ) + for (l = 0; l <= ambisonics_order; l++) { - for ( k = 0; k < ( 2 * l + 1 ); k++ ) + for (k = 0; k < (2 * l + 1); k++) { - diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f ); + diffuse_response_function[idx++] = inv_sqrt(2.0f * l + 1.0f); } } } @@ -1564,6 +1936,136 @@ void initDiffuseResponses( return; } +#ifdef IVAS_FLOAT_FIXED +void initDiffuseResponses_fx( + Word16 *diffuse_response_function_fx, + const Word16 num_channels, + const AUDIO_CONFIG output_config, + const IVAS_OUTPUT_SETUP hOutSetup, + const Word16 ambisonics_order, + const IVAS_FORMAT ivas_format, + Word16 *num_ele_spk_no_diffuse_rendering, + const AUDIO_CONFIG transport_config ) +{ + Word16 i, l, k, idx, num_horizontal_speakers; + *num_ele_spk_no_diffuse_rendering = 0; + + Word16 var1, exp_var1, res; + + IF( output_config == IVAS_AUDIO_CONFIG_MONO ) + { + diffuse_response_function_fx[0] = MAX16B; + diffuse_response_function_fx[1] = 18918 /*inv_sqrt(3.0f) oin Q15*/; + } + ELSE IF( !( output_config == IVAS_AUDIO_CONFIG_FOA || output_config == IVAS_AUDIO_CONFIG_HOA2 || output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) + { + /* set diffuse response function */ + IF( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_5_1_4 ) + { + num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); + set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); + *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; + } + ELSE IF( ivas_format == MC_FORMAT && ( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) && output_config == IVAS_AUDIO_CONFIG_7_1_4 ) + { + num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + var1, exp_var1 = 15; + var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); + var1 = shr( var1, negate( exp_var1 ) ); // Q15 + set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); + set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); + *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; + } + ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1 && num_channels == 5 ) + { + Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); + } + ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == IVAS_AUDIO_CONFIG_5_1_2 && num_channels == 7 ) + { + Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); + } + ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) + { + Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); + } + ELSE IF( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + { + IF( transport_config == IVAS_AUDIO_CONFIG_5_1 || transport_config == IVAS_AUDIO_CONFIG_7_1 ) + { + /* Detect loudspeakers with elevation */ + num_horizontal_speakers = 0; + FOR( i = 0; i < num_channels; i++ ) + { + IF( LE_32( abs( hOutSetup.ls_elevation_fx[i] ), 20971520 ) /*5 in Q22*/ ) + { + num_horizontal_speakers = add( num_horizontal_speakers, 1 ); + diffuse_response_function_fx[i] = MAX16B; + } + ELSE + { + *num_ele_spk_no_diffuse_rendering = add( *num_ele_spk_no_diffuse_rendering, 1 ); + diffuse_response_function_fx[i] = 0; + } + } + /* Diffuse only to horizontal plane IF enough loudspeakers */ + IF( GT_16( num_horizontal_speakers, 2 ) ) + { + exp_var1 = 15; + Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); + num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); + assert( 0 ); + /*No stream hitting*/ + FOR( i = 0; i < num_channels; i++ ) + { + diffuse_response_function_fx[i] = shr( mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ), Q15 ); + } + } + ELSE + { + var1 = num_channels, exp_var1 = 15; + res = ISqrt16( var1, &exp_var1 ); + res = shr( res, negate( exp_var1 ) ); + set16_fx( diffuse_response_function_fx, res, num_channels ); + *num_ele_spk_no_diffuse_rendering = 0; + } + } + ELSE + { + var1 = num_channels, exp_var1 = 15; + res = ISqrt16( var1, &exp_var1 ); + res = shr( res, negate( exp_var1 ) ); + set16_fx( diffuse_response_function_fx, res, num_channels ); + } + } + ELSE + { + var1 = num_channels, exp_var1 = 15; + res = ISqrt16( var1, &exp_var1 ); + res = shr( res, negate( exp_var1 ) ); + set16_fx( diffuse_response_function_fx, res, num_channels ); + } + } + ELSE + { + idx = 0; + Word16 j; + FOR( l = 0; l <= ambisonics_order; l++ ) + { + j = add( imult1616( 2, l ), 1 ); + FOR( k = 0; k < j; k++ ) + { + var1 = j, exp_var1 = 15; + res = ISqrt16( var1, &exp_var1 ); + diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); + idx = add( idx, 1 ); + } + } + } + + return; +} +#endif /*------------------------------------------------------------------------- * protoSignalComputation_shd() @@ -2306,7 +2808,65 @@ void computeDirectionAngles( * * Initialize stereo transport signal type detection *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_init_stereotype_detection_fx( + MASA_STEREO_TYPE_DETECT *stereo_type_detect) +{ + /*TODO : to clean up float code*/ + stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ + stereo_type_detect->right_bb_power = 0.0f; + stereo_type_detect->total_bb_power = 0.0f; + + stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ + stereo_type_detect->right_hi_power = 0.0f; + stereo_type_detect->total_hi_power = 0.0f; + + set_zero(stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS); + set_zero(stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS); + + stereo_type_detect->subtract_power_y = 0.0f; + 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; + stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; + + stereo_type_detect->counter = 0; + stereo_type_detect->interpolator = 0; + + stereo_type_detect->dipole_freq_range[0] = 1; + stereo_type_detect->dipole_freq_range[1] = 3; + + stereo_type_detect->left_bb_power_fx = 0; /* Broadband estimates */ + stereo_type_detect->right_bb_power_fx = 0; + stereo_type_detect->total_bb_power_fx = 0; + + stereo_type_detect->left_hi_power_fx = 0; /* High-frequency estimates */ + stereo_type_detect->right_hi_power_fx = 0; + stereo_type_detect->total_hi_power_fx = 0; + set16_fx(stereo_type_detect->sum_power_fx, 0,MASA_SUM_FREQ_RANGE_BINS); + set16_fx(stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS); + + stereo_type_detect->subtract_power_y_fx = 0; + stereo_type_detect->subtract_power_y_smooth_fx = 0; + stereo_type_detect->target_power_y_smooth_fx = 0; + + stereo_type_detect->lr_total_bb_ratio_db_fx = 0; + stereo_type_detect->lr_total_hi_ratio_db_fx = 0; + stereo_type_detect->min_sum_total_ratio_db_fx = 0; + stereo_type_detect->subtract_target_ratio_db_fx = 0; + + return; +} +#endif void ivas_masa_init_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ) { diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 70020c152..bde5bff23 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -374,6 +374,22 @@ void initDiffuseResponses( int16_t *num_ele_spk_no_diffuse_rendering, const AUDIO_CONFIG transport_config ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_free_mem_fx( + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem +); + +void initDiffuseResponses_fx( + Word16 *diffuse_response_function_fx, + const int16_t num_channels, + const AUDIO_CONFIG output_config, + const IVAS_OUTPUT_SETUP hOutSetup, + const int16_t ambisonics_order, + const IVAS_FORMAT ivas_format, + int16_t *num_ele_spk_no_diffuse_rendering, + const AUDIO_CONFIG transport_config +); +#endif void computeIntensityVector_dec( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -460,6 +476,12 @@ void ivas_masa_init_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_init_stereotype_detection_fx( + MASA_STEREO_TYPE_DETECT *stereo_type_detect +); +#endif + void ivas_masa_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); @@ -547,6 +569,27 @@ void ivas_dirac_dec_output_synthesis_init( const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_dec_output_synthesis_open_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +void ivas_dirac_dec_output_synthesis_init_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const Word16 nchan_out_woLFE, /* i : number of output audio channels without LFE */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +void ivas_dirac_dec_output_synthesis_close_fx( + DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */ +); +#endif void ivas_dirac_dec_output_synthesis_close( DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */ ); @@ -601,6 +644,15 @@ void compute_hoa_encoder_mtx( const int16_t num_responses, const int16_t ambisonics_order ); +#ifdef IVAS_FLOAT_FIXED +void compute_hoa_encoder_mtx_fx( + const Word32 *azimuth, + const Word32 *elevation, + Word32 *response_fx, + const Word16 num_responses, + const Word16 ambisonics_order); +#endif + void ivas_dirac_dec_compute_gain_factors( const int16_t num_freq_bands, const float *diffuseness, @@ -663,6 +715,25 @@ ivas_error ivas_dirac_allocate_parameters( ); #ifdef IVAS_FLOAT_FIXED +void ivas_dirac_rend_close_fx( + DIRAC_REND_HANDLE *hDirACRend_out +); + +void ivas_spat_hSpatParamRendCom_close_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out +); + +ivas_error ivas_spat_hSpatParamRendCom_config_fx( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, + const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + const Word16 dec_param_estim_flag, + const IVAS_FORMAT ivas_format, + const MC_MODE mc_mode, + const Word32 output_Fs, + const Word16 hodirac_flag, + const Word16 masa_ext_rend_flag +); + ivas_error ivas_dirac_allocate_parameters_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ const int16_t params_flag /* i : set of parameters flag */ @@ -673,6 +744,7 @@ void ivas_dirac_deallocate_parameters_fx( const int16_t params_flag /* i : set of parameters flag */ ); #endif + void ivas_dirac_deallocate_parameters( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ const int16_t params_flag /* i : set of parameters flag */ diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 92eb19cdb..b91662a46 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -40,6 +40,18 @@ * DirAC renderer ROM tables *----------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +const Word32 ls_azimuth_4d4_fx[8] = { 188743680, -188743680, 566231040, -566231040, 188743680, -188743680, 566231040, -566231040 };//Q22 + +const Word32 ls_elevation_4d4_fx[8] = { 0, 0, 0, 0, 146800640, 146800640, 146800640, 146800640 }; //Q22 + +const Word16 diffuse_response_CICP6_fx[5] = { 13824, 13824, 12137, 16495, 16495 };//Q15 + +const Word16 diffuse_response_CICP14_fx[7] = { 12507, 12507, 9237, 17691, 17691, 4977, 4977 };//Q15 + +const Word16 diffuse_response_CICP16_fx[9] = { 11324, 11324, 9945, 13513, 13513, 8853, 8853, 9905, 9905 };//Q15 +#endif + const float ls_azimuth_4d4[8] = { 45.0f, -45.0f, 135.0f, -135.0f, 45.0f, -45.0f, 135.0f, -135.0f }; const float ls_elevation_4d4[8] = { 0.0f, 0.0f, 0.0f, 0.0f, 35.0f, 35.0f, 35.0f, 35.0f }; diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 0f9b43177..c8d25547d 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -47,6 +47,13 @@ extern const float ls_elevation_4d4[8]; extern const float diffuse_response_CICP6[5]; extern const float diffuse_response_CICP14[7]; extern const float diffuse_response_CICP16[9]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 ls_azimuth_4d4_fx[8]; +extern const Word32 ls_elevation_4d4_fx[8]; +extern const Word16 diffuse_response_CICP6_fx[5]; +extern const Word16 diffuse_response_CICP14_fx[7]; +extern const Word16 diffuse_response_CICP16_fx[9]; +#endif extern const int16_t ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const int16_t ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 127697edc..7a26d9ea3 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -64,8 +64,6 @@ typedef struct ivas_output_setup_structure const Word32 *ls_azimuth_fx; const Word32 *ls_elevation_fx; #endif - - UWord8 separateChannelEnabled; Word16 separateChannelIndex; @@ -273,6 +271,11 @@ typedef struct dirac_output_synthesis_params_structure float *interpolator; float *alpha_synthesis; float *alpha_synthesis_fast; +#ifdef IVAS_FLOAT_FIXED + Word16 *interpolator_fx; + Word16 *alpha_synthesis_fx; + Word16 *alpha_synthesis_fast_fx; +#endif int16_t numAlphas; int16_t numAlphasFast; @@ -280,6 +283,10 @@ typedef struct dirac_output_synthesis_params_structure float diffuse_compensation_factor; float diffuse_compensation_factor_decorr; +#ifdef IVAS_FLOAT_FIXED + Word16 diffuse_compensation_factor_fx; + Word16 diffuse_compensation_factor_decorr_fx; +#endif } DIRAC_OUTPUT_SYNTHESIS_PARAMS; @@ -324,6 +331,47 @@ typedef struct dirac_output_synthesis_state_structure float *reference_power_smooth_prev; float *direction_smoothness_prev; +#ifdef IVAS_FLOAT_FIXED + /* only pointer to local buffers */ + Word16 *direct_responses_fx; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + Word16 *direct_responses_square_fx; + Word16 *diffuse_responses_square_fx; /* squared diffuse responses. Size: num_channels. */ + + /* only pointer to local buffers */ + Word16 *direct_power_factor_fx; + Word16 *diffuse_power_factor_fx; + + Word16 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + Word16 *proto_power_smooth_prev_fx; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ + + Word16 *proto_power_diff_smooth_fx; + Word16 *proto_power_diff_smooth_prev_fx; + + /* only pointer to local buffers */ + Word16 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word16 *proto_diffuse_buffer_f_fx; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + + /* Output gain memories */ + Word16 *gains_dir_prev_fx; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ + Word16 *gains_diff_prev_fx; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ + + /* only pointer to local buffers */ + Word16 *cy_auto_dir_smooth_fx; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 *cy_cross_dir_smooth_fx; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 *cy_auto_diff_smooth_fx; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + + /* PSD memories */ + Word16 *cy_auto_dir_smooth_prev_fx; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + Word16 *cy_cross_dir_smooth_prev_fx; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + Word16 *cy_auto_diff_smooth_prev_fx; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + + const Word16 *onset_filter_fx; + + /* Temporal smoothing memories */ + Word16 *reference_power_smooth_prev_fx; + Word16 *direction_smoothness_prev_fx; +#endif + } DIRAC_OUTPUT_SYNTHESIS_STATE; /* MASA stereo transport signal type detection structure */ @@ -355,6 +403,28 @@ typedef struct float min_sum_total_ratio_db; float subtract_target_ratio_db; +#ifdef IVAS_FLOAT_FIXED + Word16 left_bb_power_fx; + Word16 right_bb_power_fx; + Word16 total_bb_power_fx; + + Word16 left_hi_power_fx; + Word16 right_hi_power_fx; + Word16 total_hi_power_fx; + + Word16 sum_power_fx[MASA_SUM_FREQ_RANGE_BINS]; + Word16 total_power_fx[MASA_SUM_FREQ_RANGE_BINS]; + + Word16 subtract_power_y_fx; + Word16 subtract_power_y_smooth_fx; + Word16 target_power_y_smooth_fx; + + Word16 lr_total_bb_ratio_db_fx; + Word16 lr_total_hi_ratio_db_fx; + Word16 min_sum_total_ratio_db_fx; + Word16 subtract_target_ratio_db_fx; +#endif + int16_t counter; int16_t interpolator; @@ -437,6 +507,13 @@ typedef struct ivas_dirac_rend_data_structure float *frequency_axis; float *diffuse_response_function; +#ifdef IVAS_FLOAT_FIXED + Word16 *buffer_intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; + Word16 *buffer_energy_fx; + Word16 *diffuse_response_function_fx; + Word16 *frequency_axis_fx; + Word32 *hoa_encoder_fx; +#endif float *hoa_encoder; #ifndef IVAS_FLOAT_FIXED const float *hoa_decoder; @@ -463,6 +540,10 @@ typedef struct ivas_dirac_rend_data_structure /*Decoder states=memories*/ float *proto_frame_f; float *proto_frame_dec_f; +#ifdef IVAS_FLOAT_FIXED + Word16 *proto_frame_f_fx; + Word16 *proto_frame_dec_f_fx; +#endif DIRAC_DEC_STACK_MEM stack_mem; MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3221284f4..8757e84a9 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -8673,7 +8673,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( Word16 *frequency_axis_fx = ( Word16 * ) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ); ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands ); - FOR(int i = 0; i < hSpatParamRendCom->num_freq_bands; i++) { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++) { hDirACRend->frequency_axis[i] = (float)frequency_axis_fx[i]; } #else @@ -9149,11 +9149,17 @@ static ivas_error initMasaExtRenderer( if ( hMasaExtRend->renderer_type != RENDERER_DISABLE ) { int16_t subframe; - +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_spat_hSpatParamRendCom_config_fx( &hMasaExtRend->hSpatParamRendCom, DIRAC_OPEN, 0, MASA_FORMAT, MC_MODE_NONE, *( inputMasa->base.ctx.pOutSampleRate ), 0, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_spat_hSpatParamRendCom_config( &hMasaExtRend->hSpatParamRendCom, DIRAC_OPEN, 0, MASA_FORMAT, MC_MODE_NONE, *( inputMasa->base.ctx.pOutSampleRate ), 0, 1 ) ) != IVAS_ERR_OK ) { return error; } +#endif /* Simple population of the metadata index map as no adaptation is present */ set_s( hMasaExtRend->hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); for ( subframe = 0; subframe < MAX_PARAM_SPATIAL_SUBFRAMES; subframe++ ) -- GitLab