diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 5787470e0fbfef766b2b14b562e2800f60befd75..c3389288dedc3c1071630e2c9fa29237ea80ef0e 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -175,6 +175,10 @@ ivas_error ivas_FB_mixer_open( IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate */ IVAS_FB_CFG *fb_cfg /* i : FB config. handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ) { IVAS_FB_MIXER_HANDLE hFbMixer; @@ -186,23 +190,32 @@ ivas_error ivas_FB_mixer_open( frame_len = (int16_t) ( sampling_rate / FRAMES_PER_SEC ); +#ifdef SBA_BR_SWITCHING_CLEAN_UP + hFbMixer = *hFbMixer_out; - if ( ( hFbMixer = (IVAS_FB_MIXER_HANDLE) malloc( sizeof( IVAS_FB_MIXER_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - - if ( fb_cfg->num_out_chans > 0 ) + if ( !spar_reconfig_flag ) { - if ( ( hFbMixer->pFb = (ivas_filterbank_t *) malloc( sizeof( ivas_filterbank_t ) ) ) == NULL ) +#endif + if ( ( hFbMixer = (IVAS_FB_MIXER_HANDLE) malloc( sizeof( IVAS_FB_MIXER_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } + + if ( fb_cfg->num_out_chans > 0 ) + { + if ( ( hFbMixer->pFb = (ivas_filterbank_t *) malloc( sizeof( ivas_filterbank_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } + } + else + { + hFbMixer->pFb = NULL; + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } - else - { - hFbMixer->pFb = NULL; - } +#endif + if ( fb_cfg->active_w_mixing == -1 ) { num_chs_alloc = 0; @@ -247,6 +260,7 @@ ivas_error ivas_FB_mixer_open( { num_chs_alloc = fb_cfg->num_in_chans; } + for ( i = 0; i < num_chs_alloc; i++ ) { if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) @@ -275,61 +289,77 @@ ivas_error ivas_FB_mixer_open( } } - if ( fb_cfg->num_out_chans > 0 ) +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) { - const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; +#endif + if ( fb_cfg->num_out_chans > 0 ) + { + const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; - num_bands = ivas_get_num_bands( sampling_rate ); + num_bands = ivas_get_num_bands( sampling_rate ); - ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate ); + ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate ); - if ( fb_cfg->active_w_mixing != -1 ) - { - for ( i = 0; i < num_bands; i++ ) + if ( fb_cfg->active_w_mixing != -1 ) { - if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) + for ( i = 0; i < num_bands; i++ ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } } } - } - if ( sampling_rate != 48000 ) - { - int16_t num_diff_bands, start_diff_band_non48k; + if ( sampling_rate != 48000 ) + { + int16_t num_diff_bands, start_diff_band_non48k; - num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K; - start_diff_band_non48k = num_bands - num_diff_bands; + num_diff_bands = MAX_NUM_BANDS_DIFF_NON48K; + start_diff_band_non48k = num_bands - num_diff_bands; - hFbMixer->num_diff_bands = num_diff_bands; + hFbMixer->num_diff_bands = num_diff_bands; - for ( j = start_diff_band_non48k; j < num_bands; j++ ) - { - if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) + for ( j = start_diff_band_non48k; j < num_bands; j++ ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } + if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } - if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); + } } } } - } - else - { + else + { - /* ignore all the deeper filter bank stuff for now */ - hFbMixer->num_diff_bands = 0; + /* ignore all the deeper filter bank stuff for now */ + hFbMixer->num_diff_bands = 0; + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } +#endif hFbMixer->fb_cfg = fb_cfg; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + set_s( hFbMixer->first_frame, 1, hFbMixer->fb_cfg->num_out_chans ); + set_s( hFbMixer->first_frame + hFbMixer->fb_cfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - hFbMixer->fb_cfg->num_out_chans ); - if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK ) + if ( !spar_reconfig_flag ) { - return error; +#endif + if ( ( error = ivas_filterbank_setup( hFbMixer, sampling_rate ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } +#endif *hFbMixer_out = hFbMixer; @@ -344,8 +374,12 @@ ivas_error ivas_FB_mixer_open( *------------------------------------------------------------------------*/ void ivas_FB_mixer_close( - IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ - const int32_t sampling_rate /* i : sampling rate in Hz */ + IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ + const int32_t sampling_rate /* i : sampling rate in Hz */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ) { IVAS_FB_MIXER_HANDLE hFbMixer; @@ -405,40 +439,46 @@ void ivas_FB_mixer_close( hFbMixer->prior_mixer[0][0] = NULL; } - if ( fb_cfg->num_out_chans > 0 ) +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) { - num_bands = hFbMixer->pFb->filterbank_num_bands; - - if ( fb_cfg->active_w_mixing != -1 ) +#endif + if ( fb_cfg->num_out_chans > 0 ) { - for ( i = 0; i < num_bands; i++ ) + num_bands = hFbMixer->pFb->filterbank_num_bands; + + if ( fb_cfg->active_w_mixing != -1 ) { - free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); - hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; + for ( i = 0; i < num_bands; i++ ) + { + free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); + hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; + } } - } - - if ( sampling_rate != 48000 ) - { - int16_t start_diff_band_non48k; - start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands; - for ( j = start_diff_band_non48k; j < num_bands; j++ ) + if ( sampling_rate != 48000 ) { - free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] ); - hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = NULL; + int16_t start_diff_band_non48k; + start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands; - free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] ); - hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = NULL; + for ( j = start_diff_band_non48k; j < num_bands; j++ ) + { + free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] ); + hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = NULL; + + free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] ); + hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[1][j] = NULL; + } } } + if ( hFbMixer->pFb != NULL ) + { + free( hFbMixer->pFb ); + hFbMixer->pFb = NULL; + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } - - if ( hFbMixer->pFb != NULL ) - { - free( hFbMixer->pFb ); - hFbMixer->pFb = NULL; - } +#endif if ( hFbMixer->fb_cfg != NULL ) { @@ -446,8 +486,15 @@ void ivas_FB_mixer_close( hFbMixer->fb_cfg = NULL; } - free( hFbMixer ); - hFbMixer = NULL; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) + { +#endif + free( hFbMixer ); + hFbMixer = NULL; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + } +#endif } return; @@ -1027,10 +1074,10 @@ static ivas_error ivas_filterbank_setup( IVAS_FB_CFG *pCfg = hFbMixer->fb_cfg; error = IVAS_ERR_OK; - +#ifndef SBA_BR_SWITCHING_CLEAN_UP set_s( hFbMixer->first_frame, 1, pCfg->num_out_chans ); set_s( hFbMixer->first_frame + pCfg->num_out_chans, 0, IVAS_SPAR_MAX_CH - pCfg->num_out_chans ); - +#endif if ( pCfg->num_out_chans > 0 ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 4335929d8c9133efaae0c645ac358f9695ca39a7..9d58810857a44c8f3266483b5b354a336a173acf 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3749,12 +3749,18 @@ void FdCngDecodeDiracMDCTStereoSID( ivas_error ivas_spar_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ,const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ); void ivas_spar_enc_close( SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ const int16_t nchan_inp /* i : number of input channels */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ,const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ); ivas_error ivas_spar_enc( @@ -3767,11 +3773,19 @@ ivas_error ivas_spar_enc( ivas_error ivas_spar_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ); void ivas_spar_dec_close( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const int32_t output_Fs /* i : output sampling rate */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ); ivas_error ivas_spar_dec( @@ -4923,11 +4937,19 @@ ivas_error ivas_FB_mixer_open( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate */ IVAS_FB_CFG *fb_cfg /* i : FB config. handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ); void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ const int32_t sampling_rate /* i : sampling rate in Hz */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ); void ivas_fb_mixer_pcm_ingest( diff --git a/lib_com/options.h b/lib_com/options.h index c58ac012dcb8f333fd233e6f0b79430905b5c298..26bdb5e55ec424021854cfb53a2a59ba3f85d575 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -141,7 +141,7 @@ #define DISABLE_ADAP_RES_COD_TMP /* temporary fix for IVAS-403, disables adaptive residual coding */ /*#define ITD_WINNER_GAIN_MODIFY */ /* ITD optimization - WORK IN PROGRESS */ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ - +#define SBA_BR_SWITCHING_CLEAN_UP /*Issue 114: Clean up changes for the SBA reconfiguation functions*/ #define LOW_RATE_TRANS_CORE_CODER /* Eri: Activate low-rate-encoding-of-transients contribution for core coder, affects MC, MASA and SBA */ #define FIX_197_CREND_INTERFACE #define FIX_329_ENABLE_TD_RENDERER_REVERB_MC /* Eri: Enable reverb for TD renderer for 5.1 and 7.1 with headtracking enabled for IVAS_dec */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f4764893f19fe76e7600a80ad0d1681c40a0ce8c..4ac8658822b73052497a72e4362d556699cfd7ad 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -863,7 +863,11 @@ ivas_error ivas_init_decoder( { if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1720,7 +1724,11 @@ void ivas_destroy_dec( /* Spar handle */ if ( st_ivas->hSpar != NULL ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_spar_dec_close( st_ivas->hSpar, st_ivas->hDecoderConfig->output_Fs, 0 ); +#else ivas_spar_dec_close( st_ivas->hSpar, st_ivas->hDecoderConfig->output_Fs ); +#endif st_ivas->hSpar = NULL; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 98fad8c094ce9346f5f52e3a63edf8a3057231ed..18a54132c7db719557141da4d587078f04bfdb83 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -62,8 +62,12 @@ ivas_error ivas_sba_dec_reconfigure( int16_t sba_dirac_stereo_flag_old; SBA_MODE sba_mode_old; int32_t ivas_total_brate, last_ivas_total_brate; + RENDERER_TYPE old_renderer_type; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; +#endif error = IVAS_ERR_OK; @@ -108,7 +112,11 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { +#ifndef SBA_BR_SWITCHING_CLEAN_UP ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); +#else + ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs, 0 ); +#endif st_ivas->hSpar = NULL; if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) @@ -120,13 +128,18 @@ ivas_error ivas_sba_dec_reconfigure( } else { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + int16_t sba_order_internal; +#else int16_t i, sba_order_internal, nchan_internal; DIRAC_DEC_HANDLE hDirAC = st_ivas->hDirAC; +#endif SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); +#ifndef SBA_BR_SWITCHING_CLEAN_UP + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); if ( hSpar != NULL && nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) { // VE: dirty patch -> reconfiguration of SPAR modules should be used instead !! @@ -186,7 +199,39 @@ ivas_error ivas_sba_dec_reconfigure( } hSpar->i_subframe = 0; } +#else + if ( hSpar != NULL ) + { + if ( ( hSpar->hPCA != NULL ) && ( ( hDecoderConfig->ivas_total_brate != PCA_BRATE ) || ( sba_order_internal != 1 ) ) ) + { + free( st_ivas->hSpar->hPCA ); + hSpar->hPCA = NULL; + } + + if ( nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) + { + + ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs, 1 ); + if ( ( error = ivas_spar_dec_open( st_ivas, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); + } + else + { + if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + hSpar = st_ivas->hSpar; + st_ivas->sba_dirac_stereo_flag = 0; +#endif +#ifndef SBA_BR_SWITCHING_CLEAN_UP /* PCA handle */ if ( hSpar != NULL ) { @@ -239,6 +284,7 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } +#endif } if ( st_ivas->nchan_transport == 1 ) @@ -256,7 +302,6 @@ ivas_error ivas_sba_dec_reconfigure( /* renderer might have changed */ intern_config_old = st_ivas->intern_config; - RENDERER_TYPE old_renderer_type; old_renderer_type = st_ivas->renderer_type; ivas_renderer_select( st_ivas ); @@ -304,6 +349,50 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } + +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( sba_mode_old != st_ivas->sba_mode ) || ( ( st_ivas->sba_mode == SBA_MODE_SPAR ) && ( ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) ) ) ) + { + DIRAC_CONFIG_FLAG flag_config; + + flag_config = DIRAC_OPEN; + if ( st_ivas->hDirAC != NULL ) + { + flag_config = DIRAC_RECONFIGURE_MODE; + if ( ( sba_mode_old == st_ivas->sba_mode ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + { + flag_config = DIRAC_RECONFIGURE; + } + } + + if ( ( error = ivas_dirac_dec_config( st_ivas, flag_config ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) || ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_MONO ) ) && ( ( sba_mode_old != st_ivas->sba_mode ) && ( st_ivas->sba_mode == SBA_MODE_SPAR ) ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + + st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + } +#else if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( sba_mode_old != st_ivas->sba_mode ) ) { DIRAC_CONFIG_FLAG flag_config; @@ -323,6 +412,8 @@ ivas_error ivas_sba_dec_reconfigure( return error; } } +#endif + else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 329391dfcd7022e2cfd8d19b054d0c9f86928c08..7515300681b4cf38a149ac22ad0055011a87b224 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -61,7 +61,11 @@ static void ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); *------------------------------------------------------------------------*/ ivas_error ivas_spar_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ) { SPAR_DEC_HANDLE hSpar; @@ -74,12 +78,20 @@ ivas_error ivas_spar_dec_open( error = IVAS_ERR_OK; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); +#ifdef SBA_BR_SWITCHING_CLEAN_UP + hSpar = st_ivas->hSpar; - /* SPAR decoder handle */ - if ( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) + if ( !spar_reconfig_flag ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" ); +#endif + /* SPAR decoder handle */ + if ( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" ); + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } +#endif output_Fs = st_ivas->hDecoderConfig->output_Fs; @@ -107,7 +119,11 @@ ivas_error ivas_spar_dec_open( fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -181,8 +197,12 @@ ivas_error ivas_spar_dec_open( *------------------------------------------------------------------------*/ void ivas_spar_dec_close( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const int32_t output_Fs /* i : output sampling rate */ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const int32_t output_Fs /* i : output sampling rate */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ) { if ( hSpar != NULL ) @@ -194,7 +214,11 @@ void ivas_spar_dec_close( ivas_td_decorr_dec_close( &hSpar->hTdDecorr ); /* FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hSpar->hFbMixer, output_Fs, spar_reconfig_flag ); +#else ivas_FB_mixer_close( &hSpar->hFbMixer, output_Fs ); +#endif /* AGC */ ivas_spar_agc_dec_close( &hSpar->hAgcDec ); @@ -206,8 +230,15 @@ void ivas_spar_dec_close( hSpar->hPCA = NULL; } - free( hSpar ); - hSpar = NULL; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) + { +#endif + free( hSpar ); + hSpar = NULL; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + } +#endif } return; diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 92c2f80fadf734d36af84bb460cdf56d9afae991..fceb67d58308a02dd3a2dc3d68242fe681e6eca9 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -104,7 +104,11 @@ ivas_error ivas_dirac_enc_open( return error; } /* Allocate and initialize FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -238,7 +242,11 @@ void ivas_dirac_enc_close( if ( hDirAC->hFbMixer != NULL ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs, 0 ); +#else ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs ); +#endif } for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 9293e1a4ab91ac45bae7954666fd9416138d62de..bce42bba9237bba7ac7e48588fcdaa3140b68bb4 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -462,7 +462,11 @@ ivas_error ivas_init_encoder( if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_spar_enc_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -962,7 +966,11 @@ void ivas_destroy_enc( /* SPAR handle */ if ( st_ivas->hSpar != NULL ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_spar_enc_close( st_ivas->hSpar, st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); +#else ivas_spar_enc_close( st_ivas->hSpar, st_ivas->hEncoderConfig->input_Fs, nchan_inp ); +#endif st_ivas->hSpar = NULL; } diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index d7e3a9a35d2aba477f133b5cf6defb554ee2f52b..ef66df5a90cc409d4c634afe68e10eebcaf07ba0 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -281,7 +281,11 @@ ivas_error ivas_param_ism_enc_open( } /* Allocate and initialize FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -320,7 +324,11 @@ void ivas_param_ism_enc_close( const int32_t input_Fs /* i : input sampling_rate */ ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs, 0 ); +#else ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs ); +#endif if ( hDirAC->hParamIsm != NULL ) { diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 1409683ba2e41bb301005afd0fea3bf06133d581..9b1241f234da333c866f7439fb23ad3ae123f270 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -146,7 +146,11 @@ ivas_error ivas_param_mc_enc_open( } /* Allocate and initialize FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hParamMC->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hParamMC->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -365,7 +369,11 @@ void ivas_param_mc_enc_close( { ivas_param_mc_metadata_close( &hParamMC->hMetadataPMC ); +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hParamMC->hFbMixer, sampling_rate, 0 ); +#else ivas_FB_mixer_close( &hParamMC->hFbMixer, sampling_rate ); +#endif free( hParamMC ); diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 4fdf162955b2d9c148dab181d1c087794fe48b3a..7cae277f9a5cb2b7c63bcdf8020dc51b928143be 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -194,7 +194,11 @@ ivas_error ivas_mcmasa_enc_open( } /* Allocate and initialize FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hMcMasa->hFbMixer ), input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hMcMasa->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -217,7 +221,11 @@ ivas_error ivas_mcmasa_enc_open( return error; } +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hMcMasa->hFbMixerLfe ), input_Fs, fb_cfgLfe, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hMcMasa->hFbMixerLfe ), input_Fs, fb_cfgLfe ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -463,11 +471,19 @@ void ivas_mcmasa_enc_close( } } +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hMcMasa->hFbMixer, input_Fs, 0 ); +#else ivas_FB_mixer_close( &hMcMasa->hFbMixer, input_Fs ); +#endif if ( !hMcMasa->separateChannelEnabled ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hMcMasa->hFbMixerLfe, input_Fs, 0 ); +#else ivas_FB_mixer_close( &hMcMasa->hFbMixerLfe, input_Fs ); +#endif } /* intensity 3-dim */ diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 2af2cf76fa2ff72c36bd57eafa7f4d4d55966179..85137454351d2307350b21c5a40797716820e31c 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -106,13 +106,15 @@ ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + int16_t n; +#endif int16_t nSCE_old, nCPE_old, nchan_transport_old; int32_t ivas_total_brate; ivas_error error; ENCODER_CONFIG_HANDLE hEncoderConfig; error = IVAS_ERR_OK; - hEncoderConfig = st_ivas->hEncoderConfig; ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -124,7 +126,11 @@ ivas_error ivas_sba_enc_reconfigure( #ifdef SBA_HPF_TUNING_ENC int16_t analysis_order_old; #endif +#ifdef SBA_BR_SWITCHING_CLEAN_UP + int16_t spar_reconfig_flag; + spar_reconfig_flag = 0; +#endif nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; @@ -135,9 +141,10 @@ ivas_error ivas_sba_enc_reconfigure( #ifdef SBA_HPF_TUNING_ENC analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); + if ( analysis_order_old != st_ivas->sba_analysis_order ) { - int16_t n, i, n_old; + int16_t i, n_old; float **old_mem_hp20_in; n_old = ivas_sba_get_nchan_metadata( analysis_order_old ); @@ -206,20 +213,39 @@ ivas_error ivas_sba_enc_reconfigure( { if ( st_ivas->hSpar == NULL ) { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) +#endif { return error; } - - // VE: TBV - populate 'hSpar->hFrontVad' with 'hCoreCoder[0]' instead of resetting it to init-state? } ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); + +#ifdef SBA_BR_SWITCHING_CLEAN_UP + for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( hDirAC->sba_synchro_buffer[n] != NULL ) + { + free( hDirAC->sba_synchro_buffer[n] ); + hDirAC->sba_synchro_buffer[n] = NULL; + } + } + hDirAC->num_samples_synchro_delay = 0; +#endif } else { +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + +#else ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp ); +#endif st_ivas->hSpar = NULL; } @@ -234,23 +260,24 @@ ivas_error ivas_sba_enc_reconfigure( hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } - /*TODO : Verify if full SPAR close and open can be used instead of submodules close and open */ if ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) { /* FB mixer handle */ if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - // VE: TBV whether 'hFbMixer' can be reused if ( hDirAC->hFbMixer != NULL ) { +#ifndef SBA_BR_SWITCHING_CLEAN_UP ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); +#else + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); +#endif hDirAC->hFbMixer = NULL; } if ( sba_mode_old == SBA_MODE_SPAR ) { - // VE: dirty patch -> reconfiguration of SPAR MD, TD_decorr, FbMixer modules should be used instead !! - +#ifndef SBA_BR_SWITCHING_CLEAN_UP IVAS_FB_CFG *fb_cfg; int16_t nchan_internal, sba_order_internal; int16_t table_idx, active_w_mixing; @@ -291,6 +318,15 @@ ivas_error ivas_sba_enc_reconfigure( { return error; } +#else + spar_reconfig_flag = 1; + ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + + if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } } else @@ -305,13 +341,35 @@ ivas_error ivas_sba_enc_reconfigure( } /* Allocate and initialize FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg, 0 ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } } - } + if ( hDirAC->num_samples_synchro_delay == 0 ) + { + hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + + for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( ( hDirAC->sba_synchro_buffer[n] = (float *) malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hDirAC synchro buffer\n" ) ); + } + set_zero( hDirAC->sba_synchro_buffer[n], hDirAC->num_samples_synchro_delay ); + } + for ( ; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + hDirAC->sba_synchro_buffer[n] = NULL; + } + } + } +#ifndef SBA_BR_SWITCHING_CLEAN_UP /* initalize delay for SPAR/DirAC delay synchronization */ if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) ) { @@ -347,6 +405,9 @@ ivas_error ivas_sba_enc_reconfigure( } hDirAC->num_samples_synchro_delay = 0; } + + +#endif } ivas_dirac_enc_reconfigure( st_ivas ); @@ -356,6 +417,7 @@ ivas_error ivas_sba_enc_reconfigure( mvs2s( hDirAC->dirac_to_spar_md_bands, hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; } + /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index f1e87a59baacf8fae4fbec4fc0db34a6fd251a93..b156c524d27aecd99b375a67541ad869dcf0712d 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -58,7 +58,11 @@ static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, const ENCODER_ *------------------------------------------------------------------------*/ ivas_error ivas_spar_enc_open( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ) { SPAR_ENC_HANDLE hSpar; @@ -71,12 +75,20 @@ ivas_error ivas_spar_enc_open( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + hSpar = st_ivas->hSpar; - /* SPAR encoder handle */ - if ( ( hSpar = (SPAR_ENC_HANDLE) malloc( sizeof( SPAR_ENC_DATA ) ) ) == NULL ) + if ( !spar_reconfig_flag ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder" ); +#endif + /* SPAR encoder handle */ + if ( ( hSpar = (SPAR_ENC_HANDLE) malloc( sizeof( SPAR_ENC_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder" ); + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } +#endif input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); @@ -101,8 +113,12 @@ ivas_error ivas_spar_enc_open( ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ); fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; - /* FB mixer handle */ +/* FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -113,11 +129,21 @@ ivas_error ivas_spar_enc_open( return error; } - /* Transient Detector handle */ - if ( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) { - return error; +#endif + /* Transient Detector handle */ + if ( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } +#endif + + /* initialization */ + hSpar->hMdEnc->table_idx = -1; /* AGC handle */ #ifdef DEBUG_AGC_ENCODER_CMD_OPTION @@ -168,41 +194,48 @@ ivas_error ivas_spar_enc_open( * Allocate and initialize Front-VAD handle *-----------------------------------------------------------------*/ - hSpar->front_vad_flag = 0; - hSpar->front_vad_dtx_flag = 0; - hSpar->force_front_vad = 0; - - if ( hEncoderConfig->Opt_DTX_ON ) +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) { - if ( ( error = front_vad_create( &( hSpar->hFrontVad ), hEncoderConfig ) ) != IVAS_ERR_OK ) - { - return error; - } +#endif + hSpar->front_vad_flag = 0; + hSpar->front_vad_dtx_flag = 0; + hSpar->force_front_vad = 0; - if ( ( hSpar->hCoreCoderVAD = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + if ( hEncoderConfig->Opt_DTX_ON ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); - } + if ( ( error = front_vad_create( &( hSpar->hFrontVad ), hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } - copy_encoder_config( st_ivas, hSpar->hCoreCoderVAD, 1 ); + if ( ( hSpar->hCoreCoderVAD = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); + } + + copy_encoder_config( st_ivas, hSpar->hCoreCoderVAD, 1 ); - hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; #ifdef PARAM_ISM_DTX_CNG - if ( ( error = init_encoder( hSpar->hCoreCoderVAD, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode ) ) != IVAS_ERR_OK ) + if ( ( error = init_encoder( hSpar->hCoreCoderVAD, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode ) ) != IVAS_ERR_OK ) #else if ( ( error = init_encoder( hSpar->hCoreCoderVAD, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1 ) ) != IVAS_ERR_OK ) #endif + { + return error; + } + } + else { - return error; + hSpar->hCoreCoderVAD = NULL; + hSpar->hFrontVad = NULL; } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } - else - { - hSpar->hCoreCoderVAD = NULL; - hSpar->hFrontVad = NULL; - } +#endif /*-----------------------------------------------------------------* * Final assignment @@ -221,27 +254,39 @@ ivas_error ivas_spar_enc_open( *------------------------------------------------------------------------*/ void ivas_spar_enc_close( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder handle */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t nchan_inp /* i : number of input channels */ + SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder handle */ + const int32_t input_Fs, /* i : input sampling rate */ + const int16_t nchan_inp /* i : number of input channels */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + , + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +#endif ) { int16_t num_chans; + if ( hSpar != NULL ) { - /* core-coder-VAD handle */ - if ( hSpar->hCoreCoderVAD != NULL ) +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) { - destroy_core_enc( hSpar->hCoreCoderVAD ); - hSpar->hCoreCoderVAD = NULL; - } +#endif + /* core-coder-VAD handle */ + if ( hSpar->hCoreCoderVAD != NULL ) + { + destroy_core_enc( hSpar->hCoreCoderVAD ); + hSpar->hCoreCoderVAD = NULL; + } - /* front-VAD handle */ - if ( hSpar->hFrontVad != NULL ) - { - front_vad_destroy( &hSpar->hFrontVad ); - hSpar->hFrontVad = NULL; + /* front-VAD handle */ + if ( hSpar->hFrontVad != NULL ) + { + front_vad_destroy( &hSpar->hFrontVad ); + hSpar->hFrontVad = NULL; + } +#ifdef SBA_BR_SWITCHING_CLEAN_UP } +#endif num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans; assert( num_chans <= nchan_inp ); @@ -253,10 +298,14 @@ void ivas_spar_enc_close( ivas_spar_covar_enc_close( &hSpar->hCovEnc, num_chans ); /* FB mixer handle */ +#ifdef SBA_BR_SWITCHING_CLEAN_UP + ivas_FB_mixer_close( &hSpar->hFbMixer, input_Fs, spar_reconfig_flag ); +#else ivas_FB_mixer_close( &hSpar->hFbMixer, input_Fs ); /* Trans Det handle */ ivas_transient_det_close( &hSpar->hTranDet ); +#endif /* AGC */ ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); @@ -268,8 +317,17 @@ void ivas_spar_enc_close( hSpar->hPCA = NULL; } - free( hSpar ); - hSpar = NULL; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + if ( !spar_reconfig_flag ) + { + /* Trans Det handle */ + ivas_transient_det_close( &hSpar->hTranDet ); +#endif + free( hSpar ); + hSpar = NULL; +#ifdef SBA_BR_SWITCHING_CLEAN_UP + } +#endif } return; diff --git a/tests/conftest.py b/tests/conftest.py index 9896c4908fadbe48b84edaeffc87bf5fe1265c12..ef5f46ffc9c13b590fee7485a18499c6b7daec4f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -450,7 +450,22 @@ def test_vector_path(request) -> str: path = str(path.resolve()) return path + +@pytest.fixture(scope="session") +def br_switch_file_path(request) -> str: + """ + Return base directory of test vector files. + """ + if request.config.option.test_vector_path: + return request.config.option.test_vector_path + here = Path(__file__).parent.resolve() + + path = here.joinpath("../scripts/switchPaths") + + path = str(path.resolve()) + + return path @pytest.fixture(scope="session") def reference_path(request) -> str: diff --git a/tests/test_sba_bs_enc.py b/tests/test_sba_bs_enc.py index 9ea2c8fae944c9f02567668eda7158d24cd2a678..6825ee12ba3d162a21759cbab87d8a8aa8d2aaaa 100644 --- a/tests/test_sba_bs_enc.py +++ b/tests/test_sba_bs_enc.py @@ -53,7 +53,7 @@ dtx_set = ['0', '1'] dict_fsample_bw = {'48': '3', '32': '2', '16': '1'} dict_bw_idx = {'FB': '3', 'SWB': '2', 'WB': '1'} dict_bw_tag = {'SWB': '_ForceSWB', 'WB': '_ForceWB'} -ivas_br_FOA = ['32000', '64000', '96000', '160000', '256000', '384000', '512000'] +ivas_br_FOA = ['32000','64000', '96000', '160000', '256000', '384000', '512000','sw_24k4_256k.bin'] ivas_br_HOA2 = ['256000', '384000', '512000'] ivas_br_HOA3 = ['256000', '384000', '512000'] @@ -111,6 +111,7 @@ def test_bypass_enc( ref_encoder_path, reference_path, dut_base_path, + None, tag, fs, ivas_br, @@ -156,6 +157,7 @@ def test_sba_enc_system( dut_base_path, ref_encoder_path, ref_decoder_path, + br_switch_file_path, update_ref, keep_files, ivas_br, @@ -167,7 +169,9 @@ def test_sba_enc_system( if dtx == '1' and ivas_br not in ['32000', '64000']: # skip high bitrates for DTX until DTX issue is resolved pytest.skip() - + if ivas_br == 'sw_24k4_256k.bin' and agc != 1: + pytest.skip() + tag = tag + fs + 'c' max_bw = "FB" bypass = -1 @@ -186,6 +190,7 @@ def test_sba_enc_system( ref_encoder_path, reference_path, dut_base_path, + br_switch_file_path, tag, fs, ivas_br, @@ -252,6 +257,7 @@ def test_spar_hoa2_enc_system( ref_encoder_path, reference_path, dut_base_path, + None, tag, fs, ivas_br, @@ -315,6 +321,7 @@ def test_spar_hoa3_enc_system( ref_encoder_path, reference_path, dut_base_path, + None, tag, fs, ivas_br, @@ -368,7 +375,8 @@ def test_sba_enc_BWforce_system( if dtx == '1' and ivas_br not in ['32000', '64000']: # skip high bitrates for DTX until DTX issue is resolved pytest.skip() - + if ivas_br == 'sw_24k4_256k.bin': + pytest.skip() fs = sample_rate_bw_idx[0] bw = sample_rate_bw_idx[1] tag = tag + fs + 'c' @@ -384,6 +392,7 @@ def test_sba_enc_BWforce_system( ref_encoder_path, reference_path, dut_base_path, + None, tag, fs, ivas_br, @@ -423,6 +432,7 @@ def sba_enc( ref_encoder_path, reference_path, dut_base_path, + br_switch_file_path, tag, sampling_rate, ivas_br, @@ -453,6 +463,8 @@ def sba_enc( tag = tag + dict_bw_tag[ivas_max_bw] tag_out = f"{tag}_ivasbr{ivas_br[:-3]}k_DTX{dtx}" + if ivas_br == 'sw_24k4_256k.bin': + ivas_br = f"{br_switch_file_path}/sw_24k4_256k.bin" short_tag_ext = "" if agc != -1: short_tag_ext += f'_AGC{agc}'