From f5d43a27b81bbcd29b4d825596ece1966ae142d3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 28 Jan 2024 13:05:02 +0530 Subject: [PATCH] Few functions in ivas_masa_dec.c converted to fixed point --- lib_com/ivas_masa_com.c | 152 +++++++++++++++ lib_com/ivas_prot_fx.h | 22 +++ lib_dec/ivas_init_dec.c | 4 + lib_dec/ivas_jbm_dec.c | 21 +++ lib_dec/ivas_masa_dec.c | 390 ++++++++++++++++++++++++++++++++++++++- lib_dec/ivas_omasa_dec.c | 5 + 6 files changed, 592 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 9da241603..976a92fc5 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -478,6 +478,158 @@ void ivas_masa_set_coding_config( return; } +#ifdef IVAS_FLOAT_FIXED +/*--------------------------------------------------------------- + * ivas_masa_set_coding_config_fx() + * + * Sets MASA codec parameters based on bitrate, number of directions, + * and other metadata properties. + *---------------------------------------------------------------*/ + +void ivas_masa_set_coding_config_fx( + MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */ + Word16 *band_mapping, /* o : Band mapping used */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_transport, /* i : number of transport channels (mono/stereo) */ + const UWord8 isMcMasa /* i : toggle for selecting mcMASA specific config */ +) +{ + Word16 i; + UWord8 nbands; + UWord8 nTwoDirBands; + const Word16 *masa_bits_table; + + /* When coming into this function, these values should be already set: + * joinedSubframes; + * useCoherence; + * numberOfDirections; + */ + + /* Setup coding parameters based on the bitrate, transport channel count, subframe metadata information, + * and number of directions in metadata. */ + nbands = 0; + nTwoDirBands = 0; + i = 0; + move16(); + + /* First select correct bit budget table */ + masa_bits_table = masa_bits; + move16(); + + test(); + IF( isMcMasa ) + { + masa_bits_table = mcmasa_bits; + move16(); + } + ELSE IF( LT_32( ivas_total_brate, IVAS_48k ) && EQ_16( nchan_transport, 2 ) ) + { + masa_bits_table = masa_bits_LR_stereo; + move16(); + } + + WHILE( nbands == 0 && LT_16( i, IVAS_NUM_ACTIVE_BRATES ) ) + { + IF( LE_32( ivas_total_brate, ivas_brate_tbl[i + SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES] ) ) + { + Word16 idx_bands; + + test(); + test(); + IF( LT_32( ivas_total_brate, IVAS_48k ) && EQ_16( nchan_transport, 2 ) && GT_16( i, 3 ) ) + { + /* because it uses the bitallocation for the lower bit rates from 'masa_bits_LR_stereo' and it has 4 elements */ + i = 3; + move16(); + } + idx_bands = i; + move16(); + + IF( config->numberOfDirections > 1 ) + { + nTwoDirBands = config->joinedSubframes ? masa_twodir_bands_joined[i] : masa_twodir_bands[i]; + + IF( ( GT_32( ivas_total_brate, IVAS_96k ) && !config->joinedSubframes ) || ( GT_32( ivas_total_brate, IVAS_80k ) && config->joinedSubframes ) ) + { + idx_bands = sub( idx_bands, 1 ); + } + } + + IF( config->joinedSubframes ) + { + nbands = masa_joined_nbands[idx_bands]; + } + ELSE + { + nbands = masa_nbands[idx_bands]; + } + + config->max_metadata_bits = masa_bits_table[i]; + move16(); + + IF( EQ_32( ivas_total_brate, IVAS_64k ) && config->numberOfDirections > 1 ) + { + /* At 64k, we increase metadata bit budget when there is two directions present. */ + config->max_metadata_bits += MASA_EXTRA_BAND_META_BITS; + } + + IF( ( ( EQ_32( ivas_total_brate, IVAS_32k ) && EQ_16( nchan_transport, 2 ) ) || EQ_32( ivas_total_brate, IVAS_48k ) ) && config->joinedSubframes ) + { + /* At 32k and 48k, we increase metadata bit budget when joinedSubframes. */ + config->max_metadata_bits += ( MASA_SMALL_INC_META_BITS ); + } + } + i = add( i, 1 ); + } + config->numCodingBands = nbands; + config->numTwoDirBands = nTwoDirBands; + + IF( config->joinedSubframes == TRUE ) + { + config->mergeRatiosOverSubframes = FALSE; + } + ELSE + { + config->mergeRatiosOverSubframes = TRUE; + } + + /* Setup frequency band mapping based on the number of used coding bands */ + SWITCH( config->numCodingBands ) + { + case 5: + Copy( MASA_band_mapping_24_to_5, band_mapping, 5 + 1 ); + BREAK; + case 8: + Copy( MASA_band_mapping_24_to_8, band_mapping, 8 + 1 ); + BREAK; + case 12: + Copy( MASA_band_mapping_24_to_12, band_mapping, 12 + 1 ); + BREAK; + case 18: + Copy( MASA_band_mapping_24_to_18, band_mapping, 18 + 1 ); + BREAK; + case MASA_FREQUENCY_BANDS: + /* With input count of bands, no mapping is needed but for unified processing later, we store normal mapping */ + FOR( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) + { + band_mapping[i] = i; + move16(); + } + BREAK; + default: + assert( 0 && "Error: The number of MASA coding bands is not supported" ); + } + + config->useCoherence = TRUE; + IF( ( !isMcMasa && LT_32( ivas_total_brate, IVAS_48k ) ) || ( isMcMasa && LT_32( ivas_total_brate, IVAS_16k4 ) ) ) + { + config->useCoherence = FALSE; + } + + return; +} +#endif + /*--------------------------------------------------------------- * masa_sample_rate_band_correction() diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index c15fbcde6..8a5d14f16 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -79,6 +79,28 @@ void ivas_masa_set_elements_fx( const Word32 ism_total_brate /* i : initial ISM total bitrate */ ); +void ivas_masa_set_coding_config_fx( + MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */ + Word16 *band_mapping, /* o : Band mapping used */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_transport, /* i : number of transport channels (mono/stereo) */ + const UWord8 isMcMasa /* i : toggle for selecting mcMASA specific config */ +); + +void ivas_masa_prerender_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output_fx[], /* i/o: synthesized core-coder transport channels */ + Word16 *q_shift, /* o : specifies how much the Q-factor of output has changed by. */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_remapped /* i : number of transports used in core */ +); + +ivas_error ivas_masa_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + Word16 *data /* o : output synthesis signal */ +); + Word16 ivas_jbm_dec_get_num_tc_channels_fx( Decoder_Struct *st_ivas /* i : IVAS decoder handle */ ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index ae58fda4c..589a5ebf3 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -181,7 +181,11 @@ ivas_error ivas_dec_setup( ELSE { +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#else IF ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index ec3e23c68..6d01d5eac 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -495,7 +495,28 @@ ivas_error ivas_jbm_dec_tc( if ( st_ivas->ivas_format == MASA_FORMAT ) { +#ifdef IVAS_FLOAT_FIXED + Word16 q_shift = 0; + FOR(Word16 i = 0; i < 2; i++) + { + output_fx[i] = (Word32 *)malloc(output_frame * sizeof(Word32)); + FOR(Word16 j = 0; j < output_frame; j++) + { + output_fx[i][j] = float_to_fix(p_output[i][j], Q11); + } + } + ivas_masa_prerender_fx( st_ivas, output_fx, &q_shift, output_frame, nchan_remapped ); + FOR(Word16 i = 0; i < 2; i++) + { + FOR(Word16 j = 0; j < output_frame; j++) + { + p_output[i][j] = fix_to_float(output_fx[i][j], Q11 + q_shift); + } + free(output_fx[i]); + } +#else ivas_masa_prerender( st_ivas, p_output, output_frame, nchan_remapped ); +#endif } else if ( st_ivas->ivas_format == SBA_FORMAT && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 0fdf8ee20..5d6a42c68 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1238,11 +1238,11 @@ static ivas_error ivas_masa_dec_config_fx( IF ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } ELSE { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } test(); @@ -1353,6 +1353,48 @@ void ivas_masa_prerender( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * ivas_masa_prerender_fx() + * + * Apply gaining and copying of transport signals when needed + *-------------------------------------------------------------------*/ + +void ivas_masa_prerender_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output_fx[], /* i/o: synthesized core-coder transport channels */ + Word16 *q_shift, /* o : specifies how much the Q-factor of output has changed by. */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nchan_remapped /* i : number of transports used in core */ +) +{ + *q_shift = 0; + move16(); + + test(); + test(); + IF ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 2 ) && EQ_16( nchan_remapped, 1) ) + { + IF ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + { + Copy32( output_fx[0], output_fx[1], output_frame ); /* Copy mono signal to stereo output channels */ + } + ELSE + { + test(); + IF ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) + { + v_multc_fixed( output_fx[0], SQRT2_FIXED, output_fx[0], output_frame ); /* q + 30 - 31 = q - 1*//* Gain transport signal when transmitting mono with cpe in order to match loudness */ + *q_shift = -1; /* Q has decreased by 1. */ + move16(); + } + } + } + + return; +} +#endif + /*-------------------------------------------------------------------* * Local functions @@ -2356,6 +2398,350 @@ ivas_error ivas_masa_dec_reconfigure( } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * ivas_masa_dec_reconfigure_fx() + * + * Reconfigure IVAS MASA decoder + *-------------------------------------------------------------------*/ + +ivas_error ivas_masa_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + Word16 *data /* o : output synthesis signal */ +) +{ + Word16 n, tmp, num_bits; + Word16 sce_id, cpe_id; + UWord16 *bit_stream; + Decoder_State **sts; + UWord32 ivas_total_brate, last_ivas_total_brate; + Word16 numCldfbAnalyses_old, numCldfbSyntheses_old; + ivas_error error; + Word32 ism_total_brate; + + error = IVAS_ERR_OK; + move16(); + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); + last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + move32(); + + IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) ) + { + Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + move16(); + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + move16(); + } + + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + + /* renderer might have changed, reselect */ + ivas_renderer_select( st_ivas ); + + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend == NULL ) || + ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin == NULL ) ) + { + /* init a new DirAC dec */ + IF( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) || EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + { + IF( st_ivas->hDirAC != NULL ) + { + /* close all unnecessary parametric decoding and rendering */ + 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 ) ); + } + } + /* possible reconfigure is done later */ + + /*-----------------------------------------------------------------* + * Allocate and initialize SCE/CPE and other handles + *-----------------------------------------------------------------*/ + + IF( st_ivas->hSCE[0] != NULL ) + { + bit_stream = st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream; + move16(); + } + ELSE + { + bit_stream = st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream; + move16(); + } + + num_bits = 0; + move16(); + + Word16 tmp_e; + Word32 tmp32; + + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + + // st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; + st_ivas->hSCE[sce_id]->element_brate = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); + st_ivas->hSCE[sce_id]->element_brate = L_shr( st_ivas->hSCE[sce_id]->element_brate, sub( 15, tmp_e ) ); + + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + + sts = st_ivas->hSCE[sce_id]->hCoreCoder; + sts[0]->bit_stream = bit_stream + num_bits; + + // num_bits += (int16_t)(st_ivas->hSCE[sce_id]->element_brate / FRAMES_PER_SEC); + tmp = BASOP_Util_Divide3216_Scale( st_ivas->hSCE[sce_id]->element_brate, FRAMES_PER_SEC, &tmp_e ); + tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); + num_bits = add( num_bits, tmp ); + + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) + { + IF( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + // st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); + tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); + st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp32, CPE_CHANNELS ); + + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + tmp = CPE_CHANNELS; + move16(); + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->nCPE = 1; + move16(); + } + /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + // st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / tmp; + tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( st_ivas->hCPE[cpe_id]->element_brate, tmp, &tmp_e ) ); + tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = tmp32; + move32(); + } + sts = st_ivas->hCPE[cpe_id]->hCoreCoder; + sts[0]->bit_stream = bit_stream + num_bits; + + // num_bits += (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); + tmp = BASOP_Util_Divide3216_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_e ); + tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); + num_bits = add( num_bits, tmp ); + + test(); + test(); + test(); + test(); + IF( ( LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GE_32( last_ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || + ( LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_32( last_ivas_total_brate, FRAME_NO_DATA ) ) ) + { + st_ivas->hCPE[cpe_id]->nchan_out = 1; + move16(); + + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) ) + { + IF( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE IF( GE_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && LT_32( last_ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) + { + st_ivas->hCPE[cpe_id]->nchan_out = CPE_CHANNELS; + move16(); + + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) ) + { + IF( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + + IF( st_ivas->hDiracDecBin != NULL ) + { + /* regularization factor is bitrate-dependent */ + st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); + } + + test(); + IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->last_ivas_format, MASA_FORMAT ) ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ + { + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + IF( st_ivas->hDiracDecBin != NULL ) + { + IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + IF( ( error = ivas_cldfb_dec_reconfig( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * Set-up MASA coding elements and bitrates + *-----------------------------------------------------------------*/ + + ism_total_brate = 0; + move32(); + + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->nSCE, 0 ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[n]->element_brate ); + } + } + + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate ); + + IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + { + st_ivas->nchan_ism = 0; + move16(); + st_ivas->ism_mode = ISM_MODE_NONE; + move16(); + } + + { + Word16 tc_nchan_to_allocate; + Word16 tc_nchan_transport; + TC_BUFFER_MODE buffer_mode_new; + Word16 n_samples_granularity; + + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_transport = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + + tc_nchan_to_allocate = tc_nchan_transport; + move16(); + + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + { + tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS + 2; + move16(); + } + ELSE + { + tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; + move16(); + } + test(); + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ + IF( GT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) + { + IF( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + IF( LT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) + { + IF( ( error = ivas_jbm_dec_flush_renderer( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) + { + /* addtl channel for CNG */ + tc_nchan_to_allocate = add( tc_nchan_to_allocate, 1 ); + } + + test(); + test(); + IF( NE_16( tc_nchan_transport, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( buffer_mode_new, st_ivas->hTcBuffer->tc_buffer_mode ) ) + { + IF( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) ) + { + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); + } + + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); + FOR ( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) + { + st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult(st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier); + move16(); + } + } + } + + return error; +} +#endif + + /*-------------------------------------------------------------------* * ivas_spar_param_to_masa_param_mapping() * diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 2d25e7685..8cf66110a 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -38,6 +38,7 @@ #include "ivas_prot_rend.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#include "ivas_prot_fx.h" /*------------------------------------------------------------------------- @@ -193,7 +194,11 @@ ivas_error ivas_omasa_dec_config( { st_ivas->hCPE[0]->nchan_out = 1; } +#ifdef IVAS_FLOAT_FIXED + else if ( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#else else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#endif { return error; } -- GitLab