From de5ff7956f658ef6d1541d656d9070b2f41bdbc7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Sep 2022 14:35:01 +0200 Subject: [PATCH 01/26] first bunch of fixes; under SBA_BITRATE_SWITCHING --- lib_com/ivas_prot.h | 8 +++ lib_com/options.h | 3 +- lib_dec/ivas_sba_dec.c | 107 +++++++++++++++++++++++++---- lib_dec/ivas_spar_decoder.c | 22 ++++-- lib_dec/ivas_stat_dec.h | 2 +- lib_enc/acelp_core_enc.c | 2 +- lib_enc/ivas_dirac_enc.c | 12 +++- lib_enc/ivas_enc.c | 3 + lib_enc/ivas_sba_enc.c | 132 ++++++++++++++++++++++++++++++++---- lib_enc/ivas_sce_enc.c | 28 ++++++-- lib_enc/ivas_spar_encoder.c | 8 +++ lib_enc/ivas_spar_md_enc.c | 11 ++- lib_enc/ivas_stat_enc.h | 7 +- 13 files changed, 297 insertions(+), 48 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c4e93a9545..69ee6bc3fa 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3879,6 +3879,14 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); +#ifdef SBA_BITRATE_SWITCHING +ivas_error ivas_spar_md_enc_init( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +); +#endif + ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ diff --git a/lib_com/options.h b/lib_com/options.h index 54d2700014..954565273d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -60,7 +60,7 @@ /*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ @@ -149,6 +149,7 @@ #define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ #define FIX_I98_HANDLES_TO_NULL /* Issue 98: do the setting of all handles to NULL in one place */ +#define SBA_BITRATE_SWITCHING /* Issue 114: suppport bitrate switching in SBA */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 2eebf6967a..81365260ff 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -108,8 +108,8 @@ void ivas_mc2sba( } else { - azimuth = (int16_t) ( hIntSetup.ls_azimuth[idx_in] ); - elevation = (int16_t) ( hIntSetup.ls_elevation[idx_in] ); + azimuth = ( int16_t )( hIntSetup.ls_azimuth[idx_in] ); + elevation = ( int16_t )( hIntSetup.ls_elevation[idx_in] ); idx_in++; /* get HOA response for direction (ACN/SN3D)*/ @@ -409,8 +409,8 @@ void ivas_ism2sba( for ( i = 0; i < num_objects; i++ ) { - azimuth = (int16_t) ( hIsmMetaData[i]->azimuth + 0.5f ); - elevation = (int16_t) ( hIsmMetaData[i]->elevation + 0.5f ); + azimuth = ( int16_t )( hIsmMetaData[i]->azimuth + 0.5f ); + elevation = ( int16_t )( hIsmMetaData[i]->elevation + 0.5f ); /*get HOA gets for direction (ACN/SN3D)*/ ivas_dirac_dec_get_response( @@ -466,8 +466,10 @@ ivas_error ivas_sba_dec_reconfigure( int16_t sba_dirac_stereo_flag_old; uint16_t i; int32_t ivas_total_brate, last_ivas_total_brate; + DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; + hDecoderConfig = st_ivas->hDecoderConfig; error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -477,6 +479,9 @@ ivas_error ivas_sba_dec_reconfigure( * Allocate, initalize, and configure SBA and rendering handles *-----------------------------------------------------------------*/ +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( last_ivas_total_brate ); +#endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); numCldfbAnalyses = 0; sba_total_brate = ivas_total_brate; @@ -486,10 +491,16 @@ ivas_error ivas_sba_dec_reconfigure( nchan_transport_old = st_ivas->nchan_transport; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); +#endif + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); +#ifndef SBA_BITRATE_SWITCHING ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); st_ivas->nchan_transport = nchan_transport; +#endif /* renderer might have changed */ intern_config_old = st_ivas->intern_config; @@ -503,7 +514,13 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); +#ifdef SBA_BITRATE_SWITCHING + ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); + st_ivas->hSpar = NULL; +#endif + + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { return error; @@ -513,16 +530,39 @@ ivas_error ivas_sba_dec_reconfigure( { int16_t sba_order_internal; +#ifdef SBA_BITRATE_SWITCHING + if ( st_ivas->hSpar == NULL ) + { + if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, + 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_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) { return error; } } +#ifdef SBA_BITRATE_SWITCHING + nchan_transport = st_ivas->nchan_transport; + + if ( nchan_transport == 1 ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } +#endif + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { @@ -541,6 +581,47 @@ ivas_error ivas_sba_dec_reconfigure( } } } +#ifdef SBA_BITRATE_SWITCHING // VE: TBD - possibly merge with the above + else if( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < DIRAC_MAX_NBANDS; n++ ) + { + st_ivas->hSpar->dirac_to_spar_md_bands[n] = st_ivas->hDirAC->dirac_to_spar_md_bands[n]; + } + //mvr2r( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + } +#endif +#ifdef SBA_BITRATE_SWITCHINGaa + 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 ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + + if ( st_ivas->hVBAPdata != NULL ) + { + vbap_free_data( &( st_ivas->hVBAPdata ) ); + } + } +#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 ) @@ -681,7 +762,7 @@ ivas_error ivas_sba_dec_reconfigure( for ( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = ( int16_t )( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; } } @@ -833,7 +914,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -855,7 +936,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -955,7 +1036,7 @@ static void debug_mode_dirac( #ifdef DEBUG_MODE_DIRAC_NOCORE for ( n = 0; n < nchan_transport; n++ ) { - sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, (int16_t) ( output_frame * 0.05 ) ); + sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, ( int16_t )( output_frame * 0.05 ) ); dbgread( tmp, sizeof( int16_t ), output_frame, file_name ); for ( i = 0; i < output_frame; i++ ) { @@ -967,10 +1048,10 @@ static void debug_mode_dirac( { for ( i = 0; i < output_frame; i++ ) { - tmp[i] = (int16_t) ( output[n][i] + 0.5f ); + tmp[i] = ( int16_t )( output[n][i] + 0.5f ); } - sprintf( file_name, "./res/ivas_dirac_dec_%d.%d.pcm", n, (int16_t) ( output_frame * 0.05 ) ); + sprintf( file_name, "./res/ivas_dirac_dec_%d.%d.pcm", n, ( int16_t )( output_frame * 0.05 ) ); dbgwrite( tmp, sizeof( int16_t ), output_frame, 1, file_name ); } #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 4f48e10a09..1837a15783 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -50,7 +50,7 @@ * Local function prototypes *--------------------------------------------------------------------*/ -static void ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); +static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); /*------------------------------------------------------------------------- @@ -254,7 +254,7 @@ ivas_error ivas_spar_dec( st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ - ivas_spar_dec_MD( st_ivas, st0 ); + error = ivas_spar_dec_MD( st_ivas, st0 ); *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig; st0->bit_stream = bit_stream_orig; @@ -604,18 +604,23 @@ int16_t ivas_is_res_channel( * IVAS SPAR MD decoder *-------------------------------------------------------------------*/ -static void ivas_spar_dec_MD( +static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ ) { int16_t num_channels, table_idx, num_bands_out, bfi, sba_order; int32_t ivas_total_brate; - DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig; - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + DECODER_CONFIG_HANDLE hDecoderConfig; + SPAR_DEC_HANDLE hSpar; + ivas_error error; wmops_sub_start( "ivas_spar_dec_MD" ); + hDecoderConfig = st_ivas->hDecoderConfig; + hSpar = st_ivas->hSpar; + error = IVAS_ERR_OK; + /*---------------------------------------------------------------------* * Initialization *---------------------------------------------------------------------*/ @@ -639,7 +644,10 @@ static void ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; - ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ); + if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) + { + return error; + } } } @@ -693,7 +701,7 @@ static void ivas_spar_dec_MD( } wmops_sub_end(); - return; + return error; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index c773491d41..58a94145c4 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -873,7 +873,7 @@ typedef struct ivas_spar_dec_lib_t int16_t AGC_flag; ivas_agc_dec_state_t *hAgcDec; PCA_DEC_STATE *hPCA; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ int32_t i_subframe; diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 8420810339..300fab0425 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -369,6 +369,7 @@ ivas_error acelp_core_enc( nb_bits = 0; st->acelp_cfg.FEC_mode = 0; uc_two_stage_flag = 0; + if ( !nelp_mode && !ppp_mode ) { config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -544,7 +545,6 @@ ivas_error acelp_core_enc( return error; } - if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 557cb109ca..e31c5470a1 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -103,6 +103,7 @@ ivas_error ivas_dirac_enc_open( { return error; } + /* Allocate and initialize FB mixer handle */ if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) { @@ -124,7 +125,10 @@ ivas_error ivas_dirac_enc_open( hDirAC->num_samples_synchro_delay = NS2SA( input_Fs, IVAS_FB_ENC_DELAY_NS ); for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) { - hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ); + if ( ( st_ivas->hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( st_ivas->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[i], hDirAC->num_samples_synchro_delay ); } for ( ; i < IVAS_MAX_NUM_CH; i++ ) @@ -134,6 +138,9 @@ ivas_error ivas_dirac_enc_open( } else { +#ifdef SBA_BITRATE_SWITCHING + hDirAC->num_samples_synchro_delay = 0; +#endif for ( i = 0; i < IVAS_MAX_NUM_CH; i++ ) { hDirAC->sba_synchro_buffer[i] = NULL; @@ -338,6 +345,7 @@ void ivas_dirac_enc( } ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame ); + /* encode parameters */ if ( sba_planar || hQMetaData->useLowerRes ) { @@ -507,11 +515,13 @@ void computeReferencePower_enc( return; } + /*------------------------------------------------------------------------- * ivas_dirac_param_est_enc() * * *------------------------------------------------------------------------*/ + void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 75ffc5212d..927d40f607 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -189,7 +189,9 @@ ivas_error ivas_enc( /* SBA/MASA configuration */ if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_BITRATE_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) +#endif { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { @@ -364,6 +366,7 @@ ivas_error ivas_enc( float tmpF = ivas_total_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); } + dbgwrite( &st_ivas->nchan_transport, sizeof( int16_t ), 1, input_frame, "res/nchan_transport" ); #endif wmops_sub_end(); diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 62fc6d0667..431f4b3655 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -93,10 +93,10 @@ void ivas_sba_getTCs( int16_t tmp[L_FRAME48k]; char file_name[50] = { 0 }; - sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, (int16_t) ( input_frame * 0.05 ) ); + sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, ( int16_t )( input_frame * 0.05 ) ); for ( int16_t i = 0; i < input_frame; i++ ) { - tmp[i] = (int16_t) ( sba_data[n][i] + 0.5f ); + tmp[i] = ( int16_t )( sba_data[n][i] + 0.5f ); } dbgwrite( tmp, sizeof( int16_t ), input_frame, 1, file_name ); } @@ -225,13 +225,15 @@ ivas_error ivas_sba_enc_reconfigure( int16_t n; Indice *ind_list_metadata; int32_t ivas_total_brate; + ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; + hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + ivas_total_brate = hEncoderConfig->ivas_total_brate; - if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { ntransport = st_ivas->nchan_transport; ntransport_old = st_ivas->nchan_transport; @@ -239,9 +241,115 @@ ivas_error ivas_sba_enc_reconfigure( nSCE_old = st_ivas->nSCE; ind_list_metadata = NULL; - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); + +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( st_ivas->hSpar == NULL ) + { + if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + 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 ); + } + else + { + ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp ); + st_ivas->hSpar = NULL; + } + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + /* FB mixer handle */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + // VE: TBV whether 'hFbMixer' can be reused + if( st_ivas->hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( st_ivas->hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); + st_ivas->hDirAC->hFbMixer = NULL; + } + } + else + { + if ( st_ivas->hDirAC->hFbMixer == NULL ) + { + IVAS_FB_CFG *fb_cfg; + + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_DIRAC, DIRAC_MAX_ANA_CHANS, 0, 0, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Allocate and initialize FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &( st_ivas->hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* initalize delay for SPAR/DirAC delay synchronization */ + if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) + { + if ( st_ivas->hDirAC->num_samples_synchro_delay == 0 ) + { + st_ivas->hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + for ( n = 0; n < st_ivas->hEncoderConfig->nchan_inp; n++ ) + { + if( ( st_ivas->hDirAC->sba_synchro_buffer[n] = (float *) count_malloc( st_ivas->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( st_ivas->hDirAC->sba_synchro_buffer[n], st_ivas->hDirAC->num_samples_synchro_delay ); + } + for ( ; n < IVAS_MAX_NUM_CH; n++ ) + { + st_ivas->hDirAC->sba_synchro_buffer[n] = NULL; + } + } + } + else + { + for ( n = 0; n < IVAS_MAX_NUM_CH; n++ ) + { + if ( st_ivas->hDirAC->sba_synchro_buffer[n] != NULL ) + { + count_free( st_ivas->hDirAC->sba_synchro_buffer[n] ); + st_ivas->hDirAC->sba_synchro_buffer[n] = NULL; + } + } + st_ivas->hDirAC->num_samples_synchro_delay = 0; + } +#endif + + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + +#ifdef SBA_BITRATE_SWITCHING + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } +#endif - ivas_dirac_enc_reconfigure( st_ivas ); ntransport = st_ivas->nchan_transport; if ( ntransport == ntransport_old ) @@ -311,7 +419,7 @@ ivas_error ivas_sba_enc_reconfigure( last_ind = hBstr->last_ind; ind_list_metadata = hMetaData->ind_list; - /* destroy superfluous core coder elements */ + /* destroy superfluous core coder elements */ // VE: TBV whether a core-coder can be reused for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) { destroy_sce_enc( st_ivas->hSCE[sce_id] ); @@ -413,7 +521,7 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; } - if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) + if ( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; } @@ -430,7 +538,7 @@ ivas_error ivas_sba_enc_reconfigure( { st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = ( int16_t )( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, @@ -498,7 +606,7 @@ ivas_error ivas_sba_enc_reconfigure( { st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = ( int16_t )( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, @@ -517,8 +625,8 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } - initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, st_ivas->hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, st_ivas->hEncoderConfig->max_bwidth, 0, NULL, 1 ); - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 942dd14c99..aafccdb209 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -165,11 +165,20 @@ ivas_error ivas_sce_enc( /* set "total_brate" */ st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC; + /* set flag for sampling rate of OL S/M classifier */ +#ifdef SBA_BITRATE_SWITCHING // VE: TBV whether it can be done more efficiently + flag_16k_smc = 0; + if( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate ) + { + flag_16k_smc = 0; + } +#else + flag_16k_smc = ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) ); +#endif + #ifdef DEBUG_MODE_INFO dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" ); #endif - /* set flag for sampling rate of OL S/M classifier */ - flag_16k_smc = ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) ); /*----------------------------------------------------------------* * Front Pre-processing @@ -199,8 +208,7 @@ ivas_error ivas_sce_enc( * Reset metadata *----------------------------------------------------------------*/ - reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode, - IVAS_SCE ); + reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode,IVAS_SCE ); /*----------------------------------------------------------------* * Write IVAS format signaling in SID frames @@ -229,11 +237,10 @@ ivas_error ivas_sce_enc( coder_type_modif( st, relE[0] ); /*----------------------------------------------------------------* - * Encoder + * Core Encoder *----------------------------------------------------------------*/ - if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, - flag_16k_smc ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } @@ -246,6 +253,10 @@ ivas_error ivas_sce_enc( /* update input samples buffer */ mvr2r( st->input, st->old_input_signal, input_frame ); +#ifdef SBA_BITRATE_SWITCHING + hSCE->last_element_brate = hSCE->element_brate; +#endif + wmops_sub_end(); return error; @@ -285,6 +296,9 @@ ivas_error create_sce_enc( hSCE->sce_id = sce_id; hSCE->element_brate = element_brate; +#ifdef SBA_BITRATE_SWITCHING + hSCE->last_element_brate = hSCE->element_brate; +#endif /*-----------------------------------------------------------------* * Metadata: allocate and initialize diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6e05d741ad..5c7db120ca 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -633,7 +633,15 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; +#ifndef SBA_BITRATE_SWITCHING ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); + +#else + if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } nchan_transport = hSpar->hMdEnc->spar_md_cfg.nchan_transport; diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index de0c37c925..2d0bca8fa7 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -84,8 +84,9 @@ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int static void ivas_write_parameter_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); +#ifndef SBA_BITRATE_SWITCHING static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); - +#endif static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, float **ppValues, const int16_t ndm, int16_t **ppIndex, const int16_t dim1, float **ppQuant ); static void ivas_quant_p_per_band_dtx( float **ppP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float **ppP_out, const int16_t num_ch ); @@ -307,7 +308,11 @@ void ivas_spar_md_enc_close( * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ +#ifndef SBA_BITRATE_SWITCHING static ivas_error ivas_spar_md_enc_init( +#else +ivas_error ivas_spar_md_enc_init( +#endif ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ const int16_t sba_order /* i : Ambisonic (SBA) order */ @@ -1690,7 +1695,7 @@ static void ivas_write_parameter_bitstream_dtx( pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); - value = (uint16_t) ( pr * pd_q_lvls + pd ); + value = ( uint16_t )( pr * pd_q_lvls + pd ); push_next_indice( hMetaData, value, pr_pd_bits ); } @@ -1715,7 +1720,7 @@ static void ivas_write_parameter_bitstream_dtx( pr_idx2 -= ppIdx[0][0]; - value = (uint16_t) ( pr_idx2 * pr_q_lvls1 + pr_idx1 ); + value = ( uint16_t )( pr_idx2 * pr_q_lvls1 + pr_idx1 ); pr_pr_bits = ivas_get_bits_to_encode( pr_q_lvls1 * pr_q_lvls2 ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 2ed6a0ff91..091cedfd33 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -686,7 +686,7 @@ typedef struct ivas_spar_enc_lib_t ivas_enc_cov_handler_state_t *hCovEnc; ivas_trans_det_state_t *hTranDet; ivas_agc_enc_state_t *hAgcEnc; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; PCA_ENC_STATE *hPCA; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ @@ -841,6 +841,9 @@ typedef struct sce_enc_data_structure { int16_t sce_id; /* SCE # identifier */ int32_t element_brate; /* SCE element total bitrate in bps */ +#ifdef SBA_BITRATE_SWITCHING + int32_t last_element_brate; /* last SCE element bitrate in bps */ +#endif BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */ @@ -858,7 +861,7 @@ typedef struct cpe_enc_data_structure int16_t cpe_id; /* CPE # identifier */ int32_t element_brate; /* CPE element total bitrate in bps */ - int32_t last_element_brate; /* last CPE element total bitrate in bps */ + int32_t last_element_brate; /* last CPE element bitrate in bps */ int16_t element_mode; /* element mode, in CPE it can be IVAS_CPE_DFT, IVAS_CPE_TD or IVAS_CPE_MDCT */ int16_t last_element_mode; /* last element mode */ -- GitLab From 8106a458a8153f06d703b03b81e93f98d034f28b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Sep 2022 07:46:44 +0200 Subject: [PATCH 02/26] fixes towards support of 'stereo' output --- lib_com/options.h | 2 +- lib_dec/ivas_init_dec.c | 14 +- lib_dec/ivas_sba_dec.c | 419 +++++++++++++++++++++++++--------------- lib_dec/ivas_stat_dec.h | 2 +- 4 files changed, 266 insertions(+), 171 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 954565273d..d084e73715 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -/*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ +#define MEM_COUNT_DETAILS /* RAM counting tool: print per sub-structure details */ #define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 87b48cd0d8..625af2a3fb 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -601,7 +601,7 @@ ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t i, k, n; + int16_t i, n; int16_t sce_id, cpe_id; int16_t numCldfbAnalyses; int16_t numCldfbSyntheses; @@ -816,11 +816,9 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) { + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } if ( st_ivas->ivas_format == MASA_FORMAT ) @@ -858,10 +856,8 @@ ivas_error ivas_init_decoder( { return error; } - for ( k = 0; k < DIRAC_MAX_NBANDS; k++ ) - { - st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; - } + + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } else diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 81365260ff..52928b61bd 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -451,20 +451,16 @@ ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t n; + int16_t i, n; int16_t sce_id, cpe_id; - int16_t nchan_transport; - int16_t nchan_transport_old; + int16_t nchan_transport, nchan_transport_old; +#ifndef SBA_BITRATE_SWITCHING int32_t sba_total_brate; - int16_t nSCE_old; - int16_t nCPE_old; +#endif + int16_t nSCE_old, nCPE_old; AUDIO_CONFIG intern_config_old; - int16_t numCldfbAnalyses_old; - int16_t numCldfbAnalyses; - int16_t numCldfbSyntheses; - int16_t numCldfbSyntheses_old; + int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses; int16_t sba_dirac_stereo_flag_old; - uint16_t i; int32_t ivas_total_brate, last_ivas_total_brate; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; @@ -484,7 +480,9 @@ ivas_error ivas_sba_dec_reconfigure( #endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); numCldfbAnalyses = 0; +#ifndef SBA_BITRATE_SWITCHING sba_total_brate = ivas_total_brate; +#endif nSCE_old = st_ivas->nSCE; nCPE_old = st_ivas->nCPE; @@ -502,6 +500,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->nchan_transport = nchan_transport; #endif +#ifndef SBA_BITRATE_SWITCHING /* renderer might have changed */ intern_config_old = st_ivas->intern_config; ivas_renderer_select( st_ivas ); @@ -511,6 +510,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } +#endif if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { @@ -520,7 +520,7 @@ ivas_error ivas_sba_dec_reconfigure( #endif st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); - + 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { return error; @@ -538,6 +538,8 @@ ivas_error ivas_sba_dec_reconfigure( return error; } } + + st_ivas->sba_dirac_stereo_flag = 0; #endif sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); @@ -563,6 +565,19 @@ ivas_error ivas_sba_dec_reconfigure( } #endif +#ifdef SBA_BITRATE_SWITCHING + /* renderer might have changed */ + intern_config_old = st_ivas->intern_config; + ivas_renderer_select( st_ivas ); + + /* side effect of the renderer selection can be a changed internal config */ + if ( st_ivas->intern_config != intern_config_old ) + { + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + } +#endif + + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { @@ -582,7 +597,8 @@ ivas_error ivas_sba_dec_reconfigure( } } #ifdef SBA_BITRATE_SWITCHING // VE: TBD - possibly merge with the above - else if( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR ) + else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR ) + //else if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC || st_ivas->renderer_type == RENDERER_DIRAC ) && st_ivas->sba_mode == SBA_MODE_SPAR ) { if ( st_ivas->hDirAC != NULL ) { @@ -598,11 +614,7 @@ ivas_error ivas_sba_dec_reconfigure( return error; } - for ( n = 0; n < DIRAC_MAX_NBANDS; n++ ) - { - st_ivas->hSpar->dirac_to_spar_md_bands[n] = st_ivas->hDirAC->dirac_to_spar_md_bands[n]; - } - //mvr2r( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } } @@ -649,6 +661,48 @@ ivas_error ivas_sba_dec_reconfigure( 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() */ } +#ifdef SBA_BITRATE_SWITCHING + if ( st_ivas->hSCE[0] != NULL ) // VE: TBV if code below can be reused + { + if ( st_ivas->sba_dirac_stereo_flag ) + { + int16_t output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + + if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); + } + set_zero( st_ivas->hSCE[0]->save_synth, output_frame ); + + if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); + } + set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); + } + else + { + st_ivas->hSCE[0]->save_synth = NULL; + st_ivas->hSCE[0]->save_hb_synth = NULL; + } + } + + + /* create CPE element for DFT Stereo like upmix */ + if ( st_ivas->sba_dirac_stereo_flag ) + { + if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + } + else + { + } +#endif + 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; @@ -799,223 +853,268 @@ ivas_error ivas_sba_dec_reconfigure( } } - /*-----------------------------------------------------------------* +#ifdef SBA_BITRATE_SWITCHING + } +#endif + + /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ - if ( nchan_transport > nchan_transport_old ) + if ( nchan_transport > nchan_transport_old ) + { + /* create additional hp20 memories */ + float **old_mem_hp20_out; + uint16_t n_old; + + if ( sba_dirac_stereo_flag_old ) { - /* create additional hp20 memories */ - float **old_mem_hp20_out; - uint16_t n_old; + n_old = CPE_CHANNELS; + } + else + { + n_old = nchan_transport_old; + } + n = st_ivas->nchan_transport; - if ( sba_dirac_stereo_flag_old ) - { - n_old = CPE_CHANNELS; - } - else - { - n_old = nchan_transport_old; - } - n = st_ivas->nchan_transport; + /* save old mem_hp_20 pointer */ + old_mem_hp20_out = st_ivas->mem_hp20_out; + st_ivas->mem_hp20_out = NULL; + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_out; - st_ivas->mem_hp20_out = NULL; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + for ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; + old_mem_hp20_out[i] = NULL; + } + for ( ; i < nchan_transport; i++ ) + { + if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; - } - for ( ; i < nchan_transport; i++ ) - { - if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } + set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); + } - set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); - } + count_free( old_mem_hp20_out ); + old_mem_hp20_out = NULL; + } + else if ( nchan_transport < nchan_transport_old ) + { + /* remove superfluous hp20 memories */ + float **old_mem_hp20_out; - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; + if ( st_ivas->sba_dirac_stereo_flag ) + { + n = CPE_CHANNELS; + } + else + { + n = st_ivas->nchan_transport; } - else if ( nchan_transport < nchan_transport_old ) + + /* save old mem_hp_20 pointer */ + old_mem_hp20_out = st_ivas->mem_hp20_out; + st_ivas->mem_hp20_out = NULL; + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; + old_mem_hp20_out[i] = NULL; + } + + for ( ; i < nchan_transport_old; i++ ) + { + count_free( old_mem_hp20_out[i] ); + old_mem_hp20_out[i] = NULL; + } + + count_free( old_mem_hp20_out ); + old_mem_hp20_out = NULL; + } +#ifdef SBA_BITRATE_SWITCHING + else if( st_ivas->sba_dirac_stereo_flag != sba_dirac_stereo_flag_old ) // VE: needs more work once SBA low-bitrate coding is updated + { + if( st_ivas->sba_dirac_stereo_flag ) { - /* remove superfluous hp20 memories */ float **old_mem_hp20_out; + old_mem_hp20_out = st_ivas->mem_hp20_out; - if ( st_ivas->sba_dirac_stereo_flag ) + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( 2 * sizeof( float * ) ) ) == NULL ) { - n = CPE_CHANNELS; - } - else - { - n = st_ivas->nchan_transport; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_out; - st_ivas->mem_hp20_out = NULL; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + st_ivas->mem_hp20_out[0] = old_mem_hp20_out[0]; + + if ( ( st_ivas->mem_hp20_out[1] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - for ( i = 0; i < n; i++ ) - + set_f( st_ivas->mem_hp20_out[1], 0.0f, L_HP20_MEM ); + } + else + { + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( 1 * sizeof( float * ) ) ) == NULL ) { - st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - for ( ; i < nchan_transport_old; i++ ) + + if( st_ivas->mem_hp20_out[1] != NULL ) { - count_free( old_mem_hp20_out[i] ); - old_mem_hp20_out[i] = NULL; } - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; + count_free( st_ivas->mem_hp20_out[1] ); + st_ivas->mem_hp20_out[1] = NULL; + } } +#endif +#ifndef SBA_BITRATE_SWITCHING +} +#endif - /*-----------------------------------------------------------------* +/*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ - ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); +ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - /* special case, if there was one transport channel in the previous frame and more than one in the current frame, +/* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ - if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) - { - deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); - st_ivas->cldfbAnaDec[1] = NULL; - numCldfbAnalyses_old--; - } +if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) +{ + deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); + st_ivas->cldfbAnaDec[1] = NULL; + numCldfbAnalyses_old--; +} - /* Analysis*/ - if ( numCldfbAnalyses_old > numCldfbAnalyses ) +/* Analysis*/ +if ( numCldfbAnalyses_old > numCldfbAnalyses ) +{ + /* delete superfluous CLDFB synthesis instances */ + for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) { - /* delete superfluous CLDFB synthesis instances */ - for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) - { - deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); - st_ivas->cldfbAnaDec[i] = NULL; - } + deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); + st_ivas->cldfbAnaDec[i] = NULL; } - else if ( numCldfbAnalyses_old < numCldfbAnalyses ) +} +else if ( numCldfbAnalyses_old < numCldfbAnalyses ) +{ + /* create additional CLDFB synthesis instances */ + for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - /* create additional CLDFB synthesis instances */ - for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } +} - /* Synthesis */ - if ( numCldfbSyntheses_old > numCldfbSyntheses ) +/* Synthesis */ +if ( numCldfbSyntheses_old > numCldfbSyntheses ) +{ + /* delete superfluous CLDFB synthesis instances */ + for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) { - /* delete superfluous CLDFB synthesis instances */ - for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) - { - deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); - st_ivas->cldfbSynDec[i] = NULL; - } + deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); + st_ivas->cldfbSynDec[i] = NULL; } - else if ( numCldfbSyntheses_old < numCldfbSyntheses ) +} +else if ( numCldfbSyntheses_old < numCldfbSyntheses ) +{ + /* create additional CLDFB synthesis instances */ + for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - /* create additional CLDFB synthesis instances */ - for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } +} - /*-----------------------------------------------------------------* +/*-----------------------------------------------------------------* * Set CNA/CNG flags *-----------------------------------------------------------------*/ - if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) - { - /* skip as done in init function */ - } - else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) +if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) +{ + /* skip as done in init function */ +} +else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) +{ + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; +} +else if ( st_ivas->nchan_transport == 2 ) +{ + for ( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; - st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; } - else if ( st_ivas->nchan_transport == 2 ) +} +else +{ + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { for ( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; - } - } - else - { - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; - } + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; } } +} - /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ - if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) +/* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ +if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) +{ + if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) { - if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } +} - /*-------------------------------------------------------------------* +/*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hBinRenderer == NULL ) - { - /* open fastconv binaural renderer */ - if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) +if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hBinRenderer == NULL ) +{ + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) { - ivas_binRenderer_close( &st_ivas->hBinRenderer ); + return error; } +} +else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) +{ + ivas_binRenderer_close( &st_ivas->hBinRenderer ); +} - if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) - { - /* open parametric binaural renderer */ - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hDiracDecBin != NULL && ( 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->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) +{ + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) { - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + return error; } +} +else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) +{ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); +} - return error; +return error; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 58a94145c4..cc4a95bebd 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -876,7 +876,7 @@ typedef struct ivas_spar_dec_lib_t int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ - int32_t i_subframe; + int32_t i_subframe; // VE2DB: change to int16_t #ifdef DEBUG_SBA_AUDIO_DUMP int16_t numOutChannels; -- GitLab From 4a66efbdea57e30e19505a0ff08e8446b2af182f Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Sep 2022 08:32:08 +0200 Subject: [PATCH 03/26] reorganize ivas_sba_dec_reconfigure() + improve hp20 memory allocation/deallocation --- lib_dec/ivas_sba_dec.c | 827 ++++++++++++++++++++++++++++++----------- 1 file changed, 610 insertions(+), 217 deletions(-) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 52928b61bd..3a380c7b3c 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -451,16 +451,15 @@ ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { +#ifdef SBA_BITRATE_SWITCHING int16_t i, n; int16_t sce_id, cpe_id; - int16_t nchan_transport, nchan_transport_old; -#ifndef SBA_BITRATE_SWITCHING - int32_t sba_total_brate; -#endif - int16_t nSCE_old, nCPE_old; + int16_t nSCE_old, nCPE_old, nchan_transport_old; + int16_t nchan_hp20_old, nchan_hp20; AUDIO_CONFIG intern_config_old; int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses; int16_t sba_dirac_stereo_flag_old; + float **old_mem_hp20_out; int32_t ivas_total_brate, last_ivas_total_brate; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; @@ -472,52 +471,32 @@ ivas_error ivas_sba_dec_reconfigure( last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA and rendering handles + * Set SBA high-level parameters + * Save old SBA high-level parameters *-----------------------------------------------------------------*/ -#ifdef SBA_BITRATE_SWITCHING st_ivas->sba_mode = ivas_sba_mode_select( last_ivas_total_brate ); -#endif + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); - numCldfbAnalyses = 0; -#ifndef SBA_BITRATE_SWITCHING - sba_total_brate = ivas_total_brate; -#endif + nchan_hp20_old = getNumChanSynthesis( st_ivas ); nSCE_old = st_ivas->nSCE; nCPE_old = st_ivas->nCPE; nchan_transport_old = st_ivas->nchan_transport; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; -#ifdef SBA_BITRATE_SWITCHING st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); -#endif st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); -#ifndef SBA_BITRATE_SWITCHING - ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); - st_ivas->nchan_transport = nchan_transport; -#endif - -#ifndef SBA_BITRATE_SWITCHING - /* renderer might have changed */ - intern_config_old = st_ivas->intern_config; - ivas_renderer_select( st_ivas ); - - /* side effect of the renderer selection can be a changed internal config */ - if ( st_ivas->intern_config != intern_config_old ) - { - ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - } -#endif + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SBA handles + *-----------------------------------------------------------------*/ if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { -#ifdef SBA_BITRATE_SWITCHING ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); st_ivas->hSpar = NULL; -#endif st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); @@ -530,7 +509,6 @@ ivas_error ivas_sba_dec_reconfigure( { int16_t sba_order_internal; -#ifdef SBA_BITRATE_SWITCHING if ( st_ivas->hSpar == NULL ) { if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -540,7 +518,6 @@ ivas_error ivas_sba_dec_reconfigure( } st_ivas->sba_dirac_stereo_flag = 0; -#endif sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); @@ -552,10 +529,7 @@ ivas_error ivas_sba_dec_reconfigure( } } -#ifdef SBA_BITRATE_SWITCHING - nchan_transport = st_ivas->nchan_transport; - - if ( nchan_transport == 1 ) + if ( st_ivas->nchan_transport == 1 ) { st_ivas->element_mode_init = IVAS_SCE; } @@ -563,9 +537,11 @@ ivas_error ivas_sba_dec_reconfigure( { st_ivas->element_mode_init = IVAS_CPE_MDCT; } -#endif -#ifdef SBA_BITRATE_SWITCHING + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ + /* renderer might have changed */ intern_config_old = st_ivas->intern_config; ivas_renderer_select( st_ivas ); @@ -575,11 +551,13 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } -#endif + /*-----------------------------------------------------------------* + * hDirAC decoder handle configuration + *-----------------------------------------------------------------*/ if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && - ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) { @@ -653,7 +631,7 @@ ivas_error ivas_sba_dec_reconfigure( * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - if ( nchan_transport == nchan_transport_old ) + if ( st_ivas->nchan_transport == nchan_transport_old ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -662,9 +640,9 @@ ivas_error ivas_sba_dec_reconfigure( } #ifdef SBA_BITRATE_SWITCHING - if ( st_ivas->hSCE[0] != NULL ) // VE: TBV if code below can be reused + if ( st_ivas->hSCE[0] != NULL ) { - if ( st_ivas->sba_dirac_stereo_flag ) + if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) { int16_t output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); @@ -680,16 +658,15 @@ ivas_error ivas_sba_dec_reconfigure( } set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); } - else + else if( !st_ivas->sba_dirac_stereo_flag ) { st_ivas->hSCE[0]->save_synth = NULL; st_ivas->hSCE[0]->save_hb_synth = NULL; } } - /* create CPE element for DFT Stereo like upmix */ - if ( st_ivas->sba_dirac_stereo_flag ) + if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) { if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { @@ -698,8 +675,9 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ } - else + else if( sba_dirac_stereo_flag_old ) { + //destroy_cpe_dec( st_ivas->hCPE[0] ); } #endif @@ -852,45 +830,32 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } } - -#ifdef SBA_BITRATE_SWITCHING } -#endif /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ - - if ( nchan_transport > nchan_transport_old ) - { - /* create additional hp20 memories */ - float **old_mem_hp20_out; - uint16_t n_old; + * HP20 memories + *-----------------------------------------------------------------*/ - if ( sba_dirac_stereo_flag_old ) - { - n_old = CPE_CHANNELS; - } - else - { - n_old = nchan_transport_old; - } - n = st_ivas->nchan_transport; + nchan_hp20 = getNumChanSynthesis( st_ivas ); + if ( nchan_hp20 > nchan_hp20_old ) + { /* save old mem_hp_20 pointer */ old_mem_hp20_out = st_ivas->mem_hp20_out; st_ivas->mem_hp20_out = NULL; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - for ( i = 0; i < n_old; i++ ) + for ( i = 0; i < nchan_hp20_old; i++ ) { st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; old_mem_hp20_out[i] = NULL; } - for ( ; i < nchan_transport; i++ ) + /* create additional hp20 memories */ + for ( ; i < nchan_hp20; i++ ) { if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) { @@ -903,35 +868,24 @@ ivas_error ivas_sba_dec_reconfigure( count_free( old_mem_hp20_out ); old_mem_hp20_out = NULL; } - else if ( nchan_transport < nchan_transport_old ) + else if ( nchan_hp20 < nchan_hp20_old ) { - /* remove superfluous hp20 memories */ - float **old_mem_hp20_out; - - if ( st_ivas->sba_dirac_stereo_flag ) - { - n = CPE_CHANNELS; - } - else - { - n = st_ivas->nchan_transport; - } - /* save old mem_hp_20 pointer */ old_mem_hp20_out = st_ivas->mem_hp20_out; st_ivas->mem_hp20_out = NULL; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - for ( i = 0; i < n; i++ ) + for ( i = 0; i < nchan_hp20; i++ ) { st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; old_mem_hp20_out[i] = NULL; } - - for ( ; i < nchan_transport_old; i++ ) + /* remove superfluous hp20 memories */ + for ( ; i < nchan_hp20_old; i++ ) { count_free( old_mem_hp20_out[i] ); old_mem_hp20_out[i] = NULL; @@ -940,181 +894,620 @@ ivas_error ivas_sba_dec_reconfigure( count_free( old_mem_hp20_out ); old_mem_hp20_out = NULL; } -#ifdef SBA_BITRATE_SWITCHING - else if( st_ivas->sba_dirac_stereo_flag != sba_dirac_stereo_flag_old ) // VE: needs more work once SBA low-bitrate coding is updated - { - if( st_ivas->sba_dirac_stereo_flag ) - { - float **old_mem_hp20_out; - old_mem_hp20_out = st_ivas->mem_hp20_out; - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( 2 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ - st_ivas->mem_hp20_out[0] = old_mem_hp20_out[0]; + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - if ( ( st_ivas->mem_hp20_out[1] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } + /* special case, if there was one transport channel in the previous frame and more than one in the current frame, + remove the second CLDFB here, it was for CNA/CNG */ + if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); + st_ivas->cldfbAnaDec[1] = NULL; + numCldfbAnalyses_old--; + } - set_f( st_ivas->mem_hp20_out[1], 0.0f, L_HP20_MEM ); + /* Analysis*/ + if ( numCldfbAnalyses_old > numCldfbAnalyses ) + { + /* delete superfluous CLDFB synthesis instances */ + for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); + st_ivas->cldfbAnaDec[i] = NULL; } - else + } + else if ( numCldfbAnalyses_old < numCldfbAnalyses ) + { + /* create additional CLDFB synthesis instances */ + for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( 1 * sizeof( float * ) ) ) == NULL ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + return error; } + } + } - if( st_ivas->mem_hp20_out[1] != NULL ) + /* Synthesis */ + if ( numCldfbSyntheses_old > numCldfbSyntheses ) + { + /* delete superfluous CLDFB synthesis instances */ + for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) + { + deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); + st_ivas->cldfbSynDec[i] = NULL; + } + } + else if ( numCldfbSyntheses_old < numCldfbSyntheses ) + { + /* create additional CLDFB synthesis instances */ + for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { + return error; } - - count_free( st_ivas->mem_hp20_out[1] ); - st_ivas->mem_hp20_out[1] = NULL; - } } -#endif -#ifndef SBA_BITRATE_SWITCHING -} -#endif -/*-----------------------------------------------------------------* - * CLDFB instances + /*-----------------------------------------------------------------* + * Set CNA/CNG flags *-----------------------------------------------------------------*/ -ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - -/* special case, if there was one transport channel in the previous frame and more than one in the current frame, - remove the second CLDFB here, it was for CNA/CNG */ -if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) -{ - deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); - st_ivas->cldfbAnaDec[1] = NULL; - numCldfbAnalyses_old--; -} - -/* Analysis*/ -if ( numCldfbAnalyses_old > numCldfbAnalyses ) -{ - /* delete superfluous CLDFB synthesis instances */ - for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) { - deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); - st_ivas->cldfbAnaDec[i] = NULL; + /* skip as done in init function */ } -} -else if ( numCldfbAnalyses_old < numCldfbAnalyses ) -{ - /* create additional CLDFB synthesis instances */ - for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + } + else if ( st_ivas->nchan_transport == 2 ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + for ( n = 0; n < CPE_CHANNELS; n++ ) { - return error; + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; } } -} - -/* Synthesis */ -if ( numCldfbSyntheses_old > numCldfbSyntheses ) -{ - /* delete superfluous CLDFB synthesis instances */ - for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) + else { - deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); - st_ivas->cldfbSynDec[i] = NULL; + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + } + } } -} -else if ( numCldfbSyntheses_old < numCldfbSyntheses ) -{ - /* create additional CLDFB synthesis instances */ - for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) + + /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ + if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) { return error; } } -} -/*-----------------------------------------------------------------* - * Set CNA/CNG flags - *-----------------------------------------------------------------*/ + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ -if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) -{ - /* skip as done in init function */ -} -else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) -{ - st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; - st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; -} -else if ( st_ivas->nchan_transport == 2 ) -{ - for ( n = 0; n < CPE_CHANNELS; n++ ) + if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hBinRenderer == NULL ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + ivas_binRenderer_close( &st_ivas->hBinRenderer ); } -} -else -{ - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + + if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) { - for ( n = 0; n < CPE_CHANNELS; n++ ) + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + return error; } } -} - -/* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ -if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) -{ - if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) + else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) { - return error; + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } -} -/*-------------------------------------------------------------------* - * Reallocate and initialize binaural rendering handles - *--------------------------------------------------------------------*/ + return error; +#else + int16_t i, n; + int16_t sce_id, cpe_id; + int16_t nchan_transport, nchan_transport_old; + int32_t sba_total_brate; + int16_t nSCE_old, nCPE_old; + AUDIO_CONFIG intern_config_old; + int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses; + int16_t sba_dirac_stereo_flag_old; + int32_t ivas_total_brate, last_ivas_total_brate; + DECODER_CONFIG_HANDLE hDecoderConfig; + ivas_error error; -if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hBinRenderer == NULL ) -{ - /* open fastconv binaural renderer */ - if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + hDecoderConfig = st_ivas->hDecoderConfig; + error = IVAS_ERR_OK; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SBA and rendering handles + *-----------------------------------------------------------------*/ + + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + numCldfbAnalyses = 0; + sba_total_brate = ivas_total_brate; + + nSCE_old = st_ivas->nSCE; + nCPE_old = st_ivas->nCPE; + nchan_transport_old = st_ivas->nchan_transport; + sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + + ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); + st_ivas->nchan_transport = nchan_transport; + + /* renderer might have changed */ + intern_config_old = st_ivas->intern_config; + ivas_renderer_select( st_ivas ); + + /* side effect of the renderer selection can be a changed internal config */ + if ( st_ivas->intern_config != intern_config_old ) { - return error; + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } -} -else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) -{ - ivas_binRenderer_close( &st_ivas->hBinRenderer ); -} -if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) -{ - /* open parametric binaural renderer */ - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) + { + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + + 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else { - return error; + int16_t sba_order_internal; + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + + 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_planar, + st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + { + return error; + } } -} -else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) -{ - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); -} -return error; + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && + ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + 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 ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + + if ( st_ivas->hVBAPdata != NULL ) + { + vbap_free_data( &( st_ivas->hVBAPdata ) ); + } + } + + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + if ( nchan_transport == nchan_transport_old ) + { + 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]->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() */ + } + + 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; + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + } + + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + int16_t nSCE_existing; + int16_t nCPE_existing; + + nSCE_existing = min( nSCE_old, st_ivas->nSCE ); + nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + + /* destroy superfluous core coder elements */ + for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) + { + destroy_sce_dec( st_ivas->hSCE[sce_id] ); + st_ivas->hSCE[sce_id] = NULL; + + /* remove dummy CPE needed for 1TC->Stereo rendering via DFT stereo*/ + if ( sba_dirac_stereo_flag_old ) + { +#ifdef DEBUGGING + assert( st_ivas->hCPE[0] ); +#endif + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hCPE[0]->hCoreCoder[1] = NULL; + destroy_cpe_dec( st_ivas->hCPE[0] ); + st_ivas->hCPE[0] = NULL; + } + } + + for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) + { + destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + + if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) + { + ivas_mct_dec_close( &st_ivas->hMCT ); + } + + /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/ + if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) + { + count_free( st_ivas->hCPE[0]->hStereoMdct ); + st_ivas->hCPE[0]->hStereoMdct = NULL; + } + + for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) + { + st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; + 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() */ + } + for ( ; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + } + for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* create CPE element for DFT Stereo like upmix */ + if ( st_ivas->sba_dirac_stereo_flag ) + { + if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + } + + if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) + { + if ( nCPE_old == 1 ) + { + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = ( int16_t )( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; + } + } + + if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) + { + if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ + if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) + { + if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f; + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + /* reset mct_chan_mode */ + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + } + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + + if ( nchan_transport > nchan_transport_old ) + { + /* create additional hp20 memories */ + float **old_mem_hp20_out; + uint16_t n_old; + + if ( sba_dirac_stereo_flag_old ) + { + n_old = CPE_CHANNELS; + } + else + { + n_old = nchan_transport_old; + } + n = st_ivas->nchan_transport; + + /* save old mem_hp_20 pointer */ + old_mem_hp20_out = st_ivas->mem_hp20_out; + st_ivas->mem_hp20_out = NULL; + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n_old; i++ ) + { + st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; + old_mem_hp20_out[i] = NULL; + } + for ( ; i < nchan_transport; i++ ) + { + if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); + } + + count_free( old_mem_hp20_out ); + old_mem_hp20_out = NULL; + } + else if ( nchan_transport < nchan_transport_old ) + { + /* remove superfluous hp20 memories */ + float **old_mem_hp20_out; + + if ( st_ivas->sba_dirac_stereo_flag ) + { + n = CPE_CHANNELS; + } + else + { + n = st_ivas->nchan_transport; + } + + /* save old mem_hp_20 pointer */ + old_mem_hp20_out = st_ivas->mem_hp20_out; + st_ivas->mem_hp20_out = NULL; + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < n; i++ ) + { + st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; + old_mem_hp20_out[i] = NULL; + } + + for ( ; i < nchan_transport_old; i++ ) + { + count_free( old_mem_hp20_out[i] ); + old_mem_hp20_out[i] = NULL; + } + + count_free( old_mem_hp20_out ); + old_mem_hp20_out = NULL; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); + + /* special case, if there was one transport channel in the previous frame and more than one in the current frame, + remove the second CLDFB here, it was for CNA/CNG */ + if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); + st_ivas->cldfbAnaDec[1] = NULL; + numCldfbAnalyses_old--; + } + + /* Analysis*/ + if ( numCldfbAnalyses_old > numCldfbAnalyses ) + { + /* delete superfluous CLDFB synthesis instances */ + for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); + st_ivas->cldfbAnaDec[i] = NULL; + } + } + else if ( numCldfbAnalyses_old < numCldfbAnalyses ) + { + /* create additional CLDFB synthesis instances */ + for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* Synthesis */ + if ( numCldfbSyntheses_old > numCldfbSyntheses ) + { + /* delete superfluous CLDFB synthesis instances */ + for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) + { + deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); + st_ivas->cldfbSynDec[i] = NULL; + } + } + else if ( numCldfbSyntheses_old < numCldfbSyntheses ) + { + /* create additional CLDFB synthesis instances */ + for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /*-----------------------------------------------------------------* + * Set CNA/CNG flags + *-----------------------------------------------------------------*/ + + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) + { + /* skip as done in init function */ + } + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + } + else if ( st_ivas->nchan_transport == 2 ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + else + { + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + } + } + } + + /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ + if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) + { + if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ + + if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hBinRenderer == NULL ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + } + + if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) + { + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } + + return error; +#endif } -- GitLab From e4a16a91c580e94e12f364e70b3130459a32f8a2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Sep 2022 15:13:58 +0200 Subject: [PATCH 04/26] fixes for 'stereo' output --- lib_com/ivas_prot.h | 4 +- lib_dec/ivas_init_dec.c | 6 ++ lib_dec/ivas_sba_dec.c | 125 +++++++++++++++++------------------ lib_dec/ivas_sba_rendering.c | 14 ++-- lib_dec/ivas_spar_decoder.c | 10 +-- 5 files changed, 80 insertions(+), 79 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 69ee6bc3fa..e0e39bcb6e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3079,7 +3079,7 @@ void ivas_sba_getTCs( ); ivas_error ivas_sba_linear_renderer( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ const int16_t nchan_in, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ @@ -3969,7 +3969,7 @@ void ivas_spar_get_parameters( const int16_t num_ch_out, /* i : number of channels out */ const int16_t num_ch_in, /* i : number of channels in */ const int16_t num_spar_bands, /* i : number of SPAR bands */ - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ ); ivas_error ivas_spar_md_dec_init( diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 625af2a3fb..4050d97445 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -944,6 +944,9 @@ ivas_error ivas_init_decoder( } st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ +#ifdef SBA_BITRATE_SWITCHING + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; +#endif } if ( st_ivas->nCPE > 1 ) @@ -1140,6 +1143,9 @@ ivas_error ivas_init_decoder( } st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ +#ifdef SBA_BITRATE_SWITCHING + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; +#endif } /* set CNA/CNG flags */ diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 3a380c7b3c..6490985369 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -452,7 +452,7 @@ ivas_error ivas_sba_dec_reconfigure( ) { #ifdef SBA_BITRATE_SWITCHING - int16_t i, n; + int16_t i, n, output_frame; int16_t sce_id, cpe_id; int16_t nSCE_old, nCPE_old, nchan_transport_old; int16_t nchan_hp20_old, nchan_hp20; @@ -465,6 +465,7 @@ ivas_error ivas_sba_dec_reconfigure( ivas_error error; hDecoderConfig = st_ivas->hDecoderConfig; + output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -498,12 +499,12 @@ ivas_error ivas_sba_dec_reconfigure( ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); st_ivas->hSpar = NULL; - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); - 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { return error; } + + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); } else { @@ -631,55 +632,31 @@ ivas_error ivas_sba_dec_reconfigure( * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - if ( st_ivas->nchan_transport == nchan_transport_old ) + /* remove dummy CPE element for DFT stereo-like upmix */ + if ( sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) { - 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]->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() */ - } + st_ivas->hCPE[0]->hCoreCoder[0] = NULL; + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; + destroy_cpe_dec( st_ivas->hCPE[0] ); + st_ivas->hCPE[0] = NULL; -#ifdef SBA_BITRATE_SWITCHING if ( st_ivas->hSCE[0] != NULL ) { - if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) - { - int16_t output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); - - if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); - } - set_zero( st_ivas->hSCE[0]->save_synth, output_frame ); + count_free( st_ivas->hSCE[0]->save_synth ); + st_ivas->hSCE[0]->save_synth = NULL; - if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); - } - set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); - } - else if( !st_ivas->sba_dirac_stereo_flag ) - { - st_ivas->hSCE[0]->save_synth = NULL; - st_ivas->hSCE[0]->save_hb_synth = NULL; - } + count_free( st_ivas->hSCE[0]->save_hb_synth ); + st_ivas->hSCE[0]->save_hb_synth = NULL; } + } - /* create CPE element for DFT Stereo like upmix */ - if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) - { - if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) - { - return error; - } - - st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ - } - else if( sba_dirac_stereo_flag_old ) + if ( st_ivas->nchan_transport == nchan_transport_old ) + { + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - //destroy_cpe_dec( st_ivas->hCPE[0] ); + st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; + 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() */ } -#endif for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { @@ -713,17 +690,6 @@ ivas_error ivas_sba_dec_reconfigure( { destroy_sce_dec( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; - - /* remove dummy CPE needed for 1TC->Stereo rendering via DFT stereo*/ - if ( sba_dirac_stereo_flag_old ) - { -#ifdef DEBUGGING - assert( st_ivas->hCPE[0] ); -#endif - st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hCPE[0]->hCoreCoder[1] = NULL; - destroy_cpe_dec( st_ivas->hCPE[0] ); - st_ivas->hCPE[0] = NULL; - } } for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) @@ -775,17 +741,6 @@ ivas_error ivas_sba_dec_reconfigure( } } - /* create CPE element for DFT Stereo like upmix */ - if ( st_ivas->sba_dirac_stereo_flag ) - { - if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) - { - return error; - } - - st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ - } - if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) { if ( nCPE_old == 1 ) @@ -832,6 +787,40 @@ ivas_error ivas_sba_dec_reconfigure( } } + /* create dummy CPE element for DFT stereo-like upmix */ + if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) + { + if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + // VE: TBV - just reset for now + set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); + + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + st_ivas->hCPE[0]->hCoreCoder[1] = NULL; + + if( st_ivas->hSCE[0]->save_synth == NULL ) + { + if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); + } + set_zero( st_ivas->hSCE[0]->save_synth, output_frame ); + } + + if ( st_ivas->hSCE[0]->save_hb_synth == NULL ) + { + if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); + } + set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); + } + } + + /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ @@ -954,6 +943,12 @@ ivas_error ivas_sba_dec_reconfigure( } } + /* CLDFB Interpolation weights */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses ) ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } + /*-----------------------------------------------------------------* * Set CNA/CNG flags *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 49f3555c6f..c7715cb9b5 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -57,7 +57,7 @@ static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t outpu *-------------------------------------------------------------------*/ ivas_error ivas_sba_linear_renderer( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ const int16_t nchan_in, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ @@ -92,7 +92,7 @@ ivas_error ivas_sba_linear_renderer( { for ( i = 0; i < output_frame; i++ ) { - output_f[0][i] += output_f[1][i]; + output[0][i] += output[1][i]; } } /* else: do nothing, MONO = W*/ @@ -106,9 +106,9 @@ ivas_error ivas_sba_linear_renderer( /*Build L/R cardioids*/ for ( i = 0; i < output_frame; i++ ) { - dmx_l = 0.5f * ( output_f[0][i] + output_f[1][i] ); /* cardioid_left = 0.5(W + Y) */ - output_f[1][i] = 0.5f * ( output_f[0][i] - output_f[1][i] ); /* cardioid_right = 0.5(W - Y) */ - output_f[0][i] = dmx_l; + dmx_l = 0.5f * ( output[0][i] + output[1][i] ); /* cardioid_left = 0.5(W + Y) */ + output[1][i] = 0.5f * ( output[0][i] - output[1][i] ); /* cardioid_right = 0.5(W - Y) */ + output[0][i] = dmx_l; } } break; @@ -118,14 +118,14 @@ ivas_error ivas_sba_linear_renderer( case AUDIO_CONFIG_5_1_4: case AUDIO_CONFIG_7_1_4: case AUDIO_CONFIG_LS_CUSTOM: - ivas_sba_mtx_mult( output_f, output_frame, nchan_hoa, output_setup, hoa_dec_mtx ); + ivas_sba_mtx_mult( output, output_frame, nchan_hoa, output_setup, hoa_dec_mtx ); break; case AUDIO_CONFIG_FOA: /* Ambisonics output, order: 1 */ case AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */ case AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */ for ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ ) { - set_zero( output_f[i], output_frame ); + set_zero( output[i], output_frame ); } break; default: diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 1837a15783..1c9cd24e87 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -775,7 +775,7 @@ void ivas_spar_get_parameters( const int16_t num_ch_out, const int16_t num_ch_in, const int16_t num_spar_bands, - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { int16_t spar_band, out_ch, in_ch; float weight, weight_20ms; @@ -797,19 +797,19 @@ void ivas_spar_get_parameters( { if ( hSpar->i_subframe > 3 ) { - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + + mixer_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; } else { - par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + mixer_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; } } else { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + mixer_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; } } } @@ -898,7 +898,7 @@ void ivas_spar_dec_upmixer( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; // VE: == st_ivas->nchan_transport num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; -- GitLab From fb01a52561927a2b1991f3fbe601d98cce943a95 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Sep 2022 20:50:57 +0200 Subject: [PATCH 05/26] fix crashes for Ambisonics and MC outputs + add debugging output file "res/element_brate" --- lib_com/ivas_cnst.h | 3 ++ lib_dec/ivas_cpe_dec.c | 4 +-- lib_dec/ivas_dirac_dec.c | 16 +++++++++- lib_dec/ivas_mct_dec.c | 8 +++++ lib_dec/ivas_sba_dec.c | 68 +++++++++++++++++++++++----------------- lib_dec/ivas_sce_dec.c | 2 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_sce_enc.c | 7 +++++ 8 files changed, 76 insertions(+), 34 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 6cfb9fb305..10cd091203 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -911,6 +911,9 @@ typedef enum { DIRAC_OPEN, /* initialize to default value */ DIRAC_RECONFIGURE /* HOA3 */ +#ifdef SBA_BITRATE_SWITCHING // VE: TBV - just dirty patch for the moment + ,DIRAC_RECONFIGURE_MODE /* HOA3 */ +#endif } DIRAC_CONFIG_FLAG; diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 680839e121..321eadc380 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -496,7 +496,7 @@ ivas_error ivas_cpe_dec( #ifdef DEBUG_MODE_INFO { - float tmpF = ivas_total_brate / 1000.0f; + float tmpF = hCPE->element_brate / 1000.0f; n = 1; if ( st_ivas->ini_frame == 0 && frame > 0 ) @@ -508,7 +508,7 @@ ivas_error ivas_cpe_dec( for ( i = 0; i < n; i++ ) { dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) ); - dbgwrite( &hCPE->element_mode, 2, 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) ); + dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) ); for ( int16_t j = 0; j < CPE_CHANNELS; j++ ) { diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 8dd47fe774..30c32ca7f6 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -127,7 +127,9 @@ ivas_error ivas_dirac_dec_open( ivas_error ivas_dirac_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const DIRAC_CONFIG_FLAG flag_config /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#ifdef SBA_BITRATE_SWITCHING + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#endif ) { DIRAC_DEC_HANDLE hDirAC; @@ -146,6 +148,11 @@ ivas_error ivas_dirac_dec_config( int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_orig; +#ifdef SBA_BITRATE_SWITCHING + DIRAC_CONFIG_FLAG flag_config; + + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; +#endif error = IVAS_ERR_OK; @@ -270,6 +277,9 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef SBA_BITRATE_SWITCHING // VE: TBV + st_ivas->nchan_transport = nchan_transport_orig; +#endif return IVAS_ERR_OK; } @@ -653,7 +663,11 @@ ivas_error ivas_dirac_dec_config( } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) { +#ifdef SBA_BITRATE_SWITCHING + if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) || flag_config_inp == DIRAC_RECONFIGURE_MODE ) +#else if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) +#endif { /* close and reopen the decorrelator */ ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 31f3208429..c462a01ff6 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -250,6 +250,14 @@ ivas_error ivas_mct_dec( #endif } +#ifdef DEBUG_MODE_INFO + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + float tmpF = st_ivas->hCPE[cpe_id]->element_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) ); + } +#endif + wmops_sub_end(); return error; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 6490985369..2e8d1496dd 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -457,6 +457,7 @@ ivas_error ivas_sba_dec_reconfigure( int16_t nSCE_old, nCPE_old, nchan_transport_old; int16_t nchan_hp20_old, nchan_hp20; AUDIO_CONFIG intern_config_old; + SBA_MODE sba_mode_old; int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses; int16_t sba_dirac_stereo_flag_old; float **old_mem_hp20_out; @@ -476,9 +477,11 @@ ivas_error ivas_sba_dec_reconfigure( * Save old SBA high-level parameters *-----------------------------------------------------------------*/ - st_ivas->sba_mode = ivas_sba_mode_select( last_ivas_total_brate ); + sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); + st_ivas->sba_mode = sba_mode_old; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + nchan_hp20_old = getNumChanSynthesis( st_ivas ); nSCE_old = st_ivas->nSCE; @@ -557,12 +560,12 @@ ivas_error ivas_sba_dec_reconfigure( * hDirAC decoder handle configuration *-----------------------------------------------------------------*/ - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && - ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#ifdef SBA_BITRATE_SWITCHING // VE: TBD - possibly merge with the 'else if' branch below + if ( sba_mode_old != st_ivas->sba_mode ) { if ( st_ivas->hDirAC != NULL ) { - if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ) ) != IVAS_ERR_OK ) { return error; } @@ -575,9 +578,10 @@ ivas_error ivas_sba_dec_reconfigure( } } } -#ifdef SBA_BITRATE_SWITCHING // VE: TBD - possibly merge with the above - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR ) - //else if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC || st_ivas->renderer_type == RENDERER_DIRAC ) && st_ivas->sba_mode == SBA_MODE_SPAR ) + else +#endif + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && + ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) { @@ -592,14 +596,9 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } - - mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); - st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } } -#endif -#ifdef SBA_BITRATE_SWITCHINGaa - else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_SPAR ) ) + 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 ) { @@ -612,19 +611,11 @@ ivas_error ivas_sba_dec_reconfigure( vbap_free_data( &( st_ivas->hVBAPdata ) ); } } -#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 ) - { - ivas_dirac_dec_close( st_ivas->hDirAC ); - st_ivas->hDirAC = NULL; - } - if ( st_ivas->hVBAPdata != NULL ) - { - vbap_free_data( &( st_ivas->hVBAPdata ) ); - } + if ( st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } @@ -685,6 +676,7 @@ ivas_error ivas_sba_dec_reconfigure( nSCE_existing = min( nSCE_old, st_ivas->nSCE ); nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + // VE: TBV - try to reuse the CoreCoder /* destroy superfluous core coder elements */ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) { @@ -902,8 +894,17 @@ ivas_error ivas_sba_dec_reconfigure( /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { - /* delete superfluous CLDFB synthesis instances */ - for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) + /* resample CLDFB analysis instances */ + for ( i = 0; i < numCldfbAnalyses; i++ ) + { + if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) + { + resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); + } + } + + /* delete superfluous CLDFB analysis instances */ + for ( ; i < numCldfbAnalyses_old; i++ ) { deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); st_ivas->cldfbAnaDec[i] = NULL; @@ -911,8 +912,17 @@ ivas_error ivas_sba_dec_reconfigure( } else if ( numCldfbAnalyses_old < numCldfbAnalyses ) { - /* create additional CLDFB synthesis instances */ - for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) + /* resample CLDFB analysis instances */ + for ( i = 0; i < numCldfbAnalyses_old; i++ ) + { + if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) + { + resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); + } + } + + /* create additional CLDFB analysis instances */ + for ( ; i < numCldfbAnalyses; i++ ) { if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 5b83a41f81..299bc8e540 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -274,7 +274,7 @@ ivas_error ivas_sce_dec( for ( i = 0; i < n; i++ ) { dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, sce_id, DEC ) ); - dbgwrite( &st->element_mode, 2, 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index b543761491..edc325d041 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -692,7 +692,7 @@ ivas_error ivas_cpe_enc( } { - float tmpF = ivas_total_brate / 1000.0f; + float tmpF = hCPE->element_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, cpe_id, ENC ) ); } #endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index aafccdb209..99f05719b3 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -257,6 +257,13 @@ ivas_error ivas_sce_enc( hSCE->last_element_brate = hSCE->element_brate; #endif +#ifdef DEBUG_MODE_INFO + { + float tmpF = hSCE->element_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) ); + } +#endif + wmops_sub_end(); return error; -- GitLab From 0af26325362679de3c02e9d21fdefbbec9e4a26c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 21 Sep 2022 10:30:30 +0200 Subject: [PATCH 06/26] - fix crashes for default self-test - fixes for highest bitrates - 'sw_13k2_512k.bin' switching profile + formatting - fix crashes for 'binaural' and 'binaural_room' outputs + formatting --- lib_com/ivas_cnst.h | 2 +- lib_com/ivas_prot.h | 6 + lib_com/options.h | 4 +- lib_dec/ACcontextMapping_dec.c | 2 +- lib_dec/ivas_binauralRenderer.c | 14 +- lib_dec/ivas_binaural_reverb.c | 3 + lib_dec/ivas_dirac_dec.c | 7 +- lib_dec/ivas_dirac_dec_binaural_functions.c | 71 ++++++-- lib_dec/ivas_init_dec.c | 6 +- lib_dec/ivas_sba_dec.c | 180 ++++++++++---------- lib_dec/ivas_spar_decoder.c | 26 +-- lib_enc/ivas_core_enc.c | 19 ++- lib_enc/ivas_core_pre_proc.c | 9 + lib_enc/ivas_cpe_enc.c | 6 +- lib_enc/ivas_init_enc.c | 6 +- lib_enc/ivas_ism_enc.c | 6 +- lib_enc/ivas_mct_enc.c | 16 ++ lib_enc/ivas_sba_enc.c | 20 +-- lib_enc/ivas_sce_enc.c | 10 +- lib_enc/ivas_spar_encoder.c | 19 ++- lib_enc/ivas_stereo_mdct_core_enc.c | 1 + 21 files changed, 270 insertions(+), 163 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 10cd091203..df5d166b53 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -911,7 +911,7 @@ typedef enum { DIRAC_OPEN, /* initialize to default value */ DIRAC_RECONFIGURE /* HOA3 */ -#ifdef SBA_BITRATE_SWITCHING // VE: TBV - just dirty patch for the moment +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV - just dirty patch for the moment ,DIRAC_RECONFIGURE_MODE /* HOA3 */ #endif } DIRAC_CONFIG_FLAG; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index e0e39bcb6e..46691f2d49 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -191,6 +191,9 @@ ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ const int16_t last_element_mode, /* i : last element mode */ const int32_t element_brate, /* i : element bitrate */ +#ifdef SBA_BITRATE_SWITCHING + const int32_t last_element_brate, /* i : last element bitrate */ +#endif const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ @@ -387,6 +390,9 @@ ivas_error ivas_core_enc( float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ +#ifdef SBA_BITRATE_SWITCHING + const int16_t ivas_format, /* i : IVAS format */ +#endif const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); diff --git a/lib_com/options.h b/lib_com/options.h index d084e73715..65c4d0eee4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,9 +58,9 @@ #ifdef DEBUGGING -#define MEM_COUNT_DETAILS /* RAM counting tool: print per sub-structure details */ +/*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ diff --git a/lib_dec/ACcontextMapping_dec.c b/lib_dec/ACcontextMapping_dec.c index 10fb369741..3308eb38b9 100644 --- a/lib_dec/ACcontextMapping_dec.c +++ b/lib_dec/ACcontextMapping_dec.c @@ -633,8 +633,8 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS( /* Update bitstream pointer */ st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish( &rc_st_dec ); - /* Confirm that there is no overflow */ #ifdef DEBUGGING + /* Confirm that there is no overflow */ assert( st->next_bit_pos - start_bit_pos + rest_bits <= 0 ); #endif diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 153e159adc..74c2688567 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -439,7 +439,7 @@ ivas_error ivas_binRenderer_open( { hBinRenderer->ivas_format = SBA_FORMAT; } - hBinRenderer->max_band = (int16_t) ( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + hBinRenderer->max_band = ( int16_t )( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); convBand = hBinRenderer->max_band; hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */ @@ -472,10 +472,17 @@ ivas_error ivas_binRenderer_open( } ivas_output_init( &out_setup, AUDIO_CONFIG_7_1_4 ); - if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + +#ifdef SBA_BITRATE_SWITCHING + if( st_ivas->hoa_dec_mtx == NULL ) +#endif { - return error; + if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } } + hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ); } @@ -504,6 +511,7 @@ ivas_error ivas_binRenderer_open( { return error; } + if ( !st_ivas->hRenderConfig->roomAcoustics.override ) { ivas_binaural_reverb_setReverbTimes( hBinRenderer->hReverb, st_ivas->hDecoderConfig->output_Fs, fastconvReverberationTimes, fastconvReverberationEneCorrections ); diff --git a/lib_dec/ivas_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index 054b8c1558..82c8e0056b 100644 --- a/lib_dec/ivas_binaural_reverb.c +++ b/lib_dec/ivas_binaural_reverb.c @@ -493,6 +493,9 @@ void ivas_binaural_reverb_close( } count_free( ( *hReverb ) ); +#ifdef SBA_BITRATE_SWITCHING + ( *hReverb ) = NULL; +#endif return; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 30c32ca7f6..7b51961c8b 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -129,6 +129,8 @@ ivas_error ivas_dirac_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ #ifdef SBA_BITRATE_SWITCHING const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#else + const DIRAC_CONFIG_FLAG flag_config /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ #endif ) { @@ -277,9 +279,10 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { -#ifdef SBA_BITRATE_SWITCHING // VE: TBV +#ifdef SBA_BITRATE_SWITCHING st_ivas->nchan_transport = nchan_transport_orig; #endif + return IVAS_ERR_OK; } @@ -664,7 +667,7 @@ ivas_error ivas_dirac_dec_config( else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) { #ifdef SBA_BITRATE_SWITCHING - if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) || flag_config_inp == DIRAC_RECONFIGURE_MODE ) + if ( nchan_transport != nchan_transport_old || hDirAC->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) #else if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) #endif diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index 5e698ab289..b4421d2c27 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -98,9 +98,21 @@ ivas_error ivas_dirac_dec_init_binaural_data( float binCenterFreq, tmpFloat; ivas_error error; - if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV - Renderer Reconfig. to be reviewed + hBinaural = st_ivas->hDiracDecBin; + + if ( hBinaural == NULL ) +#endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + } + +#ifdef SBA_BITRATE_SWITCHING + hBinaural->hTdDecorr = NULL; + hBinaural->hReverb = NULL; +#endif } nBins = st_ivas->hDirAC->num_freq_bands; @@ -150,7 +162,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( hBinaural->useTdDecorr = 1; } } - if ( st_ivas->ivas_format == MASA_FORMAT ) + else if ( st_ivas->ivas_format == MASA_FORMAT ) { if ( ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_48k && st_ivas->nchan_transport == 1 ) || st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) { @@ -188,20 +200,36 @@ ivas_error ivas_dirac_dec_init_binaural_data( else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */ { mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins ); - if ( hBinaural->useSubframeMode ) + +#ifdef SBA_BITRATE_SWITCHING + /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */ + if ( hBinaural->hReverb != NULL && ( + ( hBinaural->hReverb->numBins != nBins ) || + ( hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) || + ( !hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX ) ) ) { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) ) != IVAS_ERR_OK ) - { - return error; - } + ivas_binaural_reverb_close( &( hBinaural->hReverb ) ); } - else + + if ( hBinaural->hReverb == NULL ) +#endif { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX ) ) != IVAS_ERR_OK ) + if ( hBinaural->useSubframeMode ) { - return error; + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX ) ) != IVAS_ERR_OK ) + { + return error; + } } } + ivas_binaural_reverb_setReverbTimes( hBinaural->hReverb, output_Fs, parametricReverberationTimes, parametricReverberationEneCorrections ); hBinaural->hReverb->useBinauralCoherence = 1; ivas_binaural_reverb_setPreDelay( hBinaural->hReverb, 10 ); @@ -221,7 +249,13 @@ ivas_error ivas_dirac_dec_init_binaural_data( { if ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_13k2 && st_ivas->ivas_format == SBA_FORMAT ) { - ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); +#ifdef SBA_BITRATE_SWITCHING + if ( hBinaural->hTdDecorr == NULL ) +#endif + { + ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); + } + if ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) { hBinaural->hTdDecorr->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; @@ -238,7 +272,11 @@ ivas_error ivas_dirac_dec_init_binaural_data( } else { +#ifdef SBA_BITRATE_SWITCHING + ivas_spar_td_decorr_dec_close( &( hBinaural->hTdDecorr ) ); +#else hBinaural->hTdDecorr = NULL; +#endif } st_ivas->hDiracDecBin = hBinaural; @@ -297,7 +335,7 @@ void ivas_dirac_dec_binaural( { decorr_signal[ch] = (float *) &( output_f[ch + BINAURAL_CHANNELS][0] ); } - output_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + output_frame = ( int16_t )( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); ivas_td_decorr_process( st_ivas->hDiracDecBin->hTdDecorr, output_f, decorr_signal, output_frame ); } @@ -572,7 +610,6 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric uint8_t applyLowBitRateEQ; int16_t dirac_read_idx; - hDirAC = st_ivas->hDirAC; h = st_ivas->hDiracDecBin; separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; @@ -1157,14 +1194,14 @@ static void ivas_dirac_dec_binaural_process_output( if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { /* Process second / room effect part of binaural output when needed */ - ivas_binaural_reverb_processFrame( st_ivas->hDiracDecBin->hReverb, numInChannels, inRe, inIm, reverbRe, reverbIm, firstSlot ); + ivas_binaural_reverb_processFrame( h->hReverb, numInChannels, inRe, inIm, reverbRe, reverbIm, firstSlot ); } interpVal = 0.0f; for ( slot = firstSlot; slot < ( firstSlot + numSlots ); slot++ ) { interpVal += 1.0f / (float) numSlots; - if ( !st_ivas->hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) + if ( !h->useTdDecorr && max_band_decorr > 0 ) { ivas_dirac_dec_decorrelate_slot( st_ivas->hDirAC, slot, inRe, inIm, decSlotRe, decSlotIm ); } @@ -1179,7 +1216,7 @@ static void ivas_dirac_dec_binaural_process_output( /* Processing of the first / HRTF part of the binaural output. */ for ( chB = 0; chB < numInChannels; chB++ ) { - if ( st_ivas->hDiracDecBin->useTdDecorr ) + if ( h->useTdDecorr ) { decSlotRePointer = inRe[chB + 2][slot]; decSlotImPointer = inIm[chB + 2][slot]; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 4050d97445..77d01af55c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -121,11 +121,11 @@ ivas_error ivas_dec_setup( /* read Ambisonic (SBA) order */ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; /* 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 ); - - num_bits_read += SBA_ORDER_BITS; + if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_4k4 ) { if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) @@ -280,6 +280,7 @@ ivas_error ivas_dec_setup( st->next_bit_pos = num_bits_read; st->total_brate = ACELP_8k00; /* only temporary initialization - this is needed for get_next_indice() in the frame following NO_DATA frame */ } + return error; } @@ -928,7 +929,6 @@ ivas_error ivas_init_decoder( return error; } - for ( n = 0; n < CPE_CHANNELS; n++ ) { reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 2e8d1496dd..dcf07a97f5 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -556,12 +556,41 @@ ivas_error ivas_sba_dec_reconfigure( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ + + if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + } + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } + /*-----------------------------------------------------------------* * hDirAC decoder handle configuration *-----------------------------------------------------------------*/ -#ifdef SBA_BITRATE_SWITCHING // VE: TBD - possibly merge with the 'else if' branch below - if ( sba_mode_old != st_ivas->sba_mode ) + if ( sba_mode_old != st_ivas->sba_mode ) // VE: TBD - possibly merge with the 'else if' branch below { if ( st_ivas->hDirAC != NULL ) { @@ -579,9 +608,8 @@ ivas_error ivas_sba_dec_reconfigure( } } else -#endif if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && - ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) ) { if ( st_ivas->hDirAC != NULL ) { @@ -753,7 +781,11 @@ ivas_error ivas_sba_dec_reconfigure( } else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) { +#ifdef SBA_BITRATE_SWITCHING + if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) +#else if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -812,6 +844,47 @@ ivas_error ivas_sba_dec_reconfigure( } } + /*-----------------------------------------------------------------* + * Set CNA/CNG flags + *-----------------------------------------------------------------*/ + + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) + { + /* skip as done in init function */ + } + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + } + else if ( st_ivas->nchan_transport == 2 ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + else + { + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + } + } + } + + /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ + if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) + { + if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } /*-----------------------------------------------------------------* * HP20 memories @@ -891,18 +964,18 @@ ivas_error ivas_sba_dec_reconfigure( numCldfbAnalyses_old--; } - /* Analysis*/ - if ( numCldfbAnalyses_old > numCldfbAnalyses ) + /* CLDFB Analysis */ + /* resample CLDFB analysis instances */ + for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) { - /* resample CLDFB analysis instances */ - for ( i = 0; i < numCldfbAnalyses; i++ ) + if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) { - if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) - { - resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); - } + resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); } + } + if ( numCldfbAnalyses_old > numCldfbAnalyses ) + { /* delete superfluous CLDFB analysis instances */ for ( ; i < numCldfbAnalyses_old; i++ ) { @@ -912,15 +985,6 @@ ivas_error ivas_sba_dec_reconfigure( } else if ( numCldfbAnalyses_old < numCldfbAnalyses ) { - /* resample CLDFB analysis instances */ - for ( i = 0; i < numCldfbAnalyses_old; i++ ) - { - if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) - { - resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); - } - } - /* create additional CLDFB analysis instances */ for ( ; i < numCldfbAnalyses; i++ ) { @@ -931,7 +995,7 @@ ivas_error ivas_sba_dec_reconfigure( } } - /* Synthesis */ + /* CLDFB Synthesis */ if ( numCldfbSyntheses_old > numCldfbSyntheses ) { /* delete superfluous CLDFB synthesis instances */ @@ -959,78 +1023,6 @@ ivas_error ivas_sba_dec_reconfigure( ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); } - /*-----------------------------------------------------------------* - * Set CNA/CNG flags - *-----------------------------------------------------------------*/ - - if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) - { - /* skip as done in init function */ - } - else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) - { - st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; - st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; - } - else if ( st_ivas->nchan_transport == 2 ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; - } - } - else - { - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; - } - } - } - - /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ - if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) - { - if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /*-------------------------------------------------------------------* - * Reallocate and initialize binaural rendering handles - *--------------------------------------------------------------------*/ - - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hBinRenderer == NULL ) - { - /* open fastconv binaural renderer */ - if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) - { - ivas_binRenderer_close( &st_ivas->hBinRenderer ); - } - - if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) - { - /* open parametric binaural renderer */ - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); - } - return error; #else int16_t i, n; diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 1c9cd24e87..22abfa8e5f 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -665,6 +665,13 @@ static ivas_error ivas_spar_dec_MD( { ivas_pca_read_bits( st0, hSpar->hPCA ); } +#ifdef SBA_BITRATE_SWITCHING + else if ( ivas_total_brate == PCA_BRATE && sba_order == 1 ) + { + /* skip PCA bypass bit */ + get_next_indice( st0, 1 ); + } +#endif /*---------------------------------------------------------------------* * Read AGC bits @@ -882,11 +889,10 @@ void ivas_spar_dec_upmixer( int16_t cldfb_band, num_cldfb_bands, numch_in, numch_out; float *cldfb_in_ts_re[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; float *cldfb_in_ts_im[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; - int16_t i, b, ts, out_ch, in_ch; + int16_t i, b, ts, out_ch, in_ch, i_sf; int16_t num_spar_bands, spar_band, nchan_transport; int16_t num_in_ingest, num_bands_out, split_band; float Pcm_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - int16_t numch_out_dirac; float *pPcm_tmp[MAX_OUTPUT_CHANNELS]; float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -1024,7 +1030,7 @@ void ivas_spar_dec_upmixer( *---------------------------------------------------------------------*/ /* set-up pointers */ - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { /* at this point, output channels are used as intermediate procesing buffers */ for ( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS; in_ch++ ) @@ -1065,9 +1071,7 @@ void ivas_spar_dec_upmixer( /* determine if we can skip certain data */ ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ - numch_out_dirac = st_ivas->hDecoderConfig->nchan_out; - - for ( int16_t i_sf = 0; i_sf < MAX_PARAM_SPATIAL_SUBFRAMES; i_sf++ ) + for ( i_sf = 0; i_sf < MAX_PARAM_SPATIAL_SUBFRAMES; i_sf++ ) { /* CLDFB analysis of incoming frame */ for ( in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -1086,7 +1090,7 @@ void ivas_spar_dec_upmixer( for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ - ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -1135,7 +1139,7 @@ void ivas_spar_dec_upmixer( } } - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { ivas_dirac_dec( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im, i_sf ); } @@ -1160,7 +1164,7 @@ void ivas_spar_dec_upmixer( } else { - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA || + if ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) @@ -1183,7 +1187,7 @@ void ivas_spar_dec_upmixer( else { /* CLDFB to time synthesis (overwrite mixer output) */ - for ( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + for ( out_ch = 0; out_ch < hDecoderConfig->nchan_out; out_ch++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { @@ -1196,7 +1200,7 @@ void ivas_spar_dec_upmixer( } } #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->numOutChannels = numch_out_dirac; + hSpar->numOutChannels = hDecoderConfig->nchan_out; #endif } #ifdef DEBUG_SBA_AUDIO_DUMP diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 42a17cb9cb..fdb7962ca8 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -79,6 +79,9 @@ ivas_error ivas_core_enc( float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */ float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ +#ifdef SBA_BITRATE_SWITCHING + const int16_t ivas_format, /* i : IVAS format */ +#endif const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ) { @@ -101,7 +104,11 @@ ivas_error ivas_core_enc( int16_t unbits[CPE_CHANNELS]; float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t last_element_mode, tdm_Pitch_reuse_flag; +#ifdef SBA_BITRATE_SWITCHING + int32_t element_brate, last_element_brate, input_Fs; +#else int32_t element_brate, input_Fs; +#endif ivas_error error; wmops_sub_start( "ivas_core_enc" ); @@ -120,6 +127,9 @@ ivas_error ivas_core_enc( hStereoTD = NULL; hStereoICBWE = NULL; element_brate = hSCE->element_brate; +#ifdef SBA_BITRATE_SWITCHING + last_element_brate = hSCE->last_element_brate; +#endif last_element_mode = IVAS_SCE; tdm_Pitch_reuse_flag = -1; } @@ -134,6 +144,9 @@ ivas_error ivas_core_enc( sts = hCPE->hCoreCoder; hStereoICBWE = hCPE->hStereoICBWE; element_brate = hCPE->element_brate; +#ifdef SBA_BITRATE_SWITCHING + last_element_brate = hCPE->last_element_brate; +#endif last_element_mode = hCPE->last_element_mode; if ( hCPE->hStereoTD != NULL ) @@ -174,7 +187,11 @@ ivas_error ivas_core_enc( * Pre-processing, incl. Decision matrix *---------------------------------------------------------------------*/ - if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) + if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, +#ifdef SBA_BITRATE_SWITCHING // VE2EF: dirty patch - review needed + ivas_format == SBA_FORMAT ? last_element_brate : element_brate, +#endif + input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 4ae384d5ff..6856f59eba 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -55,6 +55,9 @@ ivas_error pre_proc_ivas( Encoder_State *st, /* i/o: encoder state structure */ const int16_t last_element_mode, /* i : last element mode */ const int32_t element_brate, /* i : element bitrate */ +#ifdef SBA_BITRATE_SWITCHING + const int32_t last_element_brate, /* i : last element bitrate */ +#endif const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */ @@ -275,6 +278,12 @@ ivas_error pre_proc_ivas( { st->hTcxEnc->tfm_mem = 0.75f; } +#ifdef SBA_BITRATE_SWITCHING // VE2EF: review needed + else if( element_brate != last_element_brate ) + { + SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, is_mct ); + } +#endif /*-----------------------------------------------------------------* * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index edc325d041..ea1fb15bc1 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -622,7 +622,11 @@ ivas_error ivas_cpe_enc( * Core Encoder *----------------------------------------------------------------*/ - if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, +#ifdef SBA_BITRATE_SWITCHING + ivas_format, +#endif + 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 34868ebefc..823fcfa7c6 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -479,11 +479,9 @@ ivas_error ivas_init_encoder( } else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) { + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } if ( ivas_format == SBA_FORMAT ) diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 2653829d13..e4cda0e752 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -262,7 +262,11 @@ ivas_error ivas_ism_enc( * Encoder *----------------------------------------------------------------*/ - if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, +#ifdef SBA_BITRATE_SWITCHING + ISM_FORMAT, +#endif + 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index bcf5482da9..6962b5a891 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -337,6 +337,13 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */ hMCT->num_lfe = TRUE; } +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV + else if ( ivas_format == SBA_FORMAT ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + hMCT->num_lfe = FALSE; + } +#else else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) { hMCT->nchan_out_woLFE = ivas_dirac_getNumTransportChannels( ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); @@ -347,6 +354,7 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); hMCT->num_lfe = FALSE; } +#endif else { assert( !"IVAS format currently not supported for MCT" ); @@ -473,6 +481,14 @@ ivas_error mct_enc_reconfigure( } } +#ifdef SBA_BITRATE_SWITCHING + hMCT->hbr_mct = 0; + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ivas_total_brate >= IVAS_256k ) + { + hMCT->hbr_mct = 1; + } +#endif + return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 431f4b3655..cfd15497e7 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -216,13 +216,8 @@ ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - int16_t ntransport; - int16_t ntransport_old; - int16_t nSCE_old; - int16_t nCPE_old; - int16_t sce_id; - int16_t cpe_id; - int16_t n; + int16_t nchan_transport_old, nSCE_old, nCPE_old; + int16_t n, sce_id, cpe_id; Indice *ind_list_metadata; int32_t ivas_total_brate; ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -235,8 +230,7 @@ ivas_error ivas_sba_enc_reconfigure( if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { - ntransport = st_ivas->nchan_transport; - ntransport_old = st_ivas->nchan_transport; + nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; ind_list_metadata = NULL; @@ -350,9 +344,7 @@ ivas_error ivas_sba_enc_reconfigure( } #endif - ntransport = st_ivas->nchan_transport; - - if ( ntransport == ntransport_old ) + if ( st_ivas->nchan_transport == nchan_transport_old ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -563,7 +555,11 @@ ivas_error ivas_sba_enc_reconfigure( } else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) { +#ifdef SBA_BITRATE_SWITCHING + if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) +#else if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 99f05719b3..1972a58c7e 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -166,11 +166,11 @@ ivas_error ivas_sce_enc( st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC; /* set flag for sampling rate of OL S/M classifier */ -#ifdef SBA_BITRATE_SWITCHING // VE: TBV whether it can be done more efficiently +#ifdef SBA_BITRATE_SWITCHING // VE2EF: TBV whether it can be done more efficiently flag_16k_smc = 0; if( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate ) { - flag_16k_smc = 0; + flag_16k_smc = 1; } #else flag_16k_smc = ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) ); @@ -240,7 +240,11 @@ ivas_error ivas_sce_enc( * Core Encoder *----------------------------------------------------------------*/ - if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, flag_16k_smc ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, +#ifdef SBA_BITRATE_SWITCHING + ivas_format, +#endif + flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 5c7db120ca..c7f3931555 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -437,7 +437,7 @@ static ivas_error ivas_spar_enc_process( ivas_total_brate = hEncoderConfig->ivas_total_brate; num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); @@ -633,18 +633,23 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; -#ifndef SBA_BITRATE_SWITCHING - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); -#else - if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) +#ifdef SBA_BITRATE_SWITCHING + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { - return error; + if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + { + return error; + } } + else #endif + { + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); + } } - nchan_transport = hSpar->hMdEnc->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdEnc->spar_md_cfg.nchan_transport; // VE: == st_ivas->nchan_transport /*-----------------------------------------------------------------------------------------* * MetaData encoder diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index c41df7b24e..e9328fddc3 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -253,6 +253,7 @@ void stereo_mdct_core_enc( /*--------------------------------------------------------------* * Stereo Processing *---------------------------------------------------------------*/ + if ( !hStereoMdct->isSBAStereoMode ) { stereo_coder_tcx( hStereoMdct, sts, ms_mask, mdst_spectrum, inv_spectrum, inv_mdst_spectrum, 0 ); -- GitLab From cc76c5ed083506e80030046f451bf7b66fdc8361 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 23 Sep 2022 10:53:50 +0200 Subject: [PATCH 07/26] fixes to debugging files; under DEBUG_MODE_INFO --- lib_dec/ivas_cpe_dec.c | 3 +++ lib_dec/ivas_mct_dec.c | 5 +++++ lib_dec/ivas_sce_dec.c | 3 +++ lib_enc/ivas_cpe_enc.c | 8 +++++--- lib_enc/ivas_sce_enc.c | 3 ++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 321eadc380..0befe128d1 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -514,6 +514,9 @@ ivas_error ivas_cpe_dec( { dbgwrite( output[j], sizeof( float ), output_frame, 1, fname( debug_dir, "output.cpe", j, cpe_id, DEC ) ); } + tmpF = 0; + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) ); + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) ); } } #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index c462a01ff6..b4a4da3e3c 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -255,6 +255,11 @@ ivas_error ivas_mct_dec( { float tmpF = st_ivas->hCPE[cpe_id]->element_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) ); + + dbgwrite( output[0], sizeof( float ), output_frame, 1, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) ); + tmpF = 0; + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) ); + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, cpe_id, DEC ) ); } #endif diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 299bc8e540..0ea9c514f2 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -277,6 +277,9 @@ ivas_error ivas_sce_dec( dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); + tmpF = 0; + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) ); + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) ); } } #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index ea1fb15bc1..b6a34c106d 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -423,9 +423,11 @@ ivas_error ivas_cpe_enc( } #ifdef DEBUG_MODE_INFO - dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" ); - dbgwrite( sts[1]->input - NS2SA( sts[1]->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX.ch2" ); - dbgwrite( &hCPE->element_mode, 2, 1, input_frame, "res/element_mode" ); + for ( n = 0; n < n_CoreChannels; n++ ) + { + dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, fname( debug_dir, "input_DMX", n, sts[n]->id_element, ENC ) ); + } + dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, sts[0]->id_element, ENC ) ); #endif /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 1972a58c7e..8ddb5f5042 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -177,7 +177,8 @@ ivas_error ivas_sce_enc( #endif #ifdef DEBUG_MODE_INFO - dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" ); + dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); #endif /*----------------------------------------------------------------* -- GitLab From 5cc0eeafa5c0b8812206f6cd05e222eb24387c51 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 26 Sep 2022 11:18:33 +0200 Subject: [PATCH 08/26] updates within IMPR_TC_SWITCHING_MEMORY --- lib_com/tools.c | 2 +- lib_dec/ivas_spar_decoder.c | 3 +- lib_enc/ivas_dirac_enc.c | 65 ++++++++++++++++++++++++++++++------- lib_enc/ivas_enc.c | 11 +++++++ lib_enc/ivas_sba_enc.c | 63 +++++++++++++++++++++++++++++++---- lib_enc/ivas_sce_enc.c | 30 +++++++++-------- lib_enc/ivas_spar_encoder.c | 46 ++++++++++++++++++++++++++ 7 files changed, 186 insertions(+), 34 deletions(-) diff --git a/lib_com/tools.c b/lib_com/tools.c index 3e6e56d5a0..fb2ea7689c 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1447,7 +1447,7 @@ void polezero_filter( } #define WMC_TOOL_MAN - +// VE: define complexity macros here static float fleft_shift( float input, const int16_t shift ) { return ( input * (float) pow( 2.0, (double) shift ) ); diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 22abfa8e5f..f550c8a0d1 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1004,7 +1004,6 @@ void ivas_spar_dec_upmixer( #endif } - /*---------------------------------------------------------------------* * TD decorrelation *---------------------------------------------------------------------*/ @@ -1018,7 +1017,7 @@ void ivas_spar_dec_upmixer( mvr2r( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - i], output[nchan_internal - 1 - i], output_frame ); } - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; // VE2DB: same as below, can be simplified } else { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index e31c5470a1..cb1fa2710b 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -159,7 +159,7 @@ ivas_error ivas_dirac_enc_open( } } - hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hDirAC->no_col_avg_diff = ( int16_t )( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { hDirAC->buffer_intensity_real[i] = (float **) count_malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ); @@ -345,7 +345,7 @@ void ivas_dirac_enc( } ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame ); - + /* encode parameters */ if ( sba_planar || hQMetaData->useLowerRes ) { @@ -438,9 +438,7 @@ void ivas_dirac_enc( else { /* encode SID parameters */ - ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, - SBA_FORMAT, - SBA_MODE_DIRAC ); + ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT, SBA_MODE_DIRAC ); } } } @@ -465,14 +463,59 @@ void ivas_dirac_enc_spar_delay_synchro( int16_t ch_idx; float tmp_buffer[L_FRAME48k]; - for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) +#ifdef IMPR_TC_SWITCHING_MEMORY +#if 1 + /* check last sba_mode */ + if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR ) { - mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); - mvr2r( st_ivas->hDirAC->sba_synchro_buffer[ch_idx], data_f[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); - mvr2r( tmp_buffer, &data_f[ch_idx][st_ivas->hDirAC->num_samples_synchro_delay], input_frame - st_ivas->hDirAC->num_samples_synchro_delay ); - mvr2r( &tmp_buffer[input_frame - st_ivas->hDirAC->num_samples_synchro_delay], st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); - } + Encoder_State *sts[MCT_MAX_BLOCKS]; + int16_t i_chan = 0; + + /* initializations */ + for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]; + i_chan++; + } + for ( int16_t cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i_chan] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; + i_chan++; + } + } + + for ( ch_idx = 0; ch_idx < i_chan; ch_idx++ ) + { + mvr2r( sts[ch_idx]->input, st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); + } + } +#else + /* check last sba_mode */ + if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR ) + { + for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) + { + mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); + //set_f( data_f[ch_idx], 0, 48 ); + mvr2r( tmp_buffer, &data_f[ch_idx][st_ivas->hDirAC->num_samples_synchro_delay], input_frame - st_ivas->hDirAC->num_samples_synchro_delay ); + mvr2r( &tmp_buffer[input_frame - st_ivas->hDirAC->num_samples_synchro_delay], st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); + } + } + else +#endif +#endif + { + for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) + { + mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); + mvr2r( st_ivas->hDirAC->sba_synchro_buffer[ch_idx], data_f[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); + mvr2r( tmp_buffer, &data_f[ch_idx][st_ivas->hDirAC->num_samples_synchro_delay], input_frame - st_ivas->hDirAC->num_samples_synchro_delay ); + mvr2r( &tmp_buffer[input_frame - st_ivas->hDirAC->num_samples_synchro_delay], st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); + } + } return; } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 927d40f607..a7209051b9 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -234,6 +234,17 @@ ivas_error ivas_enc( ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 ); } + + float tmpF = 0; + dbgwrite( &tmpF, 4, 1, 960, "res/tmp_ppFilterbank_prior_input" ); + if ( st_ivas->nSCE > 0 ) + { + dbgwrite( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); + } + else + { + dbgwrite( st_ivas->hCPE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); + } } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index cfd15497e7..54e5392295 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -218,6 +218,9 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nchan_transport_old, nSCE_old, nCPE_old; int16_t n, sce_id, cpe_id; +#ifdef IMPR_TC_SWITCHING_MEMORY + int16_t len_inp_memory; +#endif Indice *ind_list_metadata; int32_t ivas_total_brate; ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -225,6 +228,10 @@ ivas_error ivas_sba_enc_reconfigure( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; +#ifdef IMPR_TC_SWITCHING_MEMORY + //VE: TBD - last 1ms sample are not correct but are needed for DirAC<->SPAR delay compensation + len_inp_memory = ( int16_t )( hEncoderConfig->input_Fs / FRAMES_PER_SEC ) + NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); +#endif ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -376,11 +383,12 @@ ivas_error ivas_sba_enc_reconfigure( else { Indice *ind_list; - int16_t nb_bits_tot; - int16_t next_ind; - int16_t last_ind; - BSTR_ENC_HANDLE hBstr; - BSTR_ENC_HANDLE hMetaData; + int16_t nb_bits_tot, next_ind, last_ind; + BSTR_ENC_HANDLE hBstr, hMetaData; +#ifdef IMPR_TC_SWITCHING_MEMORY + int16_t n_CoreCoder_save; + float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; +#endif ind_list = NULL; hBstr = NULL; @@ -411,15 +419,36 @@ ivas_error ivas_sba_enc_reconfigure( last_ind = hBstr->last_ind; ind_list_metadata = hMetaData->ind_list; - /* destroy superfluous core coder elements */ // VE: TBV whether a core-coder can be reused +#ifdef IMPR_TC_SWITCHING_MEMORY + n_CoreCoder_save = min( st_ivas->nchan_transport, nchan_transport_old ); +#endif + + /* destroy superfluous core coder elements */ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) { +#ifdef IMPR_TC_SWITCHING_MEMORY + /* save input audio buffers */ + if ( n_CoreCoder_save > sce_id ) + { + mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); + } +#endif destroy_sce_enc( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) { +#ifdef IMPR_TC_SWITCHING_MEMORY + /* save input audio buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if( n_CoreCoder_save > cpe_id * CPE_CHANNELS + n ) + { + mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + } + } +#endif destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); st_ivas->hCPE[cpe_id] = NULL; } @@ -442,12 +471,14 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nSCE_existing; nSCE_existing = min( nSCE_old, st_ivas->nSCE ); + for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; 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() */ } + for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) @@ -455,6 +486,14 @@ ivas_error ivas_sba_enc_reconfigure( return error; } +#ifdef IMPR_TC_SWITCHING_MEMORY + /* propagate input audio buffers */ + if ( n_CoreCoder_save > sce_id ) + { + mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + } +#endif + /* prepare bitstream buffers */ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; @@ -479,6 +518,7 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nCPE_existing; nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -498,6 +538,17 @@ ivas_error ivas_sba_enc_reconfigure( return error; } +#ifdef IMPR_TC_SWITCHING_MEMORY + /* propagate input audio buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( n_CoreCoder_save > cpe_id * CPE_CHANNELS + n ) + { + mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + } + } +#endif + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 8ddb5f5042..211c4af9fc 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -146,7 +146,7 @@ ivas_error ivas_sce_enc( { if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) { - st->bits_frame_nominal = (int16_t) ( hSCE->element_brate / FRAMES_PER_SEC ); + st->bits_frame_nominal = ( int16_t )( hSCE->element_brate / FRAMES_PER_SEC ); } else { @@ -155,11 +155,11 @@ ivas_error ivas_sce_enc( } else if ( st_ivas->hSpar != NULL ) { - st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); + st->bits_frame_nominal = ( int16_t )( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); } else { - st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); + st->bits_frame_nominal = ( int16_t )( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); } /* set "total_brate" */ @@ -168,7 +168,7 @@ ivas_error ivas_sce_enc( /* set flag for sampling rate of OL S/M classifier */ #ifdef SBA_BITRATE_SWITCHING // VE2EF: TBV whether it can be done more efficiently flag_16k_smc = 0; - if( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate ) + if ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate ) { flag_16k_smc = 1; } @@ -209,7 +209,7 @@ ivas_error ivas_sce_enc( * Reset metadata *----------------------------------------------------------------*/ - reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode,IVAS_SCE ); + reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode, IVAS_SCE ); /*----------------------------------------------------------------* * Write IVAS format signaling in SID frames @@ -241,11 +241,11 @@ ivas_error ivas_sce_enc( * Core Encoder *----------------------------------------------------------------*/ - if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, + if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, #ifdef SBA_BITRATE_SWITCHING ivas_format, -#endif - flag_16k_smc ) ) != IVAS_ERR_OK ) +#endif + flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } @@ -362,17 +362,19 @@ ivas_error create_sce_enc( *-------------------------------------------------------------------------*/ void destroy_sce_enc( - SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ) { Encoder_State *st; - st = hSCE->hCoreCoder[0]; - - if ( st != NULL ) { - destroy_core_enc( st ); - st = NULL; + st = hSCE->hCoreCoder[0]; + + if ( st != NULL ) + { + destroy_core_enc( st ); + st = NULL; + } } if ( hSCE->hMetaData != NULL ) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index c7f3931555..3e935ffccb 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -286,6 +286,52 @@ ivas_error ivas_spar_enc( error = IVAS_ERR_OK; hEncoderConfig = st_ivas->hEncoderConfig; +#ifdef IMPR_TC_SWITCHING_MEMORY + // VE: needs more work - not the right signal segment is used for updating FB memory!! + // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->buff ? + + /* check last sba_mode */ + if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_DIRAC ) + { + Encoder_State *sts[MCT_MAX_BLOCKS]; + + /* initializations */ + for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]; + } + + for ( int16_t cpe_id = 0, i = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; + i++; + } + } + + /* update FB prior input */ + // VE: last 1ms of 'ppFilterbank_prior_input' is not correct + for ( int16_t i = 0; i < st_ivas->nchan_transport; i++ ) + { + mvr2r( sts[i]->input_buff + NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ), st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input[i] + st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length - input_frame, input_frame ); + } + + //VE: TBD - update 'st->input_buff' for SparVAD + } + + dbgwrite( st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input[0], 4, 960, 1, "res/tmp_ppFilterbank_prior_input" ); + if ( st_ivas->nSCE > 0 ) + { + dbgwrite( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); + } + else + { + dbgwrite( st_ivas->hCPE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); + } + +#endif + /* front VAD */ if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], st_ivas->hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { -- GitLab From 1c7ee9dc8e3cdcca80262b559c768020bc9e7fd5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 26 Sep 2022 11:21:36 +0200 Subject: [PATCH 09/26] remove debugging stuff; activate IMPR_TC_SWITCHING_MEMORY --- lib_com/options.h | 3 ++- lib_enc/ivas_dirac_enc.c | 16 +--------------- lib_enc/ivas_enc.c | 10 ---------- lib_enc/ivas_spar_encoder.c | 14 +------------- 4 files changed, 4 insertions(+), 39 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2e4146a56c..5413525fd6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -60,7 +60,7 @@ /*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ @@ -150,6 +150,7 @@ #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ #define FIX_I98_HANDLES_TO_NULL /* Issue 98: do the setting of all handles to NULL in one place */ #define SBA_BITRATE_SWITCHING /* Issue 114: suppport bitrate switching in SBA */ +#define IMPR_TC_SWITCHING_MEMORY /* reuse core-coder memory when switching between different number of transport channels */ #define QUANTISE_REAL_FCN_CLEAN_UP /*Clean up the ivas_quantise_real_values() function*/ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index cb1fa2710b..57d7a38cc8 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -464,7 +464,6 @@ void ivas_dirac_enc_spar_delay_synchro( float tmp_buffer[L_FRAME48k]; #ifdef IMPR_TC_SWITCHING_MEMORY -#if 1 /* check last sba_mode */ if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR ) { @@ -492,21 +491,8 @@ void ivas_dirac_enc_spar_delay_synchro( mvr2r( sts[ch_idx]->input, st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); } } -#else - /* check last sba_mode */ - if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR ) - { - for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) - { - mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); - //set_f( data_f[ch_idx], 0, 48 ); - mvr2r( tmp_buffer, &data_f[ch_idx][st_ivas->hDirAC->num_samples_synchro_delay], input_frame - st_ivas->hDirAC->num_samples_synchro_delay ); - mvr2r( &tmp_buffer[input_frame - st_ivas->hDirAC->num_samples_synchro_delay], st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); - } - } - else -#endif #endif + { for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a7209051b9..20622edfdd 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -235,16 +235,6 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 ); } - float tmpF = 0; - dbgwrite( &tmpF, 4, 1, 960, "res/tmp_ppFilterbank_prior_input" ); - if ( st_ivas->nSCE > 0 ) - { - dbgwrite( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); - } - else - { - dbgwrite( st_ivas->hCPE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); - } } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 3e935ffccb..4e934c2eab 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -287,8 +287,7 @@ ivas_error ivas_spar_enc( hEncoderConfig = st_ivas->hEncoderConfig; #ifdef IMPR_TC_SWITCHING_MEMORY - // VE: needs more work - not the right signal segment is used for updating FB memory!! - // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->buff ? + // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->input ? /* check last sba_mode */ if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_DIRAC ) @@ -319,17 +318,6 @@ ivas_error ivas_spar_enc( //VE: TBD - update 'st->input_buff' for SparVAD } - - dbgwrite( st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input[0], 4, 960, 1, "res/tmp_ppFilterbank_prior_input" ); - if ( st_ivas->nSCE > 0 ) - { - dbgwrite( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); - } - else - { - dbgwrite( st_ivas->hCPE[0]->hCoreCoder[0]->input_buff, 4, 960, 1, "res/tmp_input_buff" ); - } - #endif /* front VAD */ -- GitLab From 50220a180e23e6a31c32dc07c4543aca8793a4ba Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 26 Sep 2022 11:59:44 +0200 Subject: [PATCH 10/26] disable DEBUG_MODE_INFO --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 5413525fd6..04a85fe78e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -60,7 +60,7 @@ /*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ -- GitLab From bd01c3e218d1a997fb24f2829a6f08b96780af5b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 27 Sep 2022 15:38:16 +0200 Subject: [PATCH 11/26] resolve conflicts --- lib_com/options.h | 3 +- lib_dec/ivas_sba_dec.c | 88 ++++++++++++++++++++++++------------ lib_enc/ivas_core_enc.c | 9 ++-- lib_enc/ivas_core_pre_proc.c | 3 -- lib_enc/ivas_dirac_enc.c | 40 ++-------------- lib_enc/ivas_sba_enc.c | 55 ++++------------------ lib_enc/ivas_spar_encoder.c | 4 +- 7 files changed, 79 insertions(+), 123 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 365017e83b..f64141d040 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,8 +160,7 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ -#define SBA_BITRATE_SWITCHING /* Issue 114: suppport bitrate switching in SBA */ -#define IMPR_TC_SWITCHING_MEMORY /* reuse core-coder memory when switching between different number of transport channels */ +#define SBA_BITRATE_SWITCHING /* Issue 114: suppport bitrate switching in SBA - CORECODER_BITRATE_SWITCHING must be defined */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 5f60de3075..d4235d25ff 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -108,8 +108,8 @@ void ivas_mc2sba( } else { - azimuth = ( int16_t )( hIntSetup.ls_azimuth[idx_in] ); - elevation = ( int16_t )( hIntSetup.ls_elevation[idx_in] ); + azimuth = (int16_t) ( hIntSetup.ls_azimuth[idx_in] ); + elevation = (int16_t) ( hIntSetup.ls_elevation[idx_in] ); idx_in++; /* get HOA response for direction (ACN/SN3D)*/ @@ -409,8 +409,8 @@ void ivas_ism2sba( for ( i = 0; i < num_objects; i++ ) { - azimuth = ( int16_t )( hIsmMetaData[i]->azimuth + 0.5f ); - elevation = ( int16_t )( hIsmMetaData[i]->elevation + 0.5f ); + azimuth = (int16_t) ( hIsmMetaData[i]->azimuth + 0.5f ); + elevation = (int16_t) ( hIsmMetaData[i]->elevation + 0.5f ); /*get HOA gets for direction (ACN/SN3D)*/ ivas_dirac_dec_get_response( @@ -466,7 +466,7 @@ ivas_error ivas_sba_dec_reconfigure( ivas_error error; hDecoderConfig = st_ivas->hDecoderConfig; - output_frame = ( int16_t )( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -607,12 +607,11 @@ ivas_error ivas_sba_dec_reconfigure( } } } - else - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && + else if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && #ifdef ALIGN_SID_SIZE - ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) ) + ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) ) #else - ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) ) + ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) ) #endif { if ( st_ivas->hDirAC != NULL ) @@ -655,6 +654,16 @@ ivas_error ivas_sba_dec_reconfigure( * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ +#ifdef CORECODER_BITRATE_SWITCHING + ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + + ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); +#else + /* remove dummy CPE element for DFT stereo-like upmix */ if ( sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) { @@ -773,7 +782,7 @@ ivas_error ivas_sba_dec_reconfigure( for ( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = ( int16_t )( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; } } @@ -829,7 +838,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ st_ivas->hCPE[0]->hCoreCoder[1] = NULL; - if( st_ivas->hSCE[0]->save_synth == NULL ) + if ( st_ivas->hSCE[0]->save_synth == NULL ) { if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) { @@ -956,6 +965,7 @@ ivas_error ivas_sba_dec_reconfigure( count_free( old_mem_hp20_out ); old_mem_hp20_out = NULL; } +#endif /*-----------------------------------------------------------------* * CLDFB instances @@ -1033,19 +1043,21 @@ ivas_error ivas_sba_dec_reconfigure( return error; #else - int16_t i, n; - int16_t sce_id, cpe_id; +#ifdef CORECODER_BITRATE_SWITCHING + int16_t i; + int16_t nchan_transport, nchan_transport_old; + int16_t nSCE_old, nCPE_old, nchan_hp20_old; +#else + int16_t i, n, sce_id, cpe_id; int16_t nchan_transport, nchan_transport_old; - int32_t sba_total_brate; int16_t nSCE_old, nCPE_old; +#endif AUDIO_CONFIG intern_config_old; - int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses; + int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; int16_t sba_dirac_stereo_flag_old; int32_t ivas_total_brate, last_ivas_total_brate; - DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; - hDecoderConfig = st_ivas->hDecoderConfig; error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -1057,7 +1069,10 @@ ivas_error ivas_sba_dec_reconfigure( ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); numCldfbAnalyses = 0; - sba_total_brate = ivas_total_brate; + +#ifdef CORECODER_BITRATE_SWITCHING + nchan_hp20_old = getNumChanSynthesis( st_ivas ); +#endif nSCE_old = st_ivas->nSCE; nCPE_old = st_ivas->nCPE; @@ -1066,7 +1081,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); st_ivas->nchan_transport = nchan_transport; /* renderer might have changed */ @@ -1081,8 +1096,7 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); - + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { return error; @@ -1091,10 +1105,11 @@ ivas_error ivas_sba_dec_reconfigure( else { int16_t sba_order_internal; + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); - 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_planar, + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) { return error; @@ -1140,6 +1155,16 @@ ivas_error ivas_sba_dec_reconfigure( * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ +#ifdef CORECODER_BITRATE_SWITCHING + ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + + ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); +#else + if ( nchan_transport == nchan_transport_old ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) @@ -1261,7 +1286,7 @@ ivas_error ivas_sba_dec_reconfigure( for ( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = ( int16_t )( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; } } @@ -1367,11 +1392,11 @@ ivas_error ivas_sba_dec_reconfigure( } for ( i = 0; i < n; i++ ) + { st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; old_mem_hp20_out[i] = NULL; } - for ( ; i < nchan_transport_old; i++ ) { count_free( old_mem_hp20_out[i] ); @@ -1382,6 +1407,7 @@ ivas_error ivas_sba_dec_reconfigure( old_mem_hp20_out = NULL; } } +#endif /*-----------------------------------------------------------------* * CLDFB instances @@ -1413,7 +1439,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1435,13 +1461,14 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } +#ifndef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* * Set CNA/CNG flags *-----------------------------------------------------------------*/ @@ -1487,6 +1514,7 @@ ivas_error ivas_sba_dec_reconfigure( return error; } } +#endif /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles @@ -1540,7 +1568,7 @@ static void debug_mode_dirac( #ifdef DEBUG_MODE_DIRAC_NOCORE for ( n = 0; n < nchan_transport; n++ ) { - sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, ( int16_t )( output_frame * 0.05 ) ); + sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, (int16_t) ( output_frame * 0.05 ) ); dbgread( tmp, sizeof( int16_t ), output_frame, file_name ); for ( i = 0; i < output_frame; i++ ) { @@ -1552,10 +1580,10 @@ static void debug_mode_dirac( { for ( i = 0; i < output_frame; i++ ) { - tmp[i] = ( int16_t )( output[n][i] + 0.5f ); + tmp[i] = (int16_t) ( output[n][i] + 0.5f ); } - sprintf( file_name, "./res/ivas_dirac_dec_%d.%d.pcm", n, ( int16_t )( output_frame * 0.05 ) ); + sprintf( file_name, "./res/ivas_dirac_dec_%d.%d.pcm", n, (int16_t) ( output_frame * 0.05 ) ); dbgwrite( tmp, sizeof( int16_t ), output_frame, 1, file_name ); } #endif diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 1f3611c8ca..7027e85e3d 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -187,11 +187,10 @@ ivas_error ivas_core_enc( * Pre-processing, incl. Decision matrix *---------------------------------------------------------------------*/ - if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, -#ifdef SBA_BITRATE_SWITCHING // VE2EF: dirty patch - review needed - ivas_format == SBA_FORMAT ? last_element_brate : element_brate, -#endif - input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) +#ifdef SBA_BITRATE_SWITCHING + if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) +#else + if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) #endif { return error; diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 419c5a008d..ded3df2235 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -57,9 +57,6 @@ ivas_error pre_proc_ivas( const int32_t element_brate, /* i : element bitrate */ #ifdef CORECODER_BITRATE_SWITCHING const int32_t last_element_brate, /* i : last element bitrate */ -#endif -#ifdef SBA_BITRATE_SWITCHING - const int32_t last_element_brate, /* i : last element bitrate */ #endif const int16_t input_frame, /* i : frame length */ float old_inp_12k8[], /* i/o: buffer of old input signal */ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 787e08bdd8..fc9a7aa36d 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -159,7 +159,7 @@ ivas_error ivas_dirac_enc_open( } } - hDirAC->no_col_avg_diff = ( int16_t )( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { hDirAC->buffer_intensity_real[i] = (float **) count_malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ); @@ -497,44 +497,14 @@ void ivas_dirac_enc_spar_delay_synchro( } #endif - for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) { - Encoder_State *sts[MCT_MAX_BLOCKS]; - int16_t i_chan = 0; - - /* initializations */ - for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]; - i_chan++; - } - - for ( int16_t cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ ) - { - sts[i_chan] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; - i_chan++; - } - } - - for ( ch_idx = 0; ch_idx < i_chan; ch_idx++ ) - { - mvr2r( sts[ch_idx]->input, st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); - } + mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); + mvr2r( st_ivas->hDirAC->sba_synchro_buffer[ch_idx], data_f[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); + mvr2r( tmp_buffer, &data_f[ch_idx][st_ivas->hDirAC->num_samples_synchro_delay], input_frame - st_ivas->hDirAC->num_samples_synchro_delay ); + mvr2r( &tmp_buffer[input_frame - st_ivas->hDirAC->num_samples_synchro_delay], st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); } -#endif - { - for ( ch_idx = 0; ch_idx < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) - { - mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); - mvr2r( st_ivas->hDirAC->sba_synchro_buffer[ch_idx], data_f[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); - mvr2r( tmp_buffer, &data_f[ch_idx][st_ivas->hDirAC->num_samples_synchro_delay], input_frame - st_ivas->hDirAC->num_samples_synchro_delay ); - mvr2r( &tmp_buffer[input_frame - st_ivas->hDirAC->num_samples_synchro_delay], st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay ); - } - } return; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 4556faa902..de93e9c8bf 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -217,6 +217,7 @@ ivas_error ivas_sba_enc_reconfigure( ) { int16_t nSCE_old, nCPE_old, nchan_transport_old; + #ifndef CORECODER_BITRATE_SWITCHING int16_t n, sce_id, cpe_id; Indice *ind_list_metadata; @@ -304,6 +305,8 @@ ivas_error ivas_sba_enc_reconfigure( /* initalize delay for SPAR/DirAC delay synchronization */ if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) { + int16_t n; + if ( st_ivas->hDirAC->num_samples_synchro_delay == 0 ) { st_ivas->hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); @@ -323,7 +326,7 @@ ivas_error ivas_sba_enc_reconfigure( } else { - for ( n = 0; n < IVAS_MAX_NUM_CH; n++ ) + for ( int16_t n = 0; n < IVAS_MAX_NUM_CH; n++ ) { if ( st_ivas->hDirAC->sba_synchro_buffer[n] != NULL ) { @@ -349,7 +352,11 @@ ivas_error ivas_sba_enc_reconfigure( #endif #ifdef CORECODER_BITRATE_SWITCHING - !!!!! + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); #else if ( st_ivas->nchan_transport == nchan_transport_old ) { @@ -385,10 +392,6 @@ ivas_error ivas_sba_enc_reconfigure( Indice *ind_list; int16_t nb_bits_tot, next_ind, last_ind; BSTR_ENC_HANDLE hBstr, hMetaData; -#ifdef IMPR_TC_SWITCHING_MEMORY - int16_t n_CoreCoder_save; - float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; -#endif ind_list = NULL; hBstr = NULL; @@ -419,36 +422,15 @@ ivas_error ivas_sba_enc_reconfigure( last_ind = hBstr->last_ind; ind_list_metadata = hMetaData->ind_list; -#ifdef IMPR_TC_SWITCHING_MEMORY - n_CoreCoder_save = min( st_ivas->nchan_transport, nchan_transport_old ); -#endif - /* destroy superfluous core coder elements */ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) { -#ifdef IMPR_TC_SWITCHING_MEMORY - /* save input audio buffers */ - if ( n_CoreCoder_save > sce_id ) - { - mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); - } -#endif destroy_sce_enc( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) { -#ifdef IMPR_TC_SWITCHING_MEMORY - /* save input audio buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( n_CoreCoder_save > cpe_id * CPE_CHANNELS + n ) - { - mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); - } - } -#endif destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); st_ivas->hCPE[cpe_id] = NULL; } @@ -486,14 +468,6 @@ ivas_error ivas_sba_enc_reconfigure( return error; } -#ifdef IMPR_TC_SWITCHING_MEMORY - /* propagate input audio buffers */ - if ( n_CoreCoder_save > sce_id ) - { - mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); - } -#endif - /* prepare bitstream buffers */ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; @@ -538,17 +512,6 @@ ivas_error ivas_sba_enc_reconfigure( return error; } -#ifdef IMPR_TC_SWITCHING_MEMORY - /* propagate input audio buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( n_CoreCoder_save > cpe_id * CPE_CHANNELS + n ) - { - mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory ); - } - } -#endif - /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 41a3913359..59faa5bf95 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -286,7 +286,7 @@ ivas_error ivas_spar_enc( error = IVAS_ERR_OK; hEncoderConfig = st_ivas->hEncoderConfig; -#ifdef IMPR_TC_SWITCHING_MEMORY +#ifdef SBA_BITRATE_SWITCHING // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->input ? /* check last sba_mode */ @@ -471,7 +471,7 @@ static ivas_error ivas_spar_enc_process( ivas_total_brate = hEncoderConfig->ivas_total_brate; num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; - input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); -- GitLab From 3bf40de17d58246fbb00b7fec423f5cc4ea7496e Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 27 Sep 2022 16:23:49 +0200 Subject: [PATCH 12/26] review + beautification --- lib_dec/ivas_sba_dec.c | 527 +++++----------------------------------- lib_enc/ivas_core_enc.c | 8 +- lib_enc/ivas_sba_enc.c | 4 - 3 files changed, 68 insertions(+), 471 deletions(-) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index d4235d25ff..f6e8e3af4a 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -451,47 +451,63 @@ ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { +#ifdef CORECODER_BITRATE_SWITCHING + int16_t i, nSCE_old, nCPE_old, nchan_transport_old, nchan_hp20_old; +#else + int16_t i, n, sce_id, cpe_id; + int16_t nchan_transport, nchan_transport_old; + int16_t nSCE_old, nCPE_old; +#endif #ifdef SBA_BITRATE_SWITCHING - int16_t i, n, output_frame; - int16_t sce_id, cpe_id; - int16_t nSCE_old, nCPE_old, nchan_transport_old; - int16_t nchan_hp20_old, nchan_hp20; - AUDIO_CONFIG intern_config_old; + int16_t output_frame; SBA_MODE sba_mode_old; - int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses_old, numCldfbSyntheses; +#endif + AUDIO_CONFIG intern_config_old; + int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; int16_t sba_dirac_stereo_flag_old; - float **old_mem_hp20_out; int32_t ivas_total_brate, last_ivas_total_brate; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; - hDecoderConfig = st_ivas->hDecoderConfig; - output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + hDecoderConfig = st_ivas->hDecoderConfig; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = hDecoderConfig->last_ivas_total_brate; + +#ifdef SBA_BITRATE_SWITCHING + output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#endif /*-----------------------------------------------------------------* * Set SBA high-level parameters * Save old SBA high-level parameters *-----------------------------------------------------------------*/ +#ifdef SBA_BITRATE_SWITCHING sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); st_ivas->sba_mode = sba_mode_old; +#endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifndef SBA_BITRATE_SWITCHING + numCldfbAnalyses = 0; +#endif +#ifdef CORECODER_BITRATE_SWITCHING nchan_hp20_old = getNumChanSynthesis( st_ivas ); +#endif nSCE_old = st_ivas->nSCE; nCPE_old = st_ivas->nCPE; nchan_transport_old = st_ivas->nchan_transport; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + +#ifdef CORECODER_BITRATE_SWITCHING st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); /*-----------------------------------------------------------------* * Allocate, initalize, and configure SBA handles @@ -541,6 +557,10 @@ ivas_error ivas_sba_dec_reconfigure( { st_ivas->element_mode_init = IVAS_CPE_MDCT; } +#else + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); + st_ivas->nchan_transport = nchan_transport; +#endif /*-----------------------------------------------------------------* * Renderer selection @@ -556,6 +576,7 @@ ivas_error ivas_sba_dec_reconfigure( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } +#ifdef SBA_BITRATE_SWITCHING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ @@ -585,11 +606,13 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } +#endif /*-----------------------------------------------------------------* * hDirAC decoder handle configuration *-----------------------------------------------------------------*/ +#ifdef SBA_BITRATE_SWITCHING if ( sba_mode_old != st_ivas->sba_mode ) // VE: TBD - possibly merge with the 'else if' branch below { if ( st_ivas->hDirAC != NULL ) @@ -649,454 +672,11 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } - - /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SCE/CPE/MCT handles - *-----------------------------------------------------------------*/ - -#ifdef CORECODER_BITRATE_SWITCHING - ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); - - /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ - - ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); #else - /* remove dummy CPE element for DFT stereo-like upmix */ - if ( sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) - { - st_ivas->hCPE[0]->hCoreCoder[0] = NULL; - st_ivas->hCPE[0]->hCoreCoder[1] = NULL; - destroy_cpe_dec( st_ivas->hCPE[0] ); - st_ivas->hCPE[0] = NULL; - - if ( st_ivas->hSCE[0] != NULL ) - { - count_free( st_ivas->hSCE[0]->save_synth ); - st_ivas->hSCE[0]->save_synth = NULL; - - count_free( st_ivas->hSCE[0]->save_hb_synth ); - st_ivas->hSCE[0]->save_hb_synth = NULL; - } - } - - if ( st_ivas->nchan_transport == nchan_transport_old ) - { - 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]->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() */ - } - - 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; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - - if ( st_ivas->nCPE > 1 ) - { - if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - else - { - int16_t nSCE_existing; - int16_t nCPE_existing; - - nSCE_existing = min( nSCE_old, st_ivas->nSCE ); - nCPE_existing = min( nCPE_old, st_ivas->nCPE ); - - // VE: TBV - try to reuse the CoreCoder - /* destroy superfluous core coder elements */ - for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) - { - destroy_sce_dec( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - - for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) - { - destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; - } - - if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) - { - ivas_mct_dec_close( &st_ivas->hMCT ); - } - - /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/ - if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) - { - count_free( st_ivas->hCPE[0]->hStereoMdct ); - st_ivas->hCPE[0]->hStereoMdct = NULL; - } - - for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) - { - st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; - 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() */ - } - for ( ; sce_id < st_ivas->nSCE; sce_id++ ) - { - if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) - { - if ( nCPE_old == 1 ) - { - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; - } - } - - if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) - { -#ifdef SBA_BITRATE_SWITCHING - if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) -#else - if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) -#endif - { - return error; - } - } - - /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ - if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) - { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); - } - - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f; - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - /* reset mct_chan_mode */ - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } - } - } - - /* create dummy CPE element for DFT stereo-like upmix */ - if ( st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) - { - if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) - { - return error; - } - - // VE: TBV - just reset for now - set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); - - st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ - st_ivas->hCPE[0]->hCoreCoder[1] = NULL; - - if ( st_ivas->hSCE[0]->save_synth == NULL ) - { - if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) ); - } - set_zero( st_ivas->hSCE[0]->save_synth, output_frame ); - } - - if ( st_ivas->hSCE[0]->save_hb_synth == NULL ) - { - if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) ); - } - set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame ); - } - } - - /*-----------------------------------------------------------------* - * Set CNA/CNG flags - *-----------------------------------------------------------------*/ - - if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) - { - /* skip as done in init function */ - } - else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) - { - st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; - st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; - } - else if ( st_ivas->nchan_transport == 2 ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; - } - } - else - { - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; - } - } - } - - /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ -#ifdef ALIGN_SID_SIZE - if ( last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 ) -#else - if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) -#endif - { - if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /*-----------------------------------------------------------------* - * HP20 memories - *-----------------------------------------------------------------*/ - - nchan_hp20 = getNumChanSynthesis( st_ivas ); - - if ( nchan_hp20 > nchan_hp20_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_out; - st_ivas->mem_hp20_out = NULL; - - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < nchan_hp20_old; i++ ) - { - st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; i < nchan_hp20; i++ ) - { - if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); - } - - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; - } - else if ( nchan_hp20 < nchan_hp20_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_out = st_ivas->mem_hp20_out; - st_ivas->mem_hp20_out = NULL; - - if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); - } - - for ( i = 0; i < nchan_hp20; i++ ) - { - st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i]; - old_mem_hp20_out[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < nchan_hp20_old; i++ ) - { - count_free( old_mem_hp20_out[i] ); - old_mem_hp20_out[i] = NULL; - } - - count_free( old_mem_hp20_out ); - old_mem_hp20_out = NULL; - } -#endif - - /*-----------------------------------------------------------------* - * CLDFB instances - *-----------------------------------------------------------------*/ - - ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - - /* special case, if there was one transport channel in the previous frame and more than one in the current frame, - remove the second CLDFB here, it was for CNA/CNG */ - if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) - { - deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); - st_ivas->cldfbAnaDec[1] = NULL; - numCldfbAnalyses_old--; - } - - /* CLDFB Analysis */ - /* resample CLDFB analysis instances */ - for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) - { - if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) - { - resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); - } - } - - if ( numCldfbAnalyses_old > numCldfbAnalyses ) - { - /* delete superfluous CLDFB analysis instances */ - for ( ; i < numCldfbAnalyses_old; i++ ) - { - deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); - st_ivas->cldfbAnaDec[i] = NULL; - } - } - else if ( numCldfbAnalyses_old < numCldfbAnalyses ) - { - /* create additional CLDFB analysis instances */ - for ( ; i < numCldfbAnalyses; i++ ) - { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - - /* CLDFB Synthesis */ - if ( numCldfbSyntheses_old > numCldfbSyntheses ) - { - /* delete superfluous CLDFB synthesis instances */ - for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) - { - deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); - st_ivas->cldfbSynDec[i] = NULL; - } - } - else if ( numCldfbSyntheses_old < numCldfbSyntheses ) - { - /* create additional CLDFB synthesis instances */ - for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) - { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - - /* CLDFB Interpolation weights */ - if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses ) ) - { - ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); - } - - return error; -#else -#ifdef CORECODER_BITRATE_SWITCHING - int16_t i; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old, nchan_hp20_old; -#else - int16_t i, n, sce_id, cpe_id; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old; -#endif - AUDIO_CONFIG intern_config_old; - int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; - int16_t sba_dirac_stereo_flag_old; - int32_t ivas_total_brate, last_ivas_total_brate; - ivas_error error; - - error = IVAS_ERR_OK; - - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; - - /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA and rendering handles - *-----------------------------------------------------------------*/ - - ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); - numCldfbAnalyses = 0; - -#ifdef CORECODER_BITRATE_SWITCHING - nchan_hp20_old = getNumChanSynthesis( st_ivas ); -#endif - - nSCE_old = st_ivas->nSCE; - nCPE_old = st_ivas->nCPE; - nchan_transport_old = st_ivas->nchan_transport; - sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; - - 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, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->sba_mode ); - st_ivas->nchan_transport = nchan_transport; - - /* renderer might have changed */ - intern_config_old = st_ivas->intern_config; - ivas_renderer_select( st_ivas ); - - /* side effect of the renderer selection can be a changed internal config */ - if ( st_ivas->intern_config != intern_config_old ) - { - ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - } - if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { return error; @@ -1107,7 +687,7 @@ ivas_error ivas_sba_dec_reconfigure( int16_t sba_order_internal; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + ivas_spar_config( hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) @@ -1117,9 +697,9 @@ ivas_error ivas_sba_dec_reconfigure( } #ifdef ALIGN_SID_SIZE - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) #else - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_4k4 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) #endif { if ( st_ivas->hDirAC != NULL ) @@ -1150,6 +730,7 @@ ivas_error ivas_sba_dec_reconfigure( vbap_free_data( &( st_ivas->hVBAPdata ) ); } } +#endif /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles @@ -1417,13 +998,24 @@ ivas_error ivas_sba_dec_reconfigure( /* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ - if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) + if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) { deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); st_ivas->cldfbAnaDec[1] = NULL; numCldfbAnalyses_old--; } +#ifdef SBA_BITRATE_SWITCHING + /* resample CLDFB analysis instances */ + for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) + { + if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) + { + resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); + } + } +#endif + /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { @@ -1439,7 +1031,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -1461,13 +1053,21 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } +#ifdef SBA_BITRATE_SWITCHING + /* CLDFB Interpolation weights */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses ) ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } +#endif + #ifndef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* * Set CNA/CNG flags @@ -1516,6 +1116,7 @@ ivas_error ivas_sba_dec_reconfigure( } #endif +#ifndef SBA_BITRATE_SWITCHING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ @@ -1545,9 +1146,9 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } +#endif return error; -#endif } diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 7027e85e3d..3f9cb84b51 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -104,7 +104,7 @@ ivas_error ivas_core_enc( int16_t unbits[CPE_CHANNELS]; float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t last_element_mode, tdm_Pitch_reuse_flag; -#ifdef SBA_BITRATE_SWITCHING +#ifdef CORECODER_BITRATE_SWITCHING int32_t element_brate, last_element_brate, input_Fs; #else int32_t element_brate, input_Fs; @@ -127,7 +127,7 @@ ivas_error ivas_core_enc( hStereoTD = NULL; hStereoICBWE = NULL; element_brate = hSCE->element_brate; -#ifdef SBA_BITRATE_SWITCHING +#ifdef CORECODER_BITRATE_SWITCHING last_element_brate = hSCE->last_element_brate; #endif last_element_mode = IVAS_SCE; @@ -144,7 +144,7 @@ ivas_error ivas_core_enc( sts = hCPE->hCoreCoder; hStereoICBWE = hCPE->hStereoICBWE; element_brate = hCPE->element_brate; -#ifdef SBA_BITRATE_SWITCHING +#ifdef CORECODER_BITRATE_SWITCHING last_element_brate = hCPE->last_element_brate; #endif last_element_mode = hCPE->last_element_mode; @@ -187,7 +187,7 @@ ivas_error ivas_core_enc( * Pre-processing, incl. Decision matrix *---------------------------------------------------------------------*/ -#ifdef SBA_BITRATE_SWITCHING +#ifdef CORECODER_BITRATE_SWITCHING if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) #else if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index de93e9c8bf..63ab55b71d 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -569,11 +569,7 @@ ivas_error ivas_sba_enc_reconfigure( } else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) { -#ifdef SBA_BITRATE_SWITCHING - if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) -#else if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nCPE != nCPE_old ) ) != IVAS_ERR_OK ) -#endif { return error; } -- GitLab From 7dc50fddf95f4247a1a91caf607aab5f8c678715 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 4 Oct 2022 16:40:40 +0200 Subject: [PATCH 13/26] reactivate main switches + few fixes --- lib_com/options.h | 6 +++--- lib_dec/ivas_dirac_dec.c | 4 ++-- lib_dec/ivas_sba_dec.c | 18 +++++------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 90ed898838..98988c8e01 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,9 +150,9 @@ #define ALIGN_SID_SIZE /* Issue 111: make all DTX modes use one SID frame bitrate (5.2 kbps) */ #define FIX_135_MDCT_STEREO_MODE_UNINITIALIZED /* Issue 135: fix uninitialized value usage in SBA MDCT-Stereo core with PLC */ #define FIX_CONTROLLABLE_SID_UPDATE_RATE /* Issue 117: fix controllable SID update rate mechanism */ -//#define FIX_DIRAC_CHANNELS /* Issue 71: lower number of DirAC analysis channels */ -//#define FIX_CREND_CHANNELS /* Issue 71: fix number of Crend channels */ -//#define HARMONIZE_SBA_NCHAN_TRANSPORT /* harmonize setting of number of transport channels in SBA */ +#define FIX_DIRAC_CHANNELS /* Issue 71: lower number of DirAC analysis channels */ +#define FIX_CREND_CHANNELS /* Issue 71: fix number of Crend channels */ +#define HARMONIZE_SBA_NCHAN_TRANSPORT /* harmonize setting of number of transport channels in SBA */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index db44e1788a..8683d31bf0 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -126,7 +126,7 @@ ivas_error ivas_dirac_dec_open( *-------------------------------------------------------------------------*/ ivas_error ivas_dirac_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ #ifdef SBA_BITRATE_SWITCHING const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ #else @@ -212,7 +212,7 @@ ivas_error ivas_dirac_dec_config( { int16_t tmp1, tmp2, tmp3; #ifdef HARMONIZE_SBA_NCHAN_TRANSPORT - ivas_sba_config( st_ivas->hDecoderConfig->last_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 ); #else ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3, SBA_MODE_DIRAC ); #endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 77c2201929..4c6007223f 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -549,7 +549,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hSpar = NULL; #ifdef HARMONIZE_SBA_NCHAN_TRANSPORT - 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_planar, -1 ) ) != IVAS_ERR_OK ) + 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 ) #else 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_planar, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) #endif @@ -561,10 +561,7 @@ ivas_error ivas_sba_dec_reconfigure( } else { - int16_t sba_order_internal; - -#if 1 - int16_t num_channels_internal; + int16_t sba_order_internal, num_channels_internal; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); @@ -576,13 +573,10 @@ ivas_error ivas_sba_dec_reconfigure( #endif { - //st_ivas->nchan_transport = ivas_get_spar_num_TCs( ivas_total_brate, sba_order_internal ); - // VE: dirty patch -> reconfiguration of SPAR modules should be used instead !! IVAS_FB_CFG *fb_cfg; int16_t active_w_mixing; -#if 1 /* MD handle */ ivas_spar_md_dec_close( &st_ivas->hSpar->hMdDec ); @@ -601,7 +595,7 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } -#endif + /* FB mixer handle */ ivas_FB_mixer_close( &st_ivas->hSpar->hFbMixer, hDecoderConfig->output_Fs ); @@ -637,7 +631,7 @@ ivas_error ivas_sba_dec_reconfigure( } st_ivas->hSpar->i_subframe = 0; } -#endif + if ( st_ivas->hSpar == NULL ) { if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -651,7 +645,6 @@ ivas_error ivas_sba_dec_reconfigure( sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); -#if 1 if ( st_ivas->hDirAC == NULL ) { if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -664,10 +657,9 @@ ivas_error ivas_sba_dec_reconfigure( mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; -#endif #ifdef HARMONIZE_SBA_NCHAN_TRANSPORT - 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_planar, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + 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 ) #else 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_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) -- GitLab From d63cde2dcb0246901713f121fd2d9e6fca96fe8b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 4 Oct 2022 16:42:34 +0200 Subject: [PATCH 14/26] correct switch name --- lib_dec/ivas_sba_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 4c6007223f..7558369034 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -535,7 +535,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); -#ifdef CORECODER_BITRATE_SWITCHING +#ifdef SBA_BITRATE_SWITCHING st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); -- GitLab From 5000adfe836e62bfe3cc36d0391cfd3a3813ec62 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 14 Oct 2022 13:30:38 +0200 Subject: [PATCH 15/26] fix SBA constant bitrate DTX crash --- lib_dec/ivas_sba_dec.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index f33d8e4141..4517f1ceab 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -493,7 +493,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hSpar->i_subframe = 0; } - if ( st_ivas->hSpar == NULL ) + if ( st_ivas->hSpar == NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) { if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -506,7 +506,7 @@ ivas_error ivas_sba_dec_reconfigure( sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); - if ( st_ivas->hDirAC == NULL ) + if ( st_ivas->hDirAC == NULL && st_ivas->sba_mode == SBA_MODE_DIRAC ) { if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -514,10 +514,13 @@ ivas_error ivas_sba_dec_reconfigure( } } - ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); - mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); - st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } 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 ) { @@ -535,10 +538,9 @@ ivas_error ivas_sba_dec_reconfigure( } #else - ivas_sba_config( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); - - st_ivas->nchan_transport = nchan_transport; + 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 + /*-----------------------------------------------------------------* * Renderer selection *-----------------------------------------------------------------*/ -- GitLab From c151888bd81c8c3e36f5054704e7c5050de73789 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 14 Oct 2022 19:28:04 +0200 Subject: [PATCH 16/26] fix merge issue --- lib_dec/dec_tcx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 2934a2309c..8f6ee52fed 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1559,7 +1559,7 @@ void decoder_tcx_tns( #ifndef FIX_I13_TCX_TNS_ISSUE tcx5TnsUngrouping( L_frameTCX >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC ); #else - if ( st->element_mode == EVS_MONO ) /* TBC: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */ + if ( st->element_mode == EVS_MONO || L_spec < L_frameTCX ) /* TBC: this is temporary to maintain EVS BE, this is a bug and should be fixed also for EVS (see issue 13) */ { tcx5TnsUngrouping( L_frameTCX >> 1, hTcxCfg->tnsConfig[0][0].iFilterBorders[0] >> 1, x, DEC ); } -- GitLab From 939dfcc7558cde458e7c2c6ec37ecf13b4023dac Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 18 Oct 2022 12:56:33 +0200 Subject: [PATCH 17/26] harmonize 'nchan' terminology --- lib_com/ivas_cov_smooth.c | 22 +- lib_com/ivas_fb_mixer.c | 84 ++++---- lib_com/ivas_prot.h | 30 +-- lib_com/ivas_spar_com.c | 158 +++++++------- lib_com/ivas_stat_com.h | 6 +- lib_dec/ivas_dirac_dec.c | 30 +-- lib_dec/ivas_dirac_decorr_dec.c | 34 +-- lib_dec/ivas_dirac_output_synthesis_cov.c | 30 +-- lib_dec/ivas_dirac_output_synthesis_dec.c | 30 +-- lib_dec/ivas_init_dec.c | 8 +- lib_dec/ivas_ism_param_dec.c | 4 +- lib_dec/ivas_limiter.c | 26 +-- lib_dec/ivas_mc_param_dec.c | 3 +- lib_dec/ivas_out_setup_conversion.c | 14 +- lib_dec/ivas_rom_dec.c | 2 +- lib_dec/ivas_sba_rendering.c | 36 ++-- lib_dec/ivas_spar_decoder.c | 67 +++--- lib_dec/ivas_spar_md_dec.c | 192 ++++++++--------- lib_dec/ivas_stat_dec.h | 36 ++-- lib_dec/ivas_td_decorr.c | 22 +- lib_dec/jbm_pcmdsp_apa.c | 48 ++--- lib_dec/jbm_pcmdsp_apa.h | 4 +- lib_enc/ivas_enc_cov_handler.c | 40 ++-- lib_enc/ivas_mc_param_enc.c | 100 ++++----- lib_enc/ivas_spar_encoder.c | 19 +- lib_enc/ivas_spar_md_enc.c | 196 +++++++++--------- lib_enc/ivas_stat_enc.h | 2 +- .../unit_tests/crend/ivas_crend_utest_utils.c | 24 +-- 28 files changed, 632 insertions(+), 635 deletions(-) diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 4584303293..49a833843c 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -180,7 +180,7 @@ static void ivas_compute_smooth_cov( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t transient_det #endif ) @@ -188,7 +188,7 @@ static void ivas_compute_smooth_cov( int16_t i, j, k; int16_t prev_idx = hCovState->prior_bank_idx; #ifndef SBA_SPAR_HARM - int16_t num_ch = pIn_buf->num_ch; + int16_t nchan = pIn_buf->nchan; #endif float factor = 0; @@ -200,7 +200,7 @@ static void ivas_compute_smooth_cov( if ( prev_idx == -1 || pIn_buf->reset_cov == 1 ) #endif { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -210,9 +210,9 @@ static void ivas_compute_smooth_cov( } else if ( prev_idx == 0 ) { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( i == j ) { @@ -253,26 +253,26 @@ void ivas_cov_smooth_process( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t transient_det #endif ) { int16_t i, j; #ifndef SBA_SPAR_HARM - int16_t num_ch = pIn_buf->num_ch; + int16_t nchan = pIn_buf->nchan; #endif int16_t num_bands = end_band - start_band; #ifdef SBA_SPAR_HARM - ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det ); + ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, nchan, transient_det ); #else - ivas_compute_smooth_cov( hCovState, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, num_ch, transient_det ); + ivas_compute_smooth_cov( hCovState, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, nchan, transient_det ); #endif - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { #ifdef SBA_SPAR_HARM mvr2r( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real[i][j][start_band], num_bands ); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 53ad90d01f..8419fea31f 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -102,8 +102,8 @@ ivas_error ivas_fb_set_cfg( IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ const int16_t ivas_format, /* i : IVAS format */ const SBA_MODE sba_mode, /* i : SBA mode */ - const int16_t num_in_chans, /* i : number of FB input channels */ - const int16_t num_out_chans, /* i : number of FB output channels*/ + const int16_t nchan_inp, /* i : number of FB input channels */ + const int16_t nchan_out, /* i : number of FB output channels*/ const int16_t active_w_mixing, /* i : active_w_mixing flag */ const int32_t sampling_rate /* i : sampling rate */ ) @@ -115,8 +115,8 @@ ivas_error ivas_fb_set_cfg( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer config" ); } - pFb_cfg->num_in_chans = num_in_chans; - pFb_cfg->num_out_chans = num_out_chans; + pFb_cfg->nchan_inp = nchan_inp; + pFb_cfg->nchan_out = nchan_out; pFb_cfg->pcm_offset = 0; /* note: in SPAR decoder, this parameter is overwritten later */ pFb_cfg->active_w_mixing = active_w_mixing; @@ -179,7 +179,7 @@ ivas_error ivas_FB_mixer_open( { IVAS_FB_MIXER_HANDLE hFbMixer; int16_t i, j, frame_len, num_bands; - int16_t num_chs_alloc; + int16_t nchan_alloc; ivas_error error; error = IVAS_ERR_OK; @@ -198,20 +198,20 @@ ivas_error ivas_FB_mixer_open( if ( fb_cfg->active_w_mixing == -1 ) { - num_chs_alloc = 0; + nchan_alloc = 0; } else if ( fb_cfg->active_w_mixing ) { - num_chs_alloc = fb_cfg->num_in_chans; + nchan_alloc = fb_cfg->nchan_inp; } else { - num_chs_alloc = fb_cfg->num_out_chans; + nchan_alloc = fb_cfg->nchan_out; } - for ( i = 0; i < num_chs_alloc; i++ ) + for ( i = 0; i < nchan_alloc; i++ ) { - if ( fb_cfg->num_out_chans == 0 ) + if ( fb_cfg->nchan_out == 0 ) { hFbMixer->ppFilterbank_inFR_re[i] = NULL; hFbMixer->ppFilterbank_inFR_im[i] = NULL; @@ -234,13 +234,13 @@ ivas_error ivas_FB_mixer_open( if ( fb_cfg->active_w_mixing == -1 ) { - num_chs_alloc = 0; + nchan_alloc = 0; } else { - num_chs_alloc = fb_cfg->num_in_chans; + nchan_alloc = fb_cfg->nchan_inp; } - for ( i = 0; i < num_chs_alloc; i++ ) + for ( i = 0; i < nchan_alloc; i++ ) { if ( ( hFbMixer->ppFilterbank_prior_input[i] = (float *) count_malloc( sizeof( float ) * fb_cfg->prior_input_length ) ) == NULL ) { @@ -249,17 +249,17 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->ppFilterbank_prior_input[i], 0, fb_cfg->prior_input_length ); } - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->nchan_out > 0 ) ) { float *pTemp_mem; - if ( ( pTemp_mem = (float *) count_malloc( sizeof( float ) * fb_cfg->num_out_chans * fb_cfg->num_in_chans * IVAS_MAX_NUM_BANDS ) ) == NULL ) + if ( ( pTemp_mem = (float *) count_malloc( sizeof( float ) * fb_cfg->nchan_out * fb_cfg->nchan_inp * IVAS_MAX_NUM_BANDS ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer" ); } - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < fb_cfg->nchan_out; i++ ) { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < fb_cfg->nchan_inp; j++ ) { hFbMixer->prior_mixer[i][j] = pTemp_mem; pTemp_mem += IVAS_MAX_NUM_BANDS; @@ -268,7 +268,7 @@ ivas_error ivas_FB_mixer_open( } } - if ( fb_cfg->num_out_chans > 0 ) + if ( fb_cfg->nchan_out > 0 ) { const int16_t *pActive_bins_per_band, *pActive_bins_per_band_abs, *pStart_offset, *pStart_offset_abs; @@ -372,18 +372,18 @@ void ivas_FB_mixer_close( } else if ( fb_cfg->active_w_mixing ) { - num_chs_alloc = fb_cfg->num_in_chans; + num_chs_alloc = fb_cfg->nchan_inp; } else { - num_chs_alloc = fb_cfg->num_out_chans; + num_chs_alloc = fb_cfg->nchan_out; } if ( hFbMixer != NULL ) { for ( i = 0; i < num_chs_alloc; i++ ) { - if ( fb_cfg->num_out_chans > 0 ) + if ( fb_cfg->nchan_out > 0 ) { j = fb_cfg->remix_order[i]; @@ -401,7 +401,7 @@ void ivas_FB_mixer_close( } else { - num_chs_alloc = fb_cfg->num_in_chans; + num_chs_alloc = fb_cfg->nchan_inp; } for ( i = 0; i < num_chs_alloc; i++ ) { @@ -409,13 +409,13 @@ void ivas_FB_mixer_close( hFbMixer->ppFilterbank_prior_input[i] = NULL; } - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->nchan_out > 0 ) ) { count_free( hFbMixer->prior_mixer[0][0] ); hFbMixer->prior_mixer[0][0] = NULL; } - if ( fb_cfg->num_out_chans > 0 ) + if ( fb_cfg->nchan_out > 0 ) { num_bands = hFbMixer->pFb->filterbank_num_bands; @@ -483,14 +483,14 @@ void ivas_fb_mixer_pcm_ingest( if ( fb_cfg->active_w_mixing ) { - num_chs_ingest = fb_cfg->num_in_chans; + num_chs_ingest = fb_cfg->nchan_inp; } else { - num_chs_ingest = fb_cfg->num_out_chans; + num_chs_ingest = fb_cfg->nchan_out; } - for ( i = 0; i < fb_cfg->num_in_chans; i++ ) + for ( i = 0; i < fb_cfg->nchan_inp; i++ ) { mvr2r( &hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len ); mvr2r( pcm_in[i], &ppOut_pcm[i][frame_len], frame_len ); @@ -519,7 +519,7 @@ void ivas_fb_mixer_update_prior_input( { int16_t i; - for ( i = 0; i < hFbMixer->fb_cfg->num_in_chans; i++ ) + for ( i = 0; i < hFbMixer->fb_cfg->nchan_inp; i++ ) { mvr2r( &hFbMixer->ppFilterbank_prior_input[i][length], hFbMixer->ppFilterbank_prior_input[i], hFbMixer->fb_cfg->prior_input_length - length ); mvr2r( pcm_in[i], &hFbMixer->ppFilterbank_prior_input[i][hFbMixer->fb_cfg->prior_input_length - length], length ); @@ -556,7 +556,7 @@ void ivas_fb_mixer_get_windowed_fr( rev_offset = (int16_t) ( 2 * mdft_len - hFbMixer->ana_window_offset ); set_zero( fr_in_block, offset ); - for ( ch_idx = 0; ch_idx < hFbMixer->fb_cfg->num_in_chans; ch_idx++ ) + for ( ch_idx = 0; ch_idx < hFbMixer->fb_cfg->nchan_inp; ch_idx++ ) { mvr2r( &hFbMixer->ppFilterbank_prior_input[ch_idx][offset + hFbMixer->fb_cfg->windowed_fr_offset], &fr_in_block[offset], n_old_samples - offset ); mvr2r( pcm_in[ch_idx], &fr_in_block[n_old_samples], n_new_samples ); @@ -657,7 +657,7 @@ void ivas_fb_mixer_process( pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; - for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->nchan_out; ch++ ) { /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ for ( hist = 0; hist < 2; hist++ ) @@ -665,7 +665,7 @@ void ivas_fb_mixer_process( set_zero( pOut_fr_re, frame_len ); set_zero( pOut_fr_im, frame_len ); - for ( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < hFbMixer->fb_cfg->nchan_inp; j++ ) { if ( in_out_mixer_map[ch][j] != 0 ) { @@ -739,9 +739,9 @@ void ivas_fb_mixer_get_in_out_mapping( { if ( fb_cfg->active_w_mixing ) { - for ( i = 0; i < fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < fb_cfg->nchan_out; i++ ) { - for ( j = 0; j < fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < fb_cfg->nchan_inp; j++ ) { in_out_mixer_map[i][j] = 1; } @@ -750,7 +750,7 @@ void ivas_fb_mixer_get_in_out_mapping( else { in_out_mixer_map[0][0] = 1; /* W depends on only W input*/ - for ( i = 1; i < fb_cfg->num_out_chans; i++ ) + for ( i = 1; i < fb_cfg->nchan_out; i++ ) { in_out_mixer_map[i][0] = 1; in_out_mixer_map[i][order[i]] = 1; @@ -768,7 +768,7 @@ void ivas_fb_mixer_get_in_out_mapping( if ( nchan_transport == 1 ) { /* no cross predicitons in 1 ch dmx*/ - for ( i = nchan_transport; i < fb_cfg->num_out_chans; i++ ) + for ( i = nchan_transport; i < fb_cfg->nchan_out; i++ ) { in_out_mixer_map[order[i]][0] = 1; in_out_mixer_map[order[i]][i] = 1; @@ -777,7 +777,7 @@ void ivas_fb_mixer_get_in_out_mapping( else { /* handle the cross predictions and decorrelation*/ - for ( i = nchan_transport; i < fb_cfg->num_out_chans; i++ ) + for ( i = nchan_transport; i < fb_cfg->nchan_out; i++ ) { for ( j = 0; j < nchan_transport; j++ ) { @@ -820,8 +820,8 @@ static int16_t ivas_calculate_abs_fr( float short_stride_nrg = 0.0f; float cldfb_nrg = 0.0f; int16_t short_stride = pFb->fb_bin_to_band.short_stride; - const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); - const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); + const int16_t num_bins_per_short_stride_bin = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); + const int16_t num_bins_per_cldfb_band = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); float short_stride_max_per_spar_band = 1e-9f; /*loop over all stored Filter Bank Response MDFT coefficients*/ @@ -1038,11 +1038,11 @@ static ivas_error ivas_filterbank_setup( error = IVAS_ERR_OK; - 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 ); + set_s( hFbMixer->first_frame, 1, pCfg->nchan_out ); + set_s( hFbMixer->first_frame + pCfg->nchan_out, 0, IVAS_SPAR_MAX_CH - pCfg->nchan_out ); - if ( pCfg->num_out_chans > 0 ) + if ( pCfg->nchan_out > 0 ) { hFbMixer->pFb->filterbank_num_bands = ivas_get_num_bands( sampling_rate ); @@ -1078,7 +1078,7 @@ static ivas_error ivas_filterbank_setup( return error; } - if ( pCfg->num_out_chans > 0 ) + if ( pCfg->nchan_out > 0 ) { ivas_filterbank_t *pFb = hFbMixer->pFb; int16_t offset = 0; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 84450e89a0..7e280a082f 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -654,7 +654,7 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( /*! r: limiter struct handle */ IVAS_LIMITER_HANDLE ivas_limiter_open( - const int16_t num_channels, /* i : number of I/O channels */ + const int16_t nchan, /* i : number of I/O channels */ const int32_t sampling_rate /* i : sampling rate for processing */ ); @@ -666,7 +666,7 @@ void ivas_limiter_dec ( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], /* i/o: input/output buffer */ - const int16_t num_channels, /* i : number of channels to be processed */ + const int16_t nchan, /* i : number of channels to be processed */ const int16_t output_frame, /* i : number of samples per channel in the buffer */ const int16_t BER_detect /* i : BER detect flag */ ); @@ -3115,7 +3115,7 @@ void ivas_sba_getTCs( ivas_error ivas_sba_linear_renderer( float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : number of input ambisonics channels */ + const int16_t nchan_inp, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup, /* i : output format setup */ const float hoa_dec_mtx[] /* i : HOA decoding mtx */ @@ -3311,7 +3311,7 @@ void computeDiffuseness( ); void ivas_dirac_dec_onset_detection_open( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t max_band_decorr, DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params, @@ -3340,7 +3340,7 @@ void ivas_dirac_dec_decorr_open( void ivas_dirac_dec_decorr_process( const int16_t num_freq_bands, - int16_t num_channels, + int16_t nchan, const int16_t num_protos_diff, const DIRAC_SYNTHESIS_CONFIG synthesisConf, const int16_t nchan_transport, /* i : number of transport channels */ @@ -3635,14 +3635,14 @@ void ivas_dirac_dec_output_synthesis_cov_open( const int16_t interp_length, /* i : length for interpolating the mixing matrices in time slots */ const int16_t num_param_bands, /* i : number of parameter bands */ const int16_t num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ - const int16_t nchan_in, /* i : number of input (transport) channels */ + const int16_t nchan_inp, /* i : number of input (transport) channels */ const int16_t nchan_out, /* i : number of output channels */ const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ); void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ - const int16_t nchan_in, /* i : number of input (tranport) channels */ + const int16_t nchan_inp, /* i : number of input (tranport) channels */ const int16_t nchan_out, /* i : number of output channels */ const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ @@ -3659,7 +3659,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( float cx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ float cx_imag[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ - const int16_t nchan_in, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t idx_slot /* i : index of the slot to be added to the input covariance */ ); @@ -3934,7 +3934,7 @@ void ivas_compute_spar_params( const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, - const int16_t num_ch, + const int16_t nchan, const int16_t bands_bw, const int16_t active_w, ivas_spar_md_com_cfg *hSparCfg, @@ -3959,7 +3959,7 @@ void ivas_calc_c_p_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, const int16_t dtx_vad, @@ -3985,7 +3985,7 @@ void ivas_get_spar_md_from_dirac( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ); void ivas_spar_md_dec_close( @@ -4005,7 +4005,7 @@ void ivas_spar_get_parameters( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ); void ivas_spar_md_dec_process( @@ -4102,7 +4102,7 @@ void ivas_cov_smooth_process( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t transient_det #endif ); @@ -5158,8 +5158,8 @@ ivas_error ivas_fb_set_cfg( IVAS_FB_CFG **pFb_cfg_out, /* o : FB config. handle */ const int16_t ivas_format, /* i : IVAS format */ const SBA_MODE sba_mode, /* i : SBA mode */ - const int16_t num_in_chans, /* i : number of FB input channels */ - const int16_t num_out_chans, /* i : number of FB output channels */ + const int16_t nchan_inp, /* i : number of FB input channels */ + const int16_t nchan_out, /* i : number of FB output channels */ const int16_t active_w_mixing, /* i : active_w_mixing flag */ const int32_t sampling_Fs /* i : sampling rate */ ); diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index a93326ec9c..b9abd5f778 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -80,9 +80,9 @@ static void ivas_get_pred_coeffs( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SP static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band ); -static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, float *pWscale ); +static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t nchan, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, float *pWscale ); -static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); +static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); static int16_t ivas_is_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim ); @@ -641,7 +641,7 @@ static void ivas_get_Wscaling_factor( const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, - const int16_t num_ch, + const int16_t nchan, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, @@ -668,11 +668,11 @@ static void ivas_get_Wscaling_factor( { float Gw_sq, g_sq = 0; - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, pNum_dmx[b * bands_bw], b, postpred_cov_re ); + ivas_calc_post_pred_per_band( cov_real, mixer_mat, nchan, pNum_dmx[b * bands_bw], b, postpred_cov_re ); Gw_sq = cov_real[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS ); - for ( ch = 0; ch < num_ch - 1; ch++ ) + for ( ch = 0; ch < nchan - 1; ch++ ) { IVAS_CALCULATE_SQ_ABS_N( pred_coeffs_re[ch][b], abs_val ); @@ -864,7 +864,7 @@ static void ivas_reorder_array( static void ivas_calc_post_pred_per_band( float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) @@ -875,29 +875,29 @@ static void ivas_calc_post_pred_per_band( float tmp_re; // NOTE: What is this doing? - if ( num_dmx != num_ch ) + if ( num_dmx != nchan ) { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; } } } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - set_zero( postpred_cov_re[i], num_ch ); + set_zero( postpred_cov_re[i], nchan ); } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* nchan x nchan mult */ + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { temp_mat[i][j] = 0; - for ( k = 0; k < num_ch; k++ ) + for ( k = 0; k < nchan; k++ ) { IVAS_RMULT_FLOAT( cov_real[i][k][band_idx], dmx_mat_conj[k][j], tmp_re ); temp_mat[i][j] += tmp_re; @@ -905,12 +905,12 @@ static void ivas_calc_post_pred_per_band( } } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* nchan x nchan mult */ + for ( i = 0; i < nchan; i++ ) { - for ( j = i; j < num_ch; j++ ) + for ( j = i; j < nchan; j++ ) { - for ( k = 0; k < num_ch; k++ ) + for ( k = 0; k < nchan; k++ ) { IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); @@ -919,7 +919,7 @@ static void ivas_calc_post_pred_per_band( } } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { for ( j = 0; j < i; j++ ) { @@ -928,9 +928,9 @@ static void ivas_calc_post_pred_per_band( } #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Postpred cov: (band %d)\n", band_idx); - for (i = 0; i < num_ch; i++) + for (i = 0; i < nchan; i++) { - for (j = 0; j < num_ch; j++) + for (j = 0; j < nchan; j++) { fprintf(stderr, "%f, ", postpred_cov_re[i][j]); } @@ -953,7 +953,7 @@ static void ivas_calc_p_coeffs_per_band( ivas_spar_md_t *pSparMd, const int16_t i_ts, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, + const int16_t nchan, const int16_t dtx_vad, const int16_t num_dmx, const int16_t band_idx ) @@ -970,7 +970,7 @@ static void ivas_calc_p_coeffs_per_band( b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS; - if ( num_dmx != num_ch ) + if ( num_dmx != nchan ) { set_zero( pSparMd->band_coeffs[b_ts_idx].P_re, IVAS_SPAR_MAX_CH - 1 ); for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) @@ -978,9 +978,9 @@ static void ivas_calc_p_coeffs_per_band( set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); } - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + for ( j = num_dmx; j < nchan; j++ ) { cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; } @@ -1043,7 +1043,7 @@ static void ivas_calc_p_coeffs_per_band( /* Step 1: Multiply C * cov_dd * C' */ float re1[3], re; - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { set_f( re1, 0, 3 ); for ( m = 0; m < num_dmx - 1; m++ ) @@ -1054,7 +1054,7 @@ static void ivas_calc_p_coeffs_per_band( re1[m] += re; } } - for ( j = 0; j < num_ch - num_dmx; j++ ) + for ( j = 0; j < nchan - num_dmx; j++ ) { for ( m = 0; m < num_dmx - 1; m++ ) { @@ -1065,9 +1065,9 @@ static void ivas_calc_p_coeffs_per_band( } /* Step 2: cov_uu - recon_uu */ - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { - for ( j = 0; j < num_ch - num_dmx; j++ ) + for ( j = 0; j < nchan - num_dmx; j++ ) { cov_uu_re[i][j] -= recon_uu_re[i][j]; } @@ -1084,7 +1084,7 @@ static void ivas_calc_p_coeffs_per_band( trace = 0.0f; - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { float tmp_out; IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); @@ -1096,9 +1096,9 @@ static void ivas_calc_p_coeffs_per_band( factor = 1 / factor; /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + for ( j = num_dmx; j < nchan; j++ ) { if ( i == j ) { @@ -1114,16 +1114,16 @@ static void ivas_calc_p_coeffs_per_band( } /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ } /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + for ( j = num_dmx; j < nchan; j++ ) { if ( i == j ) { @@ -1147,7 +1147,7 @@ static void ivas_calc_c_coeffs_per_band( ivas_spar_md_t *pSparMd, const int16_t i_ts, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, const int16_t dtx_vad ) @@ -1171,7 +1171,7 @@ static void ivas_calc_c_coeffs_per_band( return; } - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { for ( j = 1; j < num_dmx; j++ ) { @@ -1213,7 +1213,7 @@ static void ivas_calc_c_coeffs_per_band( else { ivas_calc_mat_inv( cov_dd_re, num_dmx - 1, cov_dd_re_inv ); - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { for ( j = 0; j < num_dmx - 1; j++ ) { @@ -1243,7 +1243,7 @@ void ivas_calc_c_p_coeffs( float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, - const int16_t num_ch, + const int16_t nchan, const int16_t num_dmx, const int16_t band_idx, const int16_t dtx_vad, @@ -1253,18 +1253,18 @@ void ivas_calc_c_p_coeffs( int16_t i, j; float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - if ( num_dmx != num_ch ) + if ( num_dmx != nchan ) { - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, num_dmx, band_idx, postpred_cov_re ); + ivas_calc_post_pred_per_band( cov_real, mixer_mat, nchan, num_dmx, band_idx, postpred_cov_re ); if ( num_dmx != 1 ) { - ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); + ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, nchan, num_dmx, band_idx, dtx_vad ); } if ( planarCP ) { - for ( i = 0; i < num_ch - num_dmx; i++ ) + for ( i = 0; i < nchan - num_dmx; i++ ) { if ( !keep_planar[i] ) { @@ -1278,12 +1278,12 @@ void ivas_calc_c_p_coeffs( if ( compute_p_flag == 1 ) { - ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); + ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, nchan, dtx_vad, num_dmx, band_idx ); } if ( planarCP ) { - for ( i = num_dmx; i < num_ch; i++ ) + for ( i = num_dmx; i < nchan; i++ ) { if ( !keep_planar[i - num_dmx] ) { @@ -1533,7 +1533,7 @@ void ivas_compute_spar_params( const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, - const int16_t num_ch, + const int16_t nchan, const int16_t bands_bw, const int16_t active_w, ivas_spar_md_com_cfg *hSparCfg, @@ -1544,12 +1544,12 @@ void ivas_compute_spar_params( float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; int16_t b, i, ndm; - ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, dtx_vad, from_dirac ); + ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, nchan, start_band, end_band, active_w, dtx_vad, from_dirac ); #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Prediction Coefficients:\n"); - for (i = 0; i < num_ch - 1; i++) + for (i = 0; i < nchan - 1; i++) { for (j = start_band; j < end_band; j++) { @@ -1559,14 +1559,14 @@ void ivas_compute_spar_params( } fprintf(stderr, "\n\n"); */ #endif - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, nchan, start_band, end_band, active_w, hSparCfg ); #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n 1st DMX matrix (band 0):\n"); - for (i = 0; i < num_ch; i++) + for (i = 0; i < nchan; i++) { - for (j = 0; j < num_ch; j++) + for (j = 0; j < nchan; j++) { fprintf(stderr, "%f, ", mixer_mat[i][j][0]); } @@ -1575,18 +1575,18 @@ void ivas_compute_spar_params( fprintf(stderr, "\n\n");*/ #endif - ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, + ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, nchan, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, pWscale ); for ( b = start_band; b < end_band; b++ ) { float onebyscale = 1.0f / pWscale[b]; - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[i] = pred_coeffs_re[i][b] * onebyscale; } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { mixer_mat[0][i][b] *= pWscale[b]; } @@ -1596,20 +1596,20 @@ void ivas_compute_spar_params( { ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; - if ( ndm != num_ch ) + if ( ndm != nchan ) { - ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, 0 ); + ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, nchan, ndm, b, dtx_vad, 1, 0 ); #ifdef SPAR_HOA_DBG /* if (b == 0) */ { fprintf( stdout, "\n\nUnquantised C, P coeffs -- band %d:\n", b ); - for ( int16_t ii = 0; ii < num_ch; ii++ ) + for ( int16_t ii = 0; ii < nchan; ii++ ) { fprintf( stdout, "%f |", hSparMd->band_coeffs[b].pred_re[ii] ); - if ( ii < num_ch - ndm ) + if ( ii < nchan - ndm ) { for ( int16_t jj = 0; jj < ndm - 1; jj++ ) { @@ -1649,7 +1649,7 @@ void ivas_get_spar_md_from_dirac( const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] ) { - int16_t num_ch, band, i, j; + int16_t nchan, band, i, j; int16_t block, ch; float response_avg[MAX_OUTPUT_CHANNELS]; float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; @@ -1667,7 +1667,7 @@ void ivas_get_spar_md_from_dirac( remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - num_ch = 2 * order + 2; + nchan = 2 * order + 2; hoa2_ch = 6; foa_ch = FOA_CHANNELS; diff_norm_order1 = 3.0f; @@ -1696,18 +1696,18 @@ void ivas_get_spar_md_from_dirac( P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); P_norm[1] = 0.0f; - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + for ( ; i < max( 0, min( nchan, hoa2_ch ) - ndm ); i++ ) { P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); + P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( nchan, hoa2_ch ) - ndm ) ); P_norm[2] = 0.0f; - for ( ; i < num_ch - ndm; i++ ) + for ( ; i < nchan - ndm; i++ ) { P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); + P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, nchan - ndm ) ); for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) { @@ -1715,13 +1715,13 @@ void ivas_get_spar_md_from_dirac( P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); } - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + for ( ; i < max( 0, min( nchan, hoa2_ch ) - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); } - for ( ; i < num_ch - ndm; i++ ) + for ( ; i < nchan - ndm; i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; @@ -1807,15 +1807,15 @@ void ivas_get_spar_md_from_dirac( } } - for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) + for ( i = FOA_CHANNELS + 1; i < nchan; i++ ) { response_avg[i] = response_avg[HOA_keep_ind[i]]; } en_ratio_fac = ( 1.0f - diffuseness[band] ); - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( i == j ) { @@ -1874,9 +1874,9 @@ void ivas_get_spar_md_from_dirac( } } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { pCov_real[i][j] = cov_real_dirac[i][j]; } @@ -1892,9 +1892,9 @@ void ivas_get_spar_md_from_dirac( fid = fopen( "cov_real_dirac.txt", "wt" ); } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -1907,7 +1907,7 @@ void ivas_get_spar_md_from_dirac( #endif ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, - num_ch, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); + nchan, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); if ( mixer_mat != NULL ) { @@ -1917,15 +1917,15 @@ void ivas_get_spar_md_from_dirac( for ( i = 0; i < ndm; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band]; } } - for ( i = ndm; i < num_ch; i++ ) + for ( i = ndm; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f; } @@ -1933,7 +1933,7 @@ void ivas_get_spar_md_from_dirac( if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band]; } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4b2c342f4f..859baaedce 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -355,7 +355,7 @@ typedef struct ivas_cov_smooth_cfg_t typedef struct ivas_cov_smooth_in_buf_t { float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - int16_t num_ch; + int16_t nchan; int16_t reset_cov; } ivas_cov_smooth_in_buf_t; @@ -670,8 +670,8 @@ typedef struct ivas_trans_det_state_t typedef struct ivas_fb_mixer_cfg_t { int16_t fb_latency; - int16_t num_in_chans; - int16_t num_out_chans; + int16_t nchan_inp; + int16_t nchan_out; int16_t pcm_offset; int16_t fade_len; /* this sets the stride length; no delay is introduced */ int16_t prior_input_length; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ec9a712065..116288299d 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -56,7 +56,7 @@ static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); static void initDiffuseResponses( float *diffuse_response_function, - const int16_t num_channels, + const int16_t nchan, AUDIO_CONFIG output_config, IVAS_OUTPUT_SETUP hOutSetup, const int16_t ambisonics_order, @@ -2522,7 +2522,7 @@ void ivas_dirac_dec_get_frequency_axis( static void initDiffuseResponses( float *diffuse_response_function, - const int16_t num_channels, + const int16_t nchan, AUDIO_CONFIG output_config, IVAS_OUTPUT_SETUP hOutSetup, const int16_t ambisonics_order, @@ -2543,7 +2543,7 @@ static void initDiffuseResponses( /* set diffuse response function */ if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_5_1_4 ) { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + num_horizontal_speakers = nchan - NUM_ELEVATED_SPEAKERS; mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers ); set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); @@ -2551,30 +2551,30 @@ static void initDiffuseResponses( } else if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_7_1_4 ) { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + num_horizontal_speakers = nchan - 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 == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && nchan == 5 ) { - mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); + mvr2r( diffuse_response_CICP6, diffuse_response_function, nchan ); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && nchan == 7 ) { - mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); + mvr2r( diffuse_response_CICP14, diffuse_response_function, nchan ); } - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( nchan == 9 ) ) { - mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); + mvr2r( diffuse_response_CICP16, diffuse_response_function, nchan ); } else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) { if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == 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 < nchan; i++ ) { if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f ) { @@ -2590,7 +2590,7 @@ static void initDiffuseResponses( /* Diffuse only to horizontal plane if enough loudspeakers */ if ( num_horizontal_speakers > 2 ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers ); } @@ -2598,17 +2598,17 @@ static void initDiffuseResponses( 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) nchan ), nchan ); } } else { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f( diffuse_response_function, sqrtf( 1.f / (float) nchan ), nchan ); } } else { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + set_f( diffuse_response_function, sqrtf( 1.f / (float) nchan ), nchan ); } } else diff --git a/lib_dec/ivas_dirac_decorr_dec.c b/lib_dec/ivas_dirac_decorr_dec.c index 437bdf8a64..c74d5d29ab 100644 --- a/lib_dec/ivas_dirac_decorr_dec.c +++ b/lib_dec/ivas_dirac_decorr_dec.c @@ -292,7 +292,7 @@ void ivas_dirac_dec_decorr_open( void ivas_dirac_dec_decorr_process( const int16_t num_freq_bands, - int16_t num_channels, + int16_t nchan, const int16_t num_protos_diff, const DIRAC_SYNTHESIS_CONFIG synthesisConf, const int16_t nchan_transport, /* i : number of transport channels*/ @@ -355,7 +355,7 @@ void ivas_dirac_dec_decorr_process( if ( synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - num_channels -= nchan_transport; + nchan -= nchan_transport; } @@ -380,8 +380,8 @@ void ivas_dirac_dec_decorr_process( ivas_dirac_dec_onset_detection_process( aux_buffer, onset_filter, num_protos_diff, h_freq_domain_decorr_ap_params->h_onset_detection_power_params, h_freq_domain_decorr_ap_state->h_onset_detection_power_state ); - /* Apply decorrelator if num_channels is greater than 0 */ - if ( num_channels > 0 ) + /* Apply decorrelator if nchan is greater than 0 */ + if ( nchan > 0 ) { /* remove onsets from prototype frame */ for ( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) @@ -403,7 +403,7 @@ void ivas_dirac_dec_decorr_process( phase_coeff_imag = h_freq_domain_decorr_ap_params->phase_coeff_imag; incr_aux = 2 * ( num_freq_bands - max_band_decorr ); - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { /* final phase rotation */ for ( k = 0; k < max_band_decorr; k++ ) @@ -419,9 +419,9 @@ void ivas_dirac_dec_decorr_process( decorr_buffer_len = h_freq_domain_decorr_ap_params->filter_length[0] + h_freq_domain_decorr_ap_params->pre_delay[0] - 1; for ( time_idx = 0; time_idx < ( decorr_buffer_len - 1 ); time_idx++ ) { - mvr2r( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( time_idx + 1 ) * max_band_decorr * num_channels], &h_freq_domain_decorr_ap_state->decorr_buffer[2 * (time_idx) *max_band_decorr * num_channels], 2 * max_band_decorr * num_channels ); + mvr2r( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( time_idx + 1 ) * max_band_decorr * nchan], &h_freq_domain_decorr_ap_state->decorr_buffer[2 * (time_idx) *max_band_decorr * nchan], 2 * max_band_decorr * nchan ); } - set_zero( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( decorr_buffer_len - 1 ) * max_band_decorr * num_channels], 2 * max_band_decorr * num_channels ); + set_zero( &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( decorr_buffer_len - 1 ) * max_band_decorr * nchan], 2 * max_band_decorr * nchan ); /* calculate all pass */ for ( split_bands_idx = 0; split_bands_idx < h_freq_domain_decorr_ap_params->num_split_frequency_bands; split_bands_idx++ ) @@ -431,15 +431,15 @@ void ivas_dirac_dec_decorr_process( num_bands = k_2 - k_1; filter_length = h_freq_domain_decorr_ap_params->filter_length[split_bands_idx]; pre_delay = h_freq_domain_decorr_ap_params->pre_delay[split_bands_idx]; - decorr_buffer_step = num_channels * max_band_decorr; + decorr_buffer_step = nchan * max_band_decorr; for ( k = 0; k < num_bands; ++k ) { band_idx = k_1 + k; - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { - idx_filter = band_idx * ( h_freq_domain_decorr_ap_params->filter_length[0] * num_channels ) + ch_idx * h_freq_domain_decorr_ap_params->filter_length[0]; + idx_filter = band_idx * ( h_freq_domain_decorr_ap_params->filter_length[0] * nchan ) + ch_idx * h_freq_domain_decorr_ap_params->filter_length[0]; filter_coeff_num_real = &h_freq_domain_decorr_ap_params->filter_coeff_num_real[idx_filter]; filter_coeff_den_real = &h_freq_domain_decorr_ap_params->filter_coeff_den_real[idx_filter]; decorr_buffer_start_ptr = &h_freq_domain_decorr_ap_state->decorr_buffer[2 * ( ch_idx * max_band_decorr + band_idx )]; @@ -486,18 +486,18 @@ void ivas_dirac_dec_decorr_process( /* calculate the power of the decorrelated signal */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { v_mult( &frame_dec_f[2 * ch_idx * num_freq_bands], &frame_dec_f[2 * ch_idx * num_freq_bands], &aux_buffer[2 * ch_idx * max_band_decorr], 2 * max_band_decorr ); v_add_inc( &aux_buffer[2 * ch_idx * max_band_decorr], 2, &aux_buffer[2 * ch_idx * max_band_decorr + 1], 2, &aux_buffer[ch_idx * max_band_decorr], 1, max_band_decorr ); } /* smooth energies */ - v_multc( aux_buffer, 1.0f - DIRAC_DUCK_ALPHA, aux_buffer, num_channels * max_band_decorr ); + v_multc( aux_buffer, 1.0f - DIRAC_DUCK_ALPHA, aux_buffer, nchan * max_band_decorr ); - v_multc( h_freq_domain_decorr_ap_state->reverb_energy_smooth, DIRAC_DUCK_ALPHA, h_freq_domain_decorr_ap_state->reverb_energy_smooth, num_channels * max_band_decorr ); + v_multc( h_freq_domain_decorr_ap_state->reverb_energy_smooth, DIRAC_DUCK_ALPHA, h_freq_domain_decorr_ap_state->reverb_energy_smooth, nchan * max_band_decorr ); - v_add( aux_buffer, h_freq_domain_decorr_ap_state->reverb_energy_smooth, h_freq_domain_decorr_ap_state->reverb_energy_smooth, num_channels * max_band_decorr ); + v_add( aux_buffer, h_freq_domain_decorr_ap_state->reverb_energy_smooth, h_freq_domain_decorr_ap_state->reverb_energy_smooth, nchan * max_band_decorr ); v_multc( direct_energy, 1.0f - DIRAC_DUCK_ALPHA, direct_energy, num_protos_dir * max_band_decorr ); @@ -505,7 +505,7 @@ void ivas_dirac_dec_decorr_process( v_add( direct_energy, h_freq_domain_decorr_ap_state->direct_energy_smooth, h_freq_domain_decorr_ap_state->direct_energy_smooth, num_protos_dir * max_band_decorr ); - for ( ch_idx = 0; ch_idx < num_channels; ch_idx++ ) + for ( ch_idx = 0; ch_idx < nchan; ch_idx++ ) { float *frame_dec_f_ptr = &frame_dec_f[ch_idx * 2 * num_freq_bands]; int16_t cur_proto_index = proto_index_dir[ch_idx] * max_band_decorr; @@ -545,7 +545,7 @@ void ivas_dirac_dec_decorr_process( if ( h_freq_domain_decorr_ap_params->add_back_onsets_on == 1 ) { - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { offset = proto_index_dir[ch_idx] * num_freq_bands; @@ -560,7 +560,7 @@ void ivas_dirac_dec_decorr_process( } /* avoid decorrelation above maximum frequency -> set to zero the remaining frequencies*/ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { /* calc output indices */ idx_in_out = 2 * ( ch_idx * num_freq_bands + h_freq_domain_decorr_ap_params->max_band_decorr ); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index decca34452..a26a469522 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -65,7 +65,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( const int16_t interp_length, /* i : length for interpolating the mixing matrices in time slots */ const int16_t num_param_bands, /* i : number of parameter bands */ const int16_t num_param_bands_residual, /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ - const int16_t nchan_in, /* i : number of input (transport) channels */ + const int16_t nchan_inp, /* i : number of input (transport) channels */ const int16_t nchan_out, /* i : number of output channels */ const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ) @@ -80,18 +80,18 @@ void ivas_dirac_dec_output_synthesis_cov_open( /* buffer length and interpolator */ h_dirac_output_synthesis_params->alpha_synthesis = NULL; - h_dirac_output_synthesis_params->proto_matrix = (float *) count_malloc( nchan_out * nchan_in * sizeof( float ) ); + h_dirac_output_synthesis_params->proto_matrix = (float *) count_malloc( nchan_out * nchan_inp * sizeof( float ) ); /* cov buffers */ for ( idx = 0; idx < num_param_bands; idx++ ) { - h_dirac_output_synthesis_state->cx_old[idx] = (float *) count_malloc( nchan_in * nchan_in * sizeof( float ) ); + h_dirac_output_synthesis_state->cx_old[idx] = (float *) count_malloc( nchan_inp * nchan_inp * sizeof( float ) ); h_dirac_output_synthesis_state->cy_old[idx] = (float *) count_malloc( nchan_out * nchan_out * sizeof( float ) ); - h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) count_malloc( nchan_out * nchan_in * sizeof( float ) ); - set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); + h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) count_malloc( nchan_out * nchan_inp * sizeof( float ) ); + set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_inp * nchan_inp ); set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); - set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_inp ); } for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -120,7 +120,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( h_dirac_output_synthesis_params->interpolator[idx - 1] = (float) idx / (float) interp_length; } - mvr2r( proto_matrix, h_dirac_output_synthesis_params->proto_matrix, nchan_in * nchan_out ); + mvr2r( proto_matrix, h_dirac_output_synthesis_params->proto_matrix, nchan_inp * nchan_out ); return; } @@ -134,7 +134,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ - const int16_t nchan_in, /* i : number of input (tranport) channels */ + const int16_t nchan_inp, /* i : number of input (tranport) channels */ const int16_t nchan_out, /* i : number of output channels */ const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ @@ -146,9 +146,9 @@ void ivas_dirac_dec_output_synthesis_cov_init( /* initialize buffers */ for ( idx = 0; idx < n_param_bands; idx++ ) { - set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); + set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_inp * nchan_inp ); set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); - set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); + set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_inp ); } for ( idx = 0; idx < n_param_bands_res; idx++ ) @@ -243,7 +243,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( float cx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ float cx_imag[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ - const int16_t nchan_in, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t idx_slot /* i : index of the slot to be added to the input covariance */ ) { @@ -268,18 +268,18 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( for ( band_idx = 0; band_idx < num_bands; band_idx++ ) { int16_t band = brange[0] + band_idx; - for ( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) + for ( ch_idx = 0; ch_idx < nchan_inp; ch_idx++ ) { real_in_buffer[band_idx + num_bands * ch_idx] = RealBuffer[ch_idx][idx_slot][band]; imag_in_buffer[band_idx + num_bands * ch_idx] = ImagBuffer[ch_idx][idx_slot][band]; } } - cmplx_matrix_square( real_in_buffer, imag_in_buffer, num_bands, nchan_in, real_buffer, imag_buffer ); + cmplx_matrix_square( real_in_buffer, imag_in_buffer, num_bands, nchan_inp, real_buffer, imag_buffer ); - v_add( cx[param_band], real_buffer, cx[param_band], nchan_in * nchan_in ); + v_add( cx[param_band], real_buffer, cx[param_band], nchan_inp * nchan_inp ); - v_add( cx_imag[param_band], imag_buffer, cx_imag[param_band], nchan_in * nchan_in ); + v_add( cx_imag[param_band], imag_buffer, cx_imag[param_band], nchan_inp * nchan_inp ); } return; diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 79c04f824b..3cf09b8182 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -61,15 +61,15 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void computeTargetPSDs_direct( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); +static void computeTargetPSDs_direct( const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); -static void computeTargetPSDs_direct_subframe( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); +static void computeTargetPSDs_direct_subframe( const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); -static void computeTargetPSDs_diffuse( const int16_t num_channels, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); +static void computeTargetPSDs_diffuse( const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); -static void computeTargetPSDs_diffuse_subframe( const int16_t num_channels, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); +static void computeTargetPSDs_diffuse_subframe( const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); -static void computeTargetPSDs_diffuse_with_onsets( const int16_t num_channels, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, const float *onset_filter, float *cy_auto_diff_smooth ); +static void computeTargetPSDs_diffuse_with_onsets( const int16_t nchan, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, const float *onset_filter, float *cy_auto_diff_smooth ); 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 ); @@ -1812,7 +1812,7 @@ void ivas_lfe_synth_with_filters( *------------------------------------------------------------------------*/ static void computeTargetPSDs_direct( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, @@ -1831,7 +1831,7 @@ static void computeTargetPSDs_direct( v_mult( direct_power_factor, reference_power, direct_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; @@ -1847,7 +1847,7 @@ static void computeTargetPSDs_direct( static void computeTargetPSDs_direct_subframe( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, @@ -1865,7 +1865,7 @@ static void computeTargetPSDs_direct_subframe( v_mult( direct_power_factor, reference_power, direct_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; @@ -1878,7 +1878,7 @@ static void computeTargetPSDs_direct_subframe( static void computeTargetPSDs_diffuse( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, @@ -1896,7 +1896,7 @@ static void computeTargetPSDs_diffuse( v_mult( diffuse_power_factor, reference_power, diffuse_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; v_multc( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, num_freq_bands - start_band ); @@ -1908,7 +1908,7 @@ static void computeTargetPSDs_diffuse( static void computeTargetPSDs_diffuse_subframe( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, @@ -1923,7 +1923,7 @@ static void computeTargetPSDs_diffuse_subframe( v_mult( diffuse_power_factor, reference_power, diffuse_power, num_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { cur_idx = ch_idx * num_freq_bands; @@ -1935,7 +1935,7 @@ static void computeTargetPSDs_diffuse_subframe( static void computeTargetPSDs_diffuse_with_onsets( - const int16_t num_channels, + const int16_t nchan, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, @@ -1955,7 +1955,7 @@ static void computeTargetPSDs_diffuse_with_onsets( v_mult( diffuse_power_factor, reference_power, diffuse_power, num_decorr_freq_bands ); /* compute target auto and cross PSDs of current frame (smoothed) */ - for ( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + for ( ch_idx = 0; ch_idx < nchan; ++ch_idx ) { diffuse_response_p4 = diffuse_responses_square[ch_idx] * diffuse_responses_square[ch_idx]; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e3849dfbe0..2984ada3de 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1753,7 +1753,7 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_DIRAC: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_inp; if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { @@ -1761,7 +1761,7 @@ void ivas_init_dec_get_num_cldfb_instances( } else if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) { - *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_out; } else { @@ -1811,7 +1811,7 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_BINAURAL_FASTCONV_ROOM: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; + *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_inp; if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { @@ -1819,7 +1819,7 @@ void ivas_init_dec_get_num_cldfb_instances( } else if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) { - *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; + *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->nchan_out; } else { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index c6c1f99c9c..460efb7e22 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -351,7 +351,7 @@ static ivas_error ivas_param_ism_rendering_init( static void ivas_param_ism_update_mixing_matrix( DIRAC_DEC_HANDLE hDirAC, float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX], - const int16_t nchan_in, + const int16_t nchan_inp, const int16_t nchan_out ) { int16_t inchIdx, outchIdx, bin_idx, band_idx; @@ -364,7 +364,7 @@ static void ivas_param_ism_update_mixing_matrix( for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { - for ( inchIdx = 0; inchIdx < nchan_in; inchIdx++ ) + for ( inchIdx = 0; inchIdx < nchan_inp; inchIdx++ ) { for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ ) { diff --git a/lib_dec/ivas_limiter.c b/lib_dec/ivas_limiter.c index e483318be8..d3dcd8027f 100644 --- a/lib_dec/ivas_limiter.c +++ b/lib_dec/ivas_limiter.c @@ -125,7 +125,7 @@ IVAS_LIMITER_HANDLE ivas_limiter_open( hLimiter = count_malloc( sizeof( IVAS_LIMITER ) ); hLimiter->max_num_channels = max_num_channels; - hLimiter->num_channels = max_num_channels; + hLimiter->nchan = max_num_channels; hLimiter->channel_ptrs = count_malloc( max_num_channels * sizeof( float * ) ); hLimiter->sampling_rate = sampling_rate; hLimiter->gain = 1.f; @@ -176,11 +176,11 @@ void ivas_limiter_close( *-------------------------------------------------------------------*/ void ivas_limiter_dec( - IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], /* i/o: input/output buffer */ - const int16_t num_channels, /* i : number of channels to be processed */ - const int16_t output_frame, /* i : number of samples per channel in the buffer */ - const int16_t BER_detect /* i : BER detect flag */ + IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ + float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], /* i/o: input/output buffer */ + const int16_t nchan, /* i : number of channels to be processed */ + const int16_t output_frame, /* i : number of samples per channel in the buffer */ + const int16_t BER_detect /* i : BER detect flag */ ) { int16_t c; @@ -193,11 +193,11 @@ void ivas_limiter_dec( } /* Update number of channels and prepare pointers to the beginning of each of them */ - assert( num_channels <= hLimiter->max_num_channels && "Number of channels must be lower than the maximum set during limiter initialization!" ); - hLimiter->num_channels = min( num_channels, hLimiter->max_num_channels ); + assert( nchan <= hLimiter->max_num_channels && "Number of channels must be lower than the maximum set during limiter initialization!" ); + hLimiter->nchan = min( nchan, hLimiter->max_num_channels ); channels = hLimiter->channel_ptrs; - for ( c = 0; c < num_channels; ++c ) + for ( c = 0; c < nchan; ++c ) { channels[c] = output[c]; } @@ -231,7 +231,7 @@ void limiter_process( float releaseHeuristic; int16_t apply_limiting, apply_strong_limiting; float **output; - int16_t num_channels; + int16_t nchan; int32_t sampling_rate; /* return early if given nonsensical values */ @@ -245,7 +245,7 @@ void limiter_process( gain = hLimiter->gain; output = hLimiter->channel_ptrs; - num_channels = hLimiter->num_channels; + nchan = hLimiter->nchan; sampling_rate = hLimiter->sampling_rate; attack_constant = hLimiter->attack_constant; @@ -257,7 +257,7 @@ void limiter_process( for ( i = 0; i < output_frame; i++ ) { - for ( c = 0; c < num_channels; c++ ) + for ( c = 0; c < nchan; c++ ) { tmp = fabsf( output[c][i] ); if ( tmp > max_val ) @@ -364,7 +364,7 @@ void limiter_process( gain = release_constant * ( gain - frame_gain ) + frame_gain; } - for ( c = 0; c < num_channels; c++ ) + for ( c = 0; c < nchan; c++ ) { sample = &output[c][i]; diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 29e2ce4002..a6889137f6 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -60,8 +60,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, const int16_t nchan_in, const int16_t nchan_out ); - +static void ivas_param_mc_dec_init( PARAM_MC_DEC_HANDLE hParamMC, const int16_t nchan_inp, const int16_t nchan_out ); static void param_mc_protoSignalComputation( float RealBuffer[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_NSLOTS][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_NSLOTS][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const int16_t slot_index, const int16_t num_freq_bands ); diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 9ed27e56c3..2a02fb56e9 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -147,7 +147,7 @@ static void get_custom_ls_conversion_matrix( { int16_t ch_in, ch_in_woLFE; int16_t ch_out, ch_out_woLFE; - int16_t nchan_in, nchan_out; + int16_t nchan_inp, nchan_out; int16_t lfe_in_idx, lfe_out_idx; float dmxCoeff_LFE; @@ -156,7 +156,7 @@ static void get_custom_ls_conversion_matrix( lfe_in_idx = -1; lfe_out_idx = -1; - nchan_in = hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe; + nchan_inp = hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe; nchan_out = hLsSetupCustom->num_spk + hLsSetupCustom->num_lfe; /* The below code will need to be restructured in case additional LFEs must be supported */ @@ -171,7 +171,7 @@ static void get_custom_ls_conversion_matrix( dmxCoeff_LFE = 1.f / hTransSetup.nchan_out_woLFE; - for ( ch_in = 0, ch_in_woLFE = 0; ch_in < nchan_in; ch_in++, ch_in_woLFE++ ) + for ( ch_in = 0, ch_in_woLFE = 0; ch_in < nchan_inp; ch_in++, ch_in_woLFE++ ) { if ( lfe_in_idx == ch_in ) { @@ -218,7 +218,7 @@ static ivas_error get_ls_conversion_matrix( { int16_t i, k; int16_t ch_in, ch_out; - int16_t nchan_in, nchan_out; + int16_t nchan_inp, nchan_out; int16_t index; float value; const LS_CONVERSION_MATRIX *conversion_matrix; @@ -228,7 +228,7 @@ static ivas_error get_ls_conversion_matrix( conversion_matrix = NULL; - nchan_in = audioCfg2channels( input_config ); + nchan_inp = audioCfg2channels( input_config ); nchan_out = audioCfg2channels( output_config ); /* Search the table for a mapping */ @@ -239,7 +239,7 @@ static ivas_error get_ls_conversion_matrix( /* Special handling for MONO and STEREO downmix */ if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) { - for ( ch_in = 0, k = 0; ch_in < nchan_in; ch_in++, k++ ) + for ( ch_in = 0, k = 0; ch_in < nchan_inp; ch_in++, k++ ) { /* Skip two rows in the matrix for 5.1.x formats */ if ( ch_in == 6 && ( input_config == AUDIO_CONFIG_5_1_2 || input_config == AUDIO_CONFIG_5_1_4 ) ) @@ -268,7 +268,7 @@ static ivas_error get_ls_conversion_matrix( /* If a mapping is defined with a NULL matrix, 1:1 upmix of input channels */ if ( conversion_matrix == NULL ) { - for ( k = 0; k < nchan_in; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { hLsSetUpConversion->dmxMtx[k][k] = 1.0f; } diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index 39918776e6..421ec619d3 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -516,7 +516,7 @@ const int16_t sba_map_tc[8] = * LS Renderer ROM tables *----------------------------------------------------------------------------------*/ - /* All matrices are stored with dimensions nchan_in x nchan_out */ + /* All matrices are stored with dimensions nchan_inp x nchan_out */ /* Downmix matrices */ const float ls_conversion_cicpX_mono[12][1] = { diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 92e50de535..1efde66cf5 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -47,7 +47,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t output_frame, const int16_t nchan_in, const IVAS_OUTPUT_SETUP output_setup, const float *mtx_hoa_decoder ); +static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t output_frame, const int16_t nchan_inp, const IVAS_OUTPUT_SETUP output_setup, const float *mtx_hoa_decoder ); /*-------------------------------------------------------------------* @@ -59,7 +59,7 @@ static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t outpu ivas_error ivas_sba_linear_renderer( float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : number of input ambisonics channels */ + const int16_t nchan_inp, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup, /* i : output format setup */ const float hoa_dec_mtx[] /* i : HOA decoding mtx */ @@ -73,13 +73,13 @@ ivas_error ivas_sba_linear_renderer( error = IVAS_ERR_OK; /* Number of channels of HOA depends of transport format which is mixed order xH1V*/ - nchan_hoa = nchan_in; + nchan_hoa = nchan_inp; - if ( nchan_in == 6 ) /*2H1V*/ + if ( nchan_inp == 6 ) /*2H1V*/ { nchan_hoa = 9; } - else if ( nchan_in == 8 ) /*3H1V*/ + else if ( nchan_inp == 8 ) /*3H1V*/ { nchan_hoa = 16; } @@ -88,7 +88,7 @@ ivas_error ivas_sba_linear_renderer( { case AUDIO_CONFIG_MONO: /* If stereo DMX, MONO = W = Cardioids L + R*/ - if ( nchan_in == 2 ) + if ( nchan_inp == 2 ) { for ( i = 0; i < output_frame; i++ ) { @@ -98,10 +98,10 @@ ivas_error ivas_sba_linear_renderer( /* else: do nothing, MONO = W*/ break; case AUDIO_CONFIG_STEREO: - assert( ( nchan_in >= 2 ) && "Number of input channels must be at least 2 (for W and Y)!\n" ); + assert( ( nchan_inp >= 2 ) && "Number of input channels must be at least 2 (for W and Y)!\n" ); /* Compute L and R cardioids from SB format except if stereo DMX is transmitted already in this format*/ - if ( nchan_in > 2 ) + if ( nchan_inp > 2 ) { /*Build L/R cardioids*/ for ( i = 0; i < output_frame; i++ ) @@ -145,7 +145,7 @@ ivas_error ivas_sba_linear_renderer( static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : Number of ambisonic channels */ + const int16_t nchan_inp, /* i : Number of ambisonic channels */ const IVAS_OUTPUT_SETUP output_setup, /* i : Output configuration */ const float *mtx_hoa_decoder /* i : HOA decoding mtx */ ) @@ -155,14 +155,14 @@ static void ivas_sba_mtx_mult( float input_f[16]; const float *hoa_decoder; - assert( ( nchan_in >= FOA_CHANNELS ) && "Number of input channels must be at least 4 (FOA)!\n" ); + assert( ( nchan_inp >= FOA_CHANNELS ) && "Number of input channels must be at least 4 (FOA)!\n" ); for ( i = 0; i < output_frame; i++ ) { /* init*/ idx_lfe = 0; hoa_decoder = &mtx_hoa_decoder[0]; - for ( k = 0; k < nchan_in; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { input_f[k] = output_f[k][i]; } @@ -183,7 +183,7 @@ static void ivas_sba_mtx_mult( { /*HOA decoding*/ output_f[ch_idx][i] = input_f[0] * hoa_decoder[0]; - for ( k = 1; k < nchan_in; k++ ) + for ( k = 1; k < nchan_inp; k++ ) { output_f[ch_idx][i] += input_f[k] * hoa_decoder[k]; } @@ -320,7 +320,7 @@ void ivas_sba_prototype_renderer( DECODER_CONFIG_HANDLE hDecoderConfig; int16_t num_spar_bands, spar_band; int16_t b, ts; - int16_t num_cldfb_bands, numch_in, numch_out; + int16_t num_cldfb_bands, nchan_inp, nchan_out; int16_t cldfb_band; int16_t out_ch, in_ch; int16_t firstSlot, slotEnd, firstInCh, inChEnd, firstOutCh, outChEnd; @@ -336,8 +336,8 @@ void ivas_sba_prototype_renderer( slotEnd = ( firstSubframe + nSubframes ) * ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ); num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + nchan_inp = hSpar->hFbMixer->fb_cfg->nchan_inp; + nchan_out = hSpar->hFbMixer->fb_cfg->nchan_out; if ( st_ivas->nchan_transport == 1 ) { @@ -358,7 +358,7 @@ void ivas_sba_prototype_renderer( for ( ts = firstSlot; ts < slotEnd; ts++ ) { /* determine SPAR parameters for this time slot */ - ivas_spar_get_parameters( hSpar, hDecoderConfig, ts, numch_out, numch_in, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts, nchan_out, nchan_inp, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -413,9 +413,9 @@ void ivas_sba_prototype_renderer( mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) { for ( b = 0; b < num_spar_bands; b++ ) { diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index c7a3fcff20..8da866f194 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -65,14 +65,14 @@ ivas_error ivas_spar_dec_open( { SPAR_DEC_HANDLE hSpar; ivas_error error; - int16_t sba_order_internal, num_channels_internal; + int16_t sba_order_internal, nchan_internal; IVAS_FB_CFG *fb_cfg; int16_t i, j, b, active_w_mixing; int32_t output_Fs; 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 ); + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); /* SPAR decoder handle */ if ( ( hSpar = (SPAR_DEC_HANDLE) count_malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) @@ -83,13 +83,13 @@ ivas_error ivas_spar_dec_open( output_Fs = st_ivas->hDecoderConfig->output_Fs; /* TD decorr. */ - if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_channels_internal, 1 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, nchan_internal, 1 ) ) != IVAS_ERR_OK ) { return error; } /* MD handle */ - if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, nchan_internal ) ) != IVAS_ERR_OK ) { return error; } @@ -98,7 +98,7 @@ ivas_error ivas_spar_dec_open( /* set FB config. */ active_w_mixing = -1; - if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, nchan_internal, active_w_mixing, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -130,9 +130,9 @@ ivas_error ivas_spar_dec_open( } /* mixer_mat intitialization */ - for ( i = 0; i < num_channels_internal; i++ ) + for ( i = 0; i < nchan_internal; i++ ) { - for ( j = 0; j < num_channels_internal; j++ ) + for ( j = 0; j < nchan_internal; j++ ) { for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { @@ -622,7 +622,7 @@ static void ivas_spar_dec_MD( Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ ) { - int16_t num_channels, table_idx, num_bands_out, bfi, sba_order; + int16_t nchan, table_idx, num_bands_out, bfi, sba_order; int32_t ivas_total_brate; DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig; SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; @@ -636,7 +636,7 @@ static void ivas_spar_dec_MD( sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); bfi = st_ivas->bfi; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; if ( ivas_total_brate > FRAME_NO_DATA && !bfi ) @@ -652,7 +652,7 @@ static void ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; - ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ); + ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, nchan ); } } @@ -884,14 +884,13 @@ void ivas_spar_dec_upmixer( const int16_t output_frame /* i : output frame length */ ) { - int16_t cldfb_band, num_cldfb_bands, numch_in, numch_out; + int16_t nchan_inp, nchan_out, nchan_transport, nchan_ingest; + int16_t cldfb_band, num_cldfb_bands; float *cldfb_in_ts_re[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; float *cldfb_in_ts_im[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; int16_t i, b, ts, out_ch, in_ch; - int16_t num_spar_bands, spar_band, nchan_transport; - int16_t num_in_ingest, num_bands_out, split_band; + int16_t num_spar_bands, spar_band, num_bands_out, split_band; float Pcm_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - int16_t numch_out_dirac; float *pPcm_tmp[MAX_OUTPUT_CHANNELS]; float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -906,8 +905,8 @@ void ivas_spar_dec_upmixer( nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; - numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; - numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + nchan_inp = hSpar->hFbMixer->fb_cfg->nchan_inp; + nchan_out = hSpar->hFbMixer->fb_cfg->nchan_out; #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC /* by-pass core-coder */ @@ -963,11 +962,11 @@ void ivas_spar_dec_upmixer( if ( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = nchan_internal; + nchan_ingest = nchan_internal; } else { - num_in_ingest = nchan_transport; + nchan_ingest = nchan_transport; } for ( i = 0; i < nchan_internal; i++ ) @@ -979,15 +978,15 @@ void ivas_spar_dec_upmixer( * PCA decoder *---------------------------------------------------------------------*/ #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->pca_ingest_channels = num_in_ingest; + hSpar->pca_ingest_channels = nchan_ingest; #endif if ( hSpar->hPCA != NULL ) { - ivas_pca_dec( hSpar->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); + ivas_pca_dec( hSpar->hPCA, output_frame, nchan_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); #ifdef DEBUG_SBA_AUDIO_DUMP /* Dump audio signal after ivas_pca_dec */ - ivas_spar_dump_signal_wav( output_frame, NULL, output, num_in_ingest, spar_foa_dec_wav[2], "ivas_pca_dec()" ); + ivas_spar_dump_signal_wav( output_frame, NULL, output, nchan_ingest, spar_foa_dec_wav[2], "ivas_pca_dec()" ); #endif } @@ -1005,11 +1004,11 @@ void ivas_spar_dec_upmixer( mvr2r( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - i], output[nchan_internal - 1 - i], output_frame ); } - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->nchan_inp = nchan_inp; // VE2DB: this is the same for the else branch below -> call it only once? } else { - hSpar->hFbMixer->fb_cfg->num_in_chans = num_in_ingest; + hSpar->hFbMixer->fb_cfg->nchan_inp = nchan_inp; } /*---------------------------------------------------------------------* @@ -1031,7 +1030,7 @@ void ivas_spar_dec_upmixer( } else { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { @@ -1056,14 +1055,12 @@ void ivas_spar_dec_upmixer( /* apply parameters */ /* determine if we can skip certain data */ - ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ - - numch_out_dirac = st_ivas->hDecoderConfig->nchan_out; + ivas_spar_get_skip_mat( hSpar, nchan_out, nchan_inp, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ for ( int16_t i_sf = 0; i_sf < MAX_PARAM_SPATIAL_SUBFRAMES; i_sf++ ) { /* CLDFB analysis of incoming frame */ - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { @@ -1079,7 +1076,7 @@ void ivas_spar_dec_upmixer( for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ - ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, nchan_out, nchan_inp, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -1088,12 +1085,12 @@ void ivas_spar_dec_upmixer( float cldfb_par; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) { out_re[out_ch] = 0.0f; out_im[out_ch] = 0.0f; - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) { if ( b_skip_mat[out_ch][in_ch] ) { @@ -1120,7 +1117,7 @@ void ivas_spar_dec_upmixer( } /*update CLDFB data with the parameter-modified data*/ - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) { cldfb_in_ts_re[out_ch][ts][cldfb_band] = out_re[out_ch]; cldfb_in_ts_im[out_ch][ts][cldfb_band] = out_im[out_ch]; @@ -1176,7 +1173,7 @@ void ivas_spar_dec_upmixer( else { /* CLDFB to time synthesis (overwrite mixer output) */ - for ( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + for ( out_ch = 0; out_ch < st_ivas->hDecoderConfig->nchan_out; out_ch++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { @@ -1207,9 +1204,9 @@ void ivas_spar_dec_upmixer( mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) { - for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) { for ( b = 0; b < num_spar_bands; b++ ) { diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 7f01f64c0f..a9307ddb82 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -73,7 +73,7 @@ static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, const static void ivas_get_band_idx_from_differential( ivas_spar_md_t *pSpar_md, const int16_t q_levels[2], const int16_t one_sided, const int16_t nB, const ivas_coeffs_type_t coeff_type ); -static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t num_ch ); +static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t nchan ); static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands, const int16_t bfi ); @@ -94,7 +94,7 @@ static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder static ivas_error ivas_spar_md_dec_matrix_open( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j; @@ -103,17 +103,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdDec->mixer_mat = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->mixer_mat = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->mixer_mat[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->mixer_mat[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->mixer_mat[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -122,17 +122,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs.C_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs.C_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs.C_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -141,17 +141,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs.P_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs.P_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs.P_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -160,17 +160,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_prev.C_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.C_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_prev.C_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -179,17 +179,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_prev.P_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.P_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.P_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.P_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_prev.P_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -198,17 +198,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -217,17 +217,17 @@ static ivas_error ivas_spar_md_dec_matrix_open( } } - if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.P_re[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdDec->spar_coeffs_tar.P_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -249,7 +249,7 @@ static ivas_error ivas_spar_md_dec_matrix_open( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ) { ivas_spar_md_dec_state_t *hMdDec; @@ -262,14 +262,14 @@ ivas_error ivas_spar_md_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } - if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, num_channels ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, nchan ) ) != IVAS_ERR_OK ) { return error; } hMdDec->table_idx = 0; /* just to initialize state variables*/ - if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, nchan ) ) != IVAS_ERR_OK ) { return error; } @@ -288,7 +288,7 @@ ivas_error ivas_spar_md_dec_open( static void ivas_spar_md_dec_matrix_close( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j; @@ -300,9 +300,9 @@ static void ivas_spar_md_dec_matrix_close( } if ( hMdDecoder->mixer_mat != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->mixer_mat[i][j] ); } @@ -313,9 +313,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs.C_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs.C_re[i][j] ); } @@ -326,9 +326,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs.P_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs.P_re[i][j] ); } @@ -339,9 +339,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_prev.C_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_prev.C_re[i][j] ); } @@ -352,9 +352,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_prev.P_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_prev.P_re[i][j] ); } @@ -365,9 +365,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_tar.C_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_tar.C_re[i][j] ); } @@ -378,9 +378,9 @@ static void ivas_spar_md_dec_matrix_close( if ( hMdDecoder->spar_coeffs_tar.P_re != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdDecoder->spar_coeffs_tar.P_re[i][j] ); } @@ -404,12 +404,12 @@ void ivas_spar_md_dec_close( ) { ivas_spar_md_dec_state_t *hMdDecoder; - int16_t num_channels; + int16_t nchan; hMdDecoder = *hMdDec; - num_channels = hMdDecoder->spar_md_cfg.num_umx_chs; + nchan = hMdDecoder->spar_md_cfg.num_umx_chs; - ivas_spar_md_dec_matrix_close( hMdDecoder, num_channels ); + ivas_spar_md_dec_matrix_close( hMdDecoder, nchan ); if ( *hMdDec != NULL ) { @@ -430,7 +430,7 @@ void ivas_spar_md_dec_close( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j, k; @@ -471,9 +471,9 @@ ivas_error ivas_spar_md_dec_init( hMdDec->spar_plc_num_lost_frames = 0; hMdDec->spar_plc_enable_fadeout_flag = 1; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -482,9 +482,9 @@ ivas_error ivas_spar_md_dec_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -493,9 +493,9 @@ ivas_error ivas_spar_md_dec_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -504,9 +504,9 @@ ivas_error ivas_spar_md_dec_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -622,17 +622,17 @@ void ivas_spar_md_dec_process( char f_name[100]; int16_t num_bands = nB; int16_t num_subframes = 1, num_block_groups = 1, num_elements = 1, byte_size = sizeof( float ); - int16_t num_ch = 2 * sba_order + 2; + int16_t nchan = 2 * sba_order + 2; for ( b = 0; b < num_bands; b++ ) { sprintf( f_name, "spar_band_pred_coeffs_dec.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( j = 0; j < num_ch - 1; j++ ) + for ( j = 0; j < nchan - 1; j++ ) { dbgwrite( &hMdDec->spar_md.band_coeffs[b].pred_re[j], sizeof( float ), 1, 1, f_name ); } @@ -652,12 +652,12 @@ void ivas_spar_md_dec_process( } sprintf( f_name, "spar_band_P_coeffs_dec.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &num_bands, sizeof( num_bands ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( j = 0; j < num_ch - 1; j++ ) + for ( j = 0; j < nchan - 1; j++ ) { dbgwrite( &hMdDec->spar_md.band_coeffs[b].P_re[j], sizeof( float ), 1, 1, f_name ); } @@ -826,13 +826,13 @@ void ivas_spar_setup_md_smoothing( ) { /* copy the coeffs */ - int16_t num_channels, i, j, k; + int16_t nchan, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + nchan = hMdDec->spar_md_cfg.num_umx_chs; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -841,9 +841,9 @@ void ivas_spar_setup_md_smoothing( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -852,9 +852,9 @@ void ivas_spar_setup_md_smoothing( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -863,9 +863,9 @@ void ivas_spar_setup_md_smoothing( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -889,13 +889,13 @@ void ivas_spar_setup_md_smoothing( void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec ) { - int16_t num_channels, i, j, k; + int16_t nchan, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + nchan = hMdDec->spar_md_cfg.num_umx_chs; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -904,9 +904,9 @@ void ivas_spar_update_md_hist( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -915,9 +915,9 @@ void ivas_spar_update_md_hist( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -926,9 +926,9 @@ void ivas_spar_update_md_hist( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -1316,15 +1316,15 @@ static void ivas_mat_col_rearrange( const int16_t i_ts, float ***mixer_mat, const int16_t bands, - const int16_t num_ch ) + const int16_t nchan ) { int16_t i, j, idx; - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { idx = order[i]; - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mixer_mat[j][i][bands + i_ts * IVAS_MAX_NUM_BANDS] = in_re[j][idx]; } @@ -2097,9 +2097,9 @@ static void ivas_spar_md_fill_invalid_bands( int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS]; float w = 0; - int16_t num_channels; + int16_t nchan; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); set_s( valid_band_idx, 0, IVAS_MAX_NUM_BANDS ); set_s( last_valid_band_idx, 0, IVAS_MAX_NUM_BANDS ); @@ -2155,9 +2155,9 @@ static void ivas_spar_md_fill_invalid_bands( w = ( (float) ( b - id0 ) ) / ( id1 - id0 ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { pSpar_coeffs->C_re[i][j][b] = ( 1 - w ) * pSpar_coeffs->C_re[i][j][id0] + w * pSpar_coeffs->C_re[i][j][id1]; pSpar_coeffs->P_re[i][j][b] = ( 1 - w ) * pSpar_coeffs->P_re[i][j][id0] + w * pSpar_coeffs->P_re[i][j][id1]; @@ -2168,9 +2168,9 @@ static void ivas_spar_md_fill_invalid_bands( { if ( valid_bands[b] == 0 ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { pSpar_coeffs->C_re[i][j][b] = pSpar_coeffs_prev->C_re[i][j][b]; pSpar_coeffs->P_re[i][j][b] = pSpar_coeffs_prev->P_re[i][j][b]; @@ -2182,9 +2182,9 @@ static void ivas_spar_md_fill_invalid_bands( if ( valid_bands[b] == 0 ) { int16_t i_ts; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 9f36670a7d..9bfe233e8e 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -511,37 +511,37 @@ typedef struct dirac_output_synthesis_params_structure typedef struct dirac_output_synthesis_state_structure { /* only pointer to local buffers */ - float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*nchan. */ float *direct_responses_square; - float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */ + float *diffuse_responses_square; /* squared diffuse responses. Size: nchan. */ /* only pointer to local buffers */ float *direct_power_factor; float *diffuse_power_factor; - float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ - float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ + float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*nchan. */ + float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*nchan. */ float *proto_power_diff_smooth; float *proto_power_diff_smooth_prev; /* only pointer to local buffers */ - float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ + float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ /* Output gain memories */ float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ /* only pointer to local buffers */ - float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ - float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ - float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*nchan. */ + float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*nchan. */ + float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*nchan. */ /* PSD memories */ - float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ - float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ - float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*nchan. */ + float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*nchan. */ + float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*nchan. */ const float *onset_filter; @@ -559,14 +559,14 @@ typedef struct dirac_output_synthesis_cov_state_structure float *diffuse_power_factor; /* only pointer to local buffers */ - float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*nchan. */ float *direct_responses_square; - float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */ + float *diffuse_responses_square; /* squared diffuse responses. Size: nchan. */ /* only pointer to local buffers */ - float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_power; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ + float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*nchan*buffer_length (complex interleaved). */ + float *proto_power; /* Smoothed power of the prototype signals. Size: num_freq_bands*nchan. */ float *proto_power_diff; float *cx_old[CLDFB_NO_CHANNELS_MAX]; @@ -1881,7 +1881,7 @@ typedef struct ivas_lfe_dec_data_structure typedef struct { int16_t max_num_channels; - int16_t num_channels; + int16_t nchan; float **channel_ptrs; int32_t sampling_rate; float gain; diff --git a/lib_dec/ivas_td_decorr.c b/lib_dec/ivas_td_decorr.c index 29b748e4c7..e1daf78e60 100644 --- a/lib_dec/ivas_td_decorr.c +++ b/lib_dec/ivas_td_decorr.c @@ -91,8 +91,8 @@ const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { * Local functions declaration *------------------------------------------------------------------------------------------*/ -static int16_t ivas_get_APD_filt_orders( const int16_t num_out_chans, const int32_t output_Fs, int16_t *APD_filt_orders ); -static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ); +static int16_t ivas_get_APD_filt_orders( const int16_t nchan, const int32_t output_Fs, int16_t *APD_filt_orders ); +static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t nchan, const int16_t ducking_flag ); /*------------------------------------------------------------------------- @@ -109,11 +109,11 @@ ivas_error ivas_spar_td_decorr_dec_open( ) { int16_t i, j, len; - int16_t num_out_chans; + int16_t nchan; ivas_td_decorr_state_t *hCovState; ivas_error error; - num_out_chans = nchan_internal - 1; + nchan = nchan_internal - 1; error = IVAS_ERR_OK; @@ -128,9 +128,9 @@ ivas_error ivas_spar_td_decorr_dec_open( } set_f( hCovState->look_ahead_buf, 0, (int16_t) ( output_Fs * IVAS_DECORR_PARM_LOOKAHEAD_TAU ) ); - hCovState->num_apd_sections = ivas_get_APD_filt_orders( num_out_chans, output_Fs, hCovState->APD_filt_state[0].order ); + hCovState->num_apd_sections = ivas_get_APD_filt_orders( nchan, output_Fs, hCovState->APD_filt_state[0].order ); - for ( j = 0; j < num_out_chans; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( i = 0; i < hCovState->num_apd_sections; i++ ) { @@ -145,7 +145,7 @@ ivas_error ivas_spar_td_decorr_dec_open( } } - ivas_td_decorr_init( hCovState, num_out_chans, ducking_flag ); + ivas_td_decorr_init( hCovState, nchan, ducking_flag ); if ( ducking_flag ) { @@ -213,7 +213,7 @@ void ivas_spar_td_decorr_dec_close( *-----------------------------------------------------------------------------------------*/ static int16_t ivas_get_APD_filt_orders( - const int16_t num_out_chans, + const int16_t nchan, const int32_t output_Fs, int16_t *APD_filt_orders ) { @@ -221,7 +221,7 @@ static int16_t ivas_get_APD_filt_orders( int16_t num_apd_sections = 0; float sum_R, R[IVAS_MAX_DECORR_APD_SECTIONS]; - switch ( num_out_chans ) + switch ( nchan ) { case IVAS_TD_DECORR_OUT_1CH: case IVAS_TD_DECORR_OUT_2CH: @@ -277,13 +277,13 @@ static int16_t ivas_get_APD_filt_orders( static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, - const int16_t num_out_chans, + const int16_t nchan, const int16_t ducking_flag ) { int16_t i, j; hTdDecorr->ducking_flag = ducking_flag; - hTdDecorr->num_apd_outputs = num_out_chans; + hTdDecorr->num_apd_outputs = nchan; for ( i = 0; i < hTdDecorr->num_apd_outputs; i++ ) { diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index 3968e38974..659738feb9 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -110,7 +110,7 @@ struct apa_state_t uint16_t bad_frame_count; /* # frames before quality threshold is lowered */ uint16_t good_frame_count; /* # scaled frames */ - uint16_t num_channels; /* number of input/output channels */ + uint16_t nchan; /* number of input/output channels */ }; @@ -186,7 +186,7 @@ void apa_reset( ps->last_pitch = 0; ps->bad_frame_count = 0; ps->good_frame_count = 0; - ps->num_channels = 0; + ps->nchan = 0; return; } @@ -196,7 +196,7 @@ void apa_reset( bool apa_set_rate( apa_state_t *ps, const int32_t output_Fs, - const int16_t num_channels ) + const int16_t nchan ) { /* make sure pointer is valid */ if ( ps == NULL ) @@ -217,7 +217,7 @@ bool apa_set_rate( ps->rate = (uint16_t) output_Fs; /* set number of channels */ - ps->num_channels = num_channels; + ps->nchan = nchan; /* * several other parameters depend on the sampling rate @@ -232,7 +232,7 @@ bool apa_set_rate( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = ( ps->rate / 100 ) * ps->num_channels; + ps->l_seg = ( ps->rate / 100 ) * ps->nchan; /* init Hann window */ /* Note: l_win < APA_BUF is required, which is assured */ @@ -244,17 +244,17 @@ bool apa_set_rate( /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->num_channels; + ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->nchan; /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = ( ps->rate / 400 ) * ps->num_channels; + ps->p_min = ( ps->rate / 400 ) * ps->nchan; /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = ( ps->rate / 80 ) * ps->num_channels; + ps->l_search = ( ps->rate / 80 ) * ps->nchan; return 0; } @@ -669,18 +669,18 @@ static void get_scaling_quality( uint16_t i = 0; - for ( i = 0; i < ps->num_channels; i++ ) + for ( i = 0; i < ps->nchan; i++ ) { float energy; offset = 0; - pitch_cn = normalized_cross_correlation_self( signal, pitch + offset, offset, corr_len, ps->num_channels * 2, &pitch_energy ); + pitch_cn = normalized_cross_correlation_self( signal, pitch + offset, offset, corr_len, ps->nchan * 2, &pitch_energy ); if ( pitch_cn > 0.0f ) { /* calculate correlation for double pitch */ if ( 2 * pitch + offset + corr_len <= s_len ) { - double_pitch_cn = normalized_cross_correlation_self( signal, 2 * pitch + offset, offset, corr_len, ps->num_channels * 2, &double_pitch_energy ); + double_pitch_cn = normalized_cross_correlation_self( signal, 2 * pitch + offset, offset, corr_len, ps->nchan * 2, &double_pitch_energy ); } else { @@ -690,7 +690,7 @@ static void get_scaling_quality( /* calculate correlation for three/half pitch */ if ( ( 3 * pitch ) / 2 + offset + corr_len <= s_len ) { - three_halves_pitch_cn = normalized_cross_correlation_self( signal, ( 3 * pitch ) / 2 + offset, offset, corr_len, ps->num_channels * 2, &three_halves_pitch_energy ); + three_halves_pitch_cn = normalized_cross_correlation_self( signal, ( 3 * pitch ) / 2 + offset, offset, corr_len, ps->nchan * 2, &three_halves_pitch_energy ); } else { @@ -700,7 +700,7 @@ static void get_scaling_quality( /* calculate correlation for half pitch */ if ( pitch / 2 + offset + corr_len <= s_len ) { - half_pitch_cn = normalized_cross_correlation_self( signal, pitch / 2 + offset, offset, corr_len, ps->num_channels * 2, &half_pitch_energy ); + half_pitch_cn = normalized_cross_correlation_self( signal, pitch / 2 + offset, offset, corr_len, ps->nchan * 2, &half_pitch_energy ); } else { @@ -820,13 +820,13 @@ static bool logarithmic_search( coeff_max = -FLT_MAX; /* will always be overwritten with result of first correlation */ for ( i = s_start; i < s_start + inlen; i += css ) { - if ( ( wss == 1 ) && ( ps->num_channels == 1 ) ) + if ( ( wss == 1 ) && ( ps->nchan == 1 ) ) { coeff = cross_correlation_self( signal, i + offset, fixed_pos + offset, corr_len ); } else { - coeff = cross_correlation_subsampled_self( signal, i + offset, fixed_pos + offset, corr_len, wss * ps->num_channels ); + coeff = cross_correlation_subsampled_self( signal, i + offset, fixed_pos + offset, corr_len, wss * ps->nchan ); } /* update max corr */ @@ -929,10 +929,10 @@ static bool find_synch( /* pass last pitch to search function as prediction value */ *synch_pos = ps->last_pitch; - logarithmic_search( ps, in, s_start, s_len, offset, fixed_pos, corr_len, ps->wss, ps->css * ps->num_channels, synch_pos ); + logarithmic_search( ps, in, s_start, s_len, offset, fixed_pos, corr_len, ps->wss, ps->css * ps->nchan, synch_pos ); /* assert synch_pos is cleanly divisible by number of channels */ - assert( *synch_pos % ps->num_channels == 0 ); + assert( *synch_pos % ps->nchan == 0 ); *quality = 0; get_scaling_quality( ps, in, l_in, offset, corr_len, (uint16_t) abs( fixed_pos - *synch_pos ), energy, quality ); @@ -1035,7 +1035,7 @@ static bool shrink_frm( frm_in += l_frm; /* set search range */ - s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + s_start = ( ps->p_min / ps->nchan ) * ps->nchan; s_end = s_start + ps->l_search; if ( ( s_end + l_seg ) >= l_frm ) { @@ -1055,7 +1055,7 @@ static bool shrink_frm( else { /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ - xtract = s_end - ps->num_channels; + xtract = s_end - ps->nchan; } } else @@ -1065,7 +1065,7 @@ static bool shrink_frm( } /* assert synch_pos is cleanly divisible by number of channels */ - assert( xtract % ps->num_channels == 0 ); + assert( xtract % ps->nchan == 0 ); /* set frame overlappable - reset if necessary */ over = 1; @@ -1104,7 +1104,7 @@ static bool shrink_frm( { return 1; } - overlapAdd( frm_in, frm_in + xtract, frm_out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + overlapAdd( frm_in, frm_in + xtract, frm_out, l_seg, ps->nchan, ps->win + ps->l_halfwin, ps->win ); } else { @@ -1256,7 +1256,7 @@ static bool extend_frm( /* maximum scaling */ energy = -65; quality = 5; - xtract[n] = s_start + ps->num_channels; + xtract[n] = s_start + ps->nchan; } else { @@ -1264,7 +1264,7 @@ static bool extend_frm( findSynchResult = find_synch( ps, frm_in, 2 * l_frm, s_start, s_end - s_start, sync_start, l_seg, l_frm, &energy, &quality, &xtract[n] ); } /* assert synch_pos is cleanly divisible by number of channels */ - assert( xtract[n] % ps->num_channels == 0 ); + assert( xtract[n] % ps->nchan == 0 ); /* test for sufficient quality */ if ( quality < ( ps->targetQuality - ( ps->bad_frame_count * 0.1f ) + ( ps->good_frame_count * 0.2f ) ) ) @@ -1313,7 +1313,7 @@ static bool extend_frm( fadeOut = frm_in + l_frm + xtract[n - 1] + l_seg; fadeIn = frm_in + l_frm + xtract[n]; out = frm_out + ( n - 2 ) * l_seg; - overlapAdd( fadeOut, fadeIn, out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + overlapAdd( fadeOut, fadeIn, out, l_seg, ps->nchan, ps->win + ps->l_halfwin, ps->win ); } else { diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index 5cf4e7d8b6..5297c799b9 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -101,9 +101,9 @@ void apa_reset( apa_state_t *s ); * Will also set a number of other state variables that depend on the sampling rate. * @param[in,out] ps state * @param[in] output_Fs sample rate [Hz] - * @param[in] num_channels number of channels + * @param[in] nchan number of channels * @return 0 on success, 1 on failure */ -bool apa_set_rate( apa_state_t *ps, const int32_t output_Fs, const int16_t num_channels ); +bool apa_set_rate( apa_state_t *ps, const int32_t output_Fs, const int16_t nchan ); /*! Set scaling. * The scale is given in % and will be valid until changed again. diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 907b8c5908..c49154e4a6 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -156,7 +156,7 @@ void ivas_enc_cov_handler_process( const int16_t end_band #ifdef SBA_SPAR_HARM , - const int16_t num_ch, + const int16_t nchan, const int16_t dtx_vad, const int16_t transient_det #endif @@ -169,15 +169,15 @@ void ivas_enc_cov_handler_process( dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; #else ivas_cov_smooth_in_buf_t pCov_in_buf; - int16_t num_ch = pIn_buf->num_ch; + int16_t nchan = pIn_buf->nchan; - pCov_in_buf.num_ch = num_ch; + pCov_in_buf.nchan = nchan; #endif #ifdef SBA_SPAR_HARM - ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, num_ch, hCovEnc->num_bins, + ivas_band_cov( ppIn_FR_real, ppIn_FR_imag, nchan, hCovEnc->num_bins, #else - ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->num_ch, hCovEnc->num_bins, + ivas_band_cov( pIn_buf->ppIn_FR_real, pIn_buf->ppIn_FR_imag, pIn_buf->nchan, hCovEnc->num_bins, #endif pFb->fb_bin_to_band.short_stride, pFb->fb_bin_to_band.pp_short_stride_bin_to_band, @@ -196,9 +196,9 @@ void ivas_enc_cov_handler_process( fid = fopen( "cov_real.txt", "wt" ); } - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -209,9 +209,9 @@ void ivas_enc_cov_handler_process( fprintf( fid, "\n" ); } #endif - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { #ifndef SBA_SPAR_HARM pCov_in_buf.cov_real[i][j] = cov_real[i][j]; @@ -221,7 +221,7 @@ void ivas_enc_cov_handler_process( } #ifdef SBA_SPAR_HARM - ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, num_ch, transient_det ); + ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, nchan, transient_det ); #else ivas_cov_smooth_process( hCovEnc->pCov_state, &pCov_in_buf, pFb, start_band, end_band ); #endif @@ -232,9 +232,9 @@ void ivas_enc_cov_handler_process( if ( pIn_buf->dtx_cov_flag == 0 ) #endif { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { #ifdef SBA_SPAR_HARM mvr2r( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); @@ -257,11 +257,11 @@ void ivas_enc_cov_handler_process( #endif { #ifdef SBA_SPAR_HARM - ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); + ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, nchan, transient_det ); #else - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; } @@ -277,11 +277,11 @@ void ivas_enc_cov_handler_process( if ( hCovEnc->prior_dtx_present == 0 ) { #ifdef SBA_SPAR_HARM - ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); + ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, nchan, transient_det ); #else - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { pCov_in_buf.cov_real[i][j] = cov_dtx_real[i][j]; } @@ -294,9 +294,9 @@ void ivas_enc_cov_handler_process( } else { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { mvr2r( hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index af7a48a80b..844a3c19bf 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -53,19 +53,19 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_param_mc_dmx( PARAM_MC_ENC_HANDLE hParamMC, float data_f[][L_FRAME48k], float data_dmx[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_dmx( PARAM_MC_ENC_HANDLE hParamMC, float data_f[][L_FRAME48k], float data_dmx[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp, const int16_t nchan_transport ); -static void ivas_param_mc_param_est_enc( PARAM_MC_ENC_HANDLE hParamMC, float input_frame_t[][L_FRAME48k], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t input_frame, const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_param_est_enc( PARAM_MC_ENC_HANDLE hParamMC, float input_frame_t[][L_FRAME48k], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t input_frame, const int16_t nchan_inp, const int16_t nchan_transport ); static void ivas_param_mc_parameter_quantizer( const float *x, const int16_t L, const int16_t sz_quantizer, const float *quantizer, int16_t *quant_idx, float *y ); static void ivas_param_mc_transient_detection( PARAM_MC_ENC_HANDLE hParamMC, TRAN_DET_HANDLE hTranDet, int16_t *bAttackPresent, int16_t *attackIdx ); -static void ivas_param_mc_enc_find_icc_map( PARAM_MC_ENC_HANDLE hParamMC, float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_enc_find_icc_map( PARAM_MC_ENC_HANDLE hParamMC, float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], const int16_t nchan_inp, const int16_t nchan_transport ); -static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_input, int16_t *ICC_idx_out ); +static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_inp, int16_t *ICC_idx_out ); -static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_input, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); +static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_inp, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); static void ivas_param_mc_write_bs( const PARAM_MC_ENC_HANDLE hParamMC, int16_t *ILD_idx, int16_t *ICC_idx, uint16_t bit_buffer[PARAM_MC_MAX_BITS], int16_t *bit_pos ); @@ -430,7 +430,7 @@ static void ivas_param_mc_dmx( float data_f[][L_FRAME48k], /* i : Input frame */ float data_dmx[][L_FRAME48k], /* o : Down mixed frame */ const int16_t input_frame, /* i : Input frame length */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport /* i : number of transport channels */ ) { @@ -448,7 +448,7 @@ static void ivas_param_mc_dmx( { float *dmx_sample = &data_dmx[idx[dmx_ch]][i]; *dmx_sample = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) + for ( inp_ch = 0; inp_ch < nchan_inp; inp_ch++ ) { ( *dmx_sample ) += data_f[idx[inp_ch]][i] * ( *( p_dmx_fac++ ) ); } @@ -472,7 +472,7 @@ static void ivas_param_mc_param_est_enc( float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* o : Covariance matrix for the original frame */ float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* o : Covariance matrix for the downmixed frame */ const int16_t input_frame, /* i : Input frame length */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport /* i : number of transport channels */ ) { @@ -525,7 +525,7 @@ static void ivas_param_mc_param_est_enc( } /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_input; i++ ) + for ( i = 0; i < nchan_inp; i++ ) { idx_ls = map_ls[i]; pcm_in[i] = &input_frame_t[idx_ls][0]; @@ -536,7 +536,7 @@ static void ivas_param_mc_param_est_enc( for ( ts = 0; ts < start_ts; ts++ ) { ivas_fb_mixer_update_prior_input( hParamMC->hFbMixer, pcm_in, l_ts ); - for ( i = 0; i < nchan_input; i++ ) + for ( i = 0; i < nchan_inp; i++ ) { pcm_in[i] += l_ts; } @@ -546,7 +546,7 @@ static void ivas_param_mc_param_est_enc( { ivas_fb_mixer_get_windowed_fr( hParamMC->hFbMixer, pcm_in, p_slot_frame_f_real, p_slot_frame_f_imag, l_ts, 2 * l_ts ); ivas_fb_mixer_update_prior_input( hParamMC->hFbMixer, pcm_in, l_ts ); - for ( i = 0; i < nchan_input; i++ ) + for ( i = 0; i < nchan_inp; i++ ) { pcm_in[i] += l_ts; } @@ -566,7 +566,7 @@ static void ivas_param_mc_param_est_enc( { dmx_real[ch_idx1] = 0.0f; dmx_imag[ch_idx1] = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) + for ( inp_ch = 0; inp_ch < nchan_inp; inp_ch++ ) { dmx_real[ch_idx1] += slot_frame_f_real[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); dmx_imag[ch_idx1] += slot_frame_f_imag[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); @@ -591,9 +591,9 @@ static void ivas_param_mc_param_est_enc( } /* Cy for input channels */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { a = slot_frame_f_real[ch_idx1][cur_cldfb_band]; b = slot_frame_f_imag[ch_idx1][cur_cldfb_band]; @@ -624,7 +624,7 @@ static void ivas_param_mc_param_est_enc( dmx_real[ch_idx1] = 0.0f; dmx_imag[ch_idx1] = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_input; inp_ch++ ) + for ( inp_ch = 0; inp_ch < nchan_inp; inp_ch++ ) { dmx_real[ch_idx1] += slot_frame_f_real[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); dmx_imag[ch_idx1] += slot_frame_f_imag[inp_ch][cur_cldfb_band] * ( *p_dmx_fac ); @@ -648,9 +648,9 @@ static void ivas_param_mc_param_est_enc( } /* Cy for input channels */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { a = slot_frame_f_real[ch_idx1][cur_cldfb_band]; b = slot_frame_f_imag[ch_idx1][cur_cldfb_band]; @@ -671,7 +671,7 @@ static void ivas_param_mc_param_est_enc( { for ( cur_param_band = PARAM_MC_MAX_BAND_LFE; cur_param_band < hParamMC->max_param_band_abs_cov; cur_param_band++ ) { - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { Cy_sum[cur_param_band][hParamMC->lfe_index][ch_idx1] = 0.0f; Cy_sum[cur_param_band][ch_idx1][hParamMC->lfe_index] = 0.0f; @@ -682,7 +682,7 @@ static void ivas_param_mc_param_est_enc( for ( ; cur_param_band < num_parameter_bands; cur_param_band++ ) { - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { Cy_sum[cur_param_band][hParamMC->lfe_index][ch_idx1] = 0.0f; Cy_sum[cur_param_band][ch_idx1][hParamMC->lfe_index] = 0.0f; @@ -704,9 +704,9 @@ static void ivas_param_mc_param_est_enc( } } - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { Cy_sum[cur_param_band - 1][ch_idx1][ch_idx2] += Cy_sum[cur_param_band][ch_idx1][ch_idx2]; Cy_sum_imag[cur_param_band - 1][ch_idx1][ch_idx2] += Cy_sum_imag[cur_param_band][ch_idx1][ch_idx2]; @@ -726,9 +726,9 @@ static void ivas_param_mc_param_est_enc( } } - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ++ch_idx2 ) { Cy_sum[cur_param_band - 1][ch_idx1][ch_idx2] += Cy_sum[cur_param_band][ch_idx1][ch_idx2]; } @@ -756,9 +756,9 @@ static void ivas_param_mc_param_est_enc( } /* Cy for transport channels */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ch_idx1++ ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ch_idx1++ ) { - for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_input; ch_idx2++ ) + for ( ch_idx2 = ch_idx1; ch_idx2 < nchan_inp; ch_idx2++ ) { real_part = Cy_sum[cur_param_band][ch_idx1][ch_idx2]; imag_part = Cy_sum_imag[cur_param_band][ch_idx1][ch_idx2]; @@ -794,7 +794,7 @@ static void ivas_param_mc_enc_find_icc_map( float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* i : Covariance matrix for the downmixed frame */ float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix for the original frame */ float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], /* i : quantized ILDs */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport /* i : number of transport channels */ ) { @@ -824,7 +824,7 @@ static void ivas_param_mc_enc_find_icc_map( icc_map_size_wo_lfe = hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_wo_lfe; icc_map_size = hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_lfe; - set_zero( Cy_band, nchan_input * nchan_input ); + set_zero( Cy_band, nchan_inp * nchan_inp ); /* Estimate the target covariance like in the decoder using the * already available qunantised ICLDs */ @@ -842,18 +842,18 @@ static void ivas_param_mc_enc_find_icc_map( } /* get estimated Cy from Cx and proto matrix */ - matrix_product( hParamMC->dmx_factors, nchan_input, nchan_transport, 0, + matrix_product( hParamMC->dmx_factors, nchan_inp, nchan_transport, 0, Cx_band, nchan_transport, nchan_transport, 0, mat_mult_buffer1 ); - matrix_product( mat_mult_buffer1, nchan_input, nchan_transport, 0, - hParamMC->dmx_factors, nchan_input, nchan_transport, 1, + matrix_product( mat_mult_buffer1, nchan_inp, nchan_transport, 0, + hParamMC->dmx_factors, nchan_inp, nchan_transport, 1, Cproto_band ); set_zero( Nrqq, MAX_OUTPUT_CHANNELS ); /*get back Nrg*/ - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { float ref_ener = 0.0f; int16_t ref_channel_cnt; @@ -868,51 +868,51 @@ static void ivas_param_mc_enc_find_icc_map( } /* apply quantized ICLDs in the estimated covariance */ - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { - a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cproto_band[k + nchan_input * k] ) + EPSILON ); - v_multc( Cproto_band + k * nchan_input, a[k], Cproto_band + k * nchan_input, nchan_input ); + a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cproto_band[k + nchan_inp * k] ) + EPSILON ); + v_multc( Cproto_band + k * nchan_inp, a[k], Cproto_band + k * nchan_inp, nchan_inp ); } - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { int16_t l; float *Cyp = Cproto_band + k; float ap = a[k]; - for ( l = 0; l < nchan_input; l++ ) + for ( l = 0; l < nchan_inp; l++ ) { ( *Cyp ) *= ap; - Cyp += nchan_input; + Cyp += nchan_inp; } } /* transfer Cy_sum band to columnwise matrix */ - for ( ch_idx1 = 0; ch_idx1 < nchan_input; ++ch_idx1 ) + for ( ch_idx1 = 0; ch_idx1 < nchan_inp; ++ch_idx1 ) { - for ( ch_idx2 = 0; ch_idx2 < nchan_input; ++ch_idx2 ) + for ( ch_idx2 = 0; ch_idx2 < nchan_inp; ++ch_idx2 ) { Cy_band[ch_idx1 + nchan_transport * ch_idx2] = Cy_sum[cur_param_band][ch_idx1][ch_idx2]; } } /* apply quantized ICLDs on the input covariance */ - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { - a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cy_band[k + nchan_input * k] ) + EPSILON ); - v_multc( Cy_band + k * nchan_input, a[k], Cy_band + k * nchan_input, nchan_input ); + a[k] = sqrtf( Nrqq[k] ) / ( sqrtf( Cy_band[k + nchan_inp * k] ) + EPSILON ); + v_multc( Cy_band + k * nchan_inp, a[k], Cy_band + k * nchan_inp, nchan_inp ); } - for ( k = 0; k < nchan_input; k++ ) + for ( k = 0; k < nchan_inp; k++ ) { int16_t l; float *Cyp = Cy_band + k; float ap = a[k]; - for ( l = 0; l < nchan_input; l++ ) + for ( l = 0; l < nchan_inp; l++ ) { ( *Cyp ) *= ap; - Cyp += nchan_input; + Cyp += nchan_inp; } } @@ -921,7 +921,7 @@ static void ivas_param_mc_enc_find_icc_map( { int16_t idx0 = hParamMC->hMetadataPMC.icc_map_full[0][map_idx]; int16_t idx1 = hParamMC->hMetadataPMC.icc_map_full[1][map_idx]; - mapped_error[map_idx] += fabsf( Cproto_band[idx0 + idx1 * nchan_input] - Cy_band[idx0 + idx1 * nchan_input] ); + mapped_error[map_idx] += fabsf( Cproto_band[idx0 + idx1 * nchan_inp] - Cy_band[idx0 + idx1 * nchan_inp] ); } } } @@ -1018,7 +1018,7 @@ static void ivas_param_mc_quantize_ilds( float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* i : Covariance matrix of the dmx */ const int16_t freq_idx, /* i : frequency index being processed */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t nchan_transport, /* i : number of transport channels */ int16_t *ILD_idx_out, /* o : ILD indices */ float ILD_q[PARAM_MC_SZ_ILD_MAP] /* o : Quanzited ILD matrix */ @@ -1040,7 +1040,7 @@ static void ivas_param_mc_quantize_ilds( set_zero( Nrg, MAX_CICP_CHANNELS ); set_zero( ILD, PARAM_MC_SZ_ILD_MAP ); - Ny = nchan_input; + Ny = nchan_inp; h_ild_mapping = hParamMC->hMetadataPMC.ild_mapping_conf; ild_map_size = hParamMC->hMetadataPMC.ild_mapping_conf->ild_map_size_lfe; @@ -1159,7 +1159,7 @@ static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ const int16_t freq_idx, /* i : frequency index being processed */ - const int16_t nchan_input, /* i : number of input channels */ + const int16_t nchan_inp, /* i : number of input channels */ int16_t *ICC_idx_out /* o : quantizer indices */ ) { @@ -1179,7 +1179,7 @@ static void ivas_param_mc_quantize_iccs( set_zero( ICC_vect, PARAM_MC_SZ_ICC_MAP ); set_zero( ICC_vect_q, PARAM_MC_SZ_ICC_MAP ); - Ny = nchan_input; + Ny = nchan_inp; /* Downsampling */ if ( ( hParamMC->hMetadataPMC.bAttackPresent == 0 ) && ( hParamMC->hMetadataPMC.param_frame_idx != hParamMC->hMetadataPMC.coding_band_mapping[freq_idx] ) ) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6c17a5711e..e863f3ded9 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -213,7 +213,8 @@ void ivas_spar_enc_close( const int16_t nchan_inp /* i : number of input channels */ ) { - int16_t num_chans; + int16_t nchan; + if ( hSpar != NULL ) { /* core-coder-VAD handle */ @@ -231,14 +232,14 @@ void ivas_spar_enc_close( } - num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans; - assert( num_chans <= nchan_inp ); + nchan = hSpar->hFbMixer->fb_cfg->nchan_inp; + assert( nchan <= nchan_inp ); /* MD handle */ ivas_spar_md_enc_close( &hSpar->hMdEnc ); /* Covar. State handle */ - ivas_spar_covar_enc_close( &hSpar->hCovEnc, num_chans ); + ivas_spar_covar_enc_close( &hSpar->hCovEnc, nchan ); /* FB mixer handle */ ivas_FB_mixer_close( &hSpar->hFbMixer, input_Fs ); @@ -527,7 +528,7 @@ static ivas_error ivas_spar_enc_process( } #ifndef SBA_SPAR_HARM - cov_in_buf.num_ch = nchan_inp; + cov_in_buf.nchan = nchan_inp; #endif dtx_vad = ( hEncoderConfig->Opt_DTX_ON == 1 ) ? front_vad_flag : 1; @@ -645,7 +646,7 @@ static ivas_error ivas_spar_enc_process( *-----------------------------------------------------------------------------------------*/ #ifndef SBA_SPAR_HARM - cov_in_buf.num_ch = nchan_inp; + cov_in_buf.nchan = nchan_inp; #endif for ( i = 0; i < nchan_inp; i++ ) { @@ -793,9 +794,9 @@ static ivas_error ivas_spar_enc_process( if ( f_mat == 0 ) f_mat = fopen( "mixer_mat_enc", "w" ); - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->nchan_out; i++ ) { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->nchan_inp; j++ ) { for ( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) { @@ -878,7 +879,7 @@ static ivas_error ivas_spar_enc_process( { if ( hEncoderConfig->Opt_AGC_ON > 0 ) { - ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); + ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->nchan_out, hEncoderConfig ); } else { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 7ae45903d5..6b8e43ba87 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -68,7 +68,7 @@ typedef enum ivas_strats_t * Static functions declaration *------------------------------------------------------------------------------------------*/ -static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t num_ch, int16_t *num_bands, int16_t red_band_fact ); +static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t nchan, int16_t *num_bands, int16_t red_band_fact ); static void ivas_get_band_differential_index( ivas_band_coeffs_ind_t *pBand_idx, const int16_t q_levels[2], const int16_t one_sided, const int16_t nB, const int16_t complex_cov, const int16_t dim, const ivas_coeffs_type_t coeff_type ); @@ -86,14 +86,14 @@ static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, cons static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); -static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); +static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t nchan ); static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); -static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); +static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t nchan ); static void ivas_quant_c_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t ndec, const int16_t ndm ); -static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); +static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t nchan ); /*------------------------------------------------------------------------- @@ -110,7 +110,7 @@ ivas_error ivas_spar_md_enc_open( { ivas_spar_md_enc_state_t *hMdEnc; ivas_error error; - int16_t num_channels, i, j; + int16_t nchan, i, j; error = IVAS_ERR_OK; @@ -119,23 +119,23 @@ ivas_error ivas_spar_md_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } - num_channels = 2 * sba_order + 2; + nchan = 2 * sba_order + 2; if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdEnc->mixer_mat = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->mixer_mat[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->mixer_mat[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -144,17 +144,17 @@ ivas_error ivas_spar_md_enc_open( } } - if ( ( hMdEnc->cov_real = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->cov_real = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->cov_real[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->cov_real[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->cov_real[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -163,17 +163,17 @@ ivas_error ivas_spar_md_enc_open( } } - if ( ( hMdEnc->cov_dtx_real = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->cov_dtx_real = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->cov_dtx_real[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->cov_dtx_real[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->cov_dtx_real[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -182,17 +182,17 @@ ivas_error ivas_spar_md_enc_open( } } - if ( ( hMdEnc->mixer_mat_local = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat_local = (float ***) count_malloc( nchan * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - if ( ( hMdEnc->mixer_mat_local[i] = (float **) count_malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdEnc->mixer_mat_local[i] = (float **) count_malloc( nchan * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { if ( ( hMdEnc->mixer_mat_local[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { @@ -222,11 +222,11 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) { - int16_t num_channels, i, j; + int16_t nchan, i, j; ivas_spar_md_enc_state_t *hMdEnc; hMdEnc = *hMdEnc_in; - num_channels = hMdEnc->num_umx_ch; + nchan = hMdEnc->num_umx_ch; if ( hMdEnc->spar_md.band_coeffs != NULL ) { @@ -235,9 +235,9 @@ void ivas_spar_md_enc_close( } if ( hMdEnc->mixer_mat != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->mixer_mat[i][j] ); } @@ -248,10 +248,10 @@ void ivas_spar_md_enc_close( if ( hMdEnc->cov_real != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->cov_real[i][j] ); } @@ -262,10 +262,10 @@ void ivas_spar_md_enc_close( if ( hMdEnc->cov_dtx_real != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->cov_dtx_real[i][j] ); } @@ -276,10 +276,10 @@ void ivas_spar_md_enc_close( if ( hMdEnc->mixer_mat_local != NULL ) { - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { count_free( hMdEnc->mixer_mat_local[i][j] ); } @@ -313,9 +313,9 @@ static ivas_error ivas_spar_md_enc_init( float pFC[IVAS_MAX_NUM_BANDS]; int16_t table_idx; float PR_minmax[2]; - int16_t num_channels, i, j, k; + int16_t nchan, i, j, k; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); @@ -328,7 +328,7 @@ static ivas_error ivas_spar_md_enc_init( pFC[i] = ivas_fb_fcs_12band_1ms[i] * hEncoderConfig->input_Fs * 0.5f; } - ivas_spar_set_enc_config( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels ); + ivas_spar_set_enc_config( hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, nchan ); /* if(hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].C.q_levels[1] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[0] == 0 || hMdEnc->spar_md_cfg.quant_strat[0].PR.q_levels[1] == 0 @@ -362,9 +362,9 @@ static ivas_error ivas_spar_md_enc_init( hMdEnc->spar_md_cfg.prior_strat = START; hMdEnc->spar_md_cfg.prev_quant_idx = -1; - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -373,9 +373,9 @@ static ivas_error ivas_spar_md_enc_init( } } - for ( i = 0; i < num_channels; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_channels; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { @@ -451,7 +451,7 @@ static ivas_error ivas_spar_set_enc_config( static void ivas_band_limit_dmx_matrix( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, + const int16_t nchan, const int16_t num_bands, const int16_t bands_bw ) { @@ -461,9 +461,9 @@ static void ivas_band_limit_dmx_matrix( { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; - for ( i = ndm; i < num_ch; i++ ) + for ( i = ndm; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { hMdEnc->mixer_mat[i][j][b] = 0; } @@ -482,7 +482,7 @@ static void ivas_band_limit_dmx_matrix( static void ivas_band_mixing( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const int16_t num_ch, + const int16_t nchan, const int16_t num_bands, const int16_t nchan_transport, const int16_t upmixed_bands ) @@ -494,7 +494,7 @@ static void ivas_band_mixing( for ( i = 0; i < nchan_transport; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = num_bands - 1; k >= 0; k-- ) { @@ -571,7 +571,7 @@ ivas_error ivas_spar_md_enc_process( float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - int16_t i, b, qsi, ndm, ndec, num_ch, num_quant_strats; + int16_t i, b, qsi, ndm, ndec, nchan, num_quant_strats; int16_t j, planarCP; #ifdef SBA_SPAR_HARM int16_t k, bwidth, num_bands, num_bands_full, num_bands_bw; @@ -589,7 +589,7 @@ ivas_error ivas_spar_md_enc_process( float Wscale[IVAS_MAX_NUM_BANDS]; num_quant_strats = hMdEnc->spar_md_cfg.num_quant_strats; - num_ch = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); active_w = hMdEnc->spar_md_cfg.active_w; nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; @@ -660,9 +660,9 @@ ivas_error ivas_spar_md_enc_process( bands_bw = num_bands / nB; #ifdef SBA_SPAR_HARM - ivas_band_mixer( cov_real, num_ch, &num_bands, bands_bw ); + ivas_band_mixer( cov_real, nchan, &num_bands, bands_bw ); #else - ivas_band_mixer( pIn_buf->cov_real, num_ch, &num_bands, bands_bw ); + ivas_band_mixer( pIn_buf->cov_real, nchan, &num_bands, bands_bw ); #endif } else @@ -672,16 +672,16 @@ ivas_error ivas_spar_md_enc_process( } #ifdef SBA_SPAR_HARM - ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, + ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, nchan, bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); #else - ivas_compute_spar_params( pIn_buf->cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, + ivas_compute_spar_params( pIn_buf->cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, nchan, bands_bw, active_w, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0 ); #endif - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( b = 0; b < num_bands; b++ ) { @@ -722,12 +722,12 @@ ivas_error ivas_spar_md_enc_process( { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; - if ( ndm != num_ch ) + if ( ndm != nchan ) { #ifdef SBA_SPAR_HARM - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat_local, nchan, ndm, b, dtx_vad, 1, planarCP ); #else - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, num_ch, ndm, b, dtx_vad, 1, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat_local, nchan, ndm, b, dtx_vad, 1, planarCP ); #endif } } @@ -739,7 +739,7 @@ ivas_error ivas_spar_md_enc_process( if ( dtx_vad == 1 ) { - if ( ndm != num_ch ) + if ( ndm != nchan ) { #ifdef SPAR_HOA_DBG /* fprintf(stderr, "\n\n P coefficients: band %d\n", b); @@ -779,27 +779,27 @@ ivas_error ivas_spar_md_enc_process( #endif } - ivas_quant_p_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); + ivas_quant_p_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], nchan ); } - ivas_quant_pred_coeffs_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); + ivas_quant_pred_coeffs_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], nchan ); } else { - if ( ndm != num_ch ) + if ( ndm != nchan ) { - ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, num_ch ); + ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, nchan ); } - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; } - ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, num_ch - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re ); + ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, nchan - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re ); } } - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { for ( b = 0; b < num_bands; b++ ) { @@ -807,29 +807,29 @@ ivas_error ivas_spar_md_enc_process( } } - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); + ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, hMdEnc->mixer_mat, nchan, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); for ( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[b * bands_bw]; - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { hMdEnc->mixer_mat[0][i][b] *= Wscale[b]; } - if ( ( ndm != num_ch ) && ( ndm != 1 ) ) + if ( ( ndm != nchan ) && ( ndm != 1 ) ) { #ifdef SBA_SPAR_HARM - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, nchan, ndm, b, dtx_vad, 0, planarCP ); #else - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, planarCP ); + ivas_calc_c_p_coeffs( &hMdEnc->spar_md, pIn_buf->cov_real, 0, hMdEnc->mixer_mat, nchan, ndm, b, dtx_vad, 0, planarCP ); #endif #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n C coefficients: band %d\n", b); - for (i = 0; i < num_ch - ndm; i++) + for (i = 0; i < nchan - ndm; i++) { for (j = 0; j < ndm - 1; j++) { @@ -841,7 +841,7 @@ ivas_error ivas_spar_md_enc_process( #endif if ( planarCP ) { - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { if ( !keep_planar[i] ) { @@ -854,7 +854,7 @@ ivas_error ivas_spar_md_enc_process( #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n Planar C coefficients: band %d\n", b); - for (i = 0; i < num_ch - ndm; i++) + for (i = 0; i < nchan - ndm; i++) { for (j = 0; j < ndm - 1; j++) { @@ -881,15 +881,15 @@ ivas_error ivas_spar_md_enc_process( } /* band limit downmix matrix */ - ivas_band_limit_dmx_matrix( hMdEnc, num_ch, num_bands, bands_bw ); + ivas_band_limit_dmx_matrix( hMdEnc, nchan, num_bands, bands_bw ); /* band mixing */ if ( bands_bw > 1 ) { #ifdef SBA_SPAR_HARM - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); + ivas_band_mixing( hMdEnc, nchan, num_bands, nchan_transport, num_bands_full ); #else - ivas_band_mixing( hMdEnc, num_ch, num_bands, nchan_transport, pIn_buf->num_bands ); + ivas_band_mixing( hMdEnc, nchan, num_bands, nchan_transport, pIn_buf->num_bands ); #endif } @@ -950,7 +950,7 @@ ivas_error ivas_spar_md_enc_process( { b = 0; fprintf( stdout, "\n\nMETADATA PR: band %d, qsi %d\n\n", b, qsi ); - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { fprintf( stdout, "i: %d -- %f\t %d\t %d\n", i, //hMdEnc->spar_md.band_coeffs[b].pred_re[i], hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i], @@ -971,7 +971,7 @@ ivas_error ivas_spar_md_enc_process( } } fprintf( stdout, "\n\n METADATA Pd: band %d\n\n", b ); - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { fprintf( stdout, "i: %d -- %f\t %d\t %d\n", i, //hMdEnc->spar_md.band_coeffs[b].P_re[i][i], hMdEnc->spar_md.band_coeffs[b].P_quant_re[i][i], @@ -985,10 +985,10 @@ ivas_error ivas_spar_md_enc_process( ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; fprintf( stdout, "\n\n Metadata PR (15x1), C(15x15), P(15x15): band %d\n", b ); - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { fprintf( stdout, "i: %d -- %.2f\t|\t", i, hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] ); - if ( i < num_ch - ndm ) + if ( i < nchan - ndm ) { if ( keep_planar[i] == 1 ) { @@ -1003,7 +1003,7 @@ ivas_error ivas_spar_md_enc_process( fprintf( stdout, "%.2f\t", hMdEnc->spar_md.band_coeffs[b].C_quant_re[i][j] ); } fprintf( stdout, "|\t" ); - for ( j = 0; j < num_ch - ndm; j++ ) + for ( j = 0; j < nchan - ndm; j++ ) { fprintf( stdout, "%.2f\t", hMdEnc->spar_md.band_coeffs[b].P_quant_re[j] ); } @@ -1035,12 +1035,12 @@ ivas_error ivas_spar_md_enc_process( { sprintf( f_name, "spar_band_pred_coeffs.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].pred_re[i], sizeof( float ), 1, 1, f_name ); } @@ -1060,23 +1060,23 @@ ivas_error ivas_spar_md_enc_process( } sprintf( f_name, "spar_band_P_coeffs.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - ndm; + num_elements = nchan - ndm; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].P_re[i], sizeof( float ), 1, 1, f_name ); } sprintf( f_name, "spar_band_pred_coeffs_quant.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - 1; + num_elements = nchan - 1; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - 1; i++ ) + for ( i = 0; i < nchan - 1; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i], sizeof( float ), 1, 1, f_name ); } @@ -1096,12 +1096,12 @@ ivas_error ivas_spar_md_enc_process( } sprintf( f_name, "spar_band_P_coeffs_quant.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; - num_elements = num_ch - ndm; + num_elements = nchan - ndm; ( b == 0 && frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &num_block_groups, sizeof( num_block_groups ), 1, 1, f_name ) : false; ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - for ( i = 0; i < num_ch - ndm; i++ ) + for ( i = 0; i < nchan - ndm; i++ ) { dbgwrite( &hMdEnc->spar_md.band_coeffs[b].P_quant_re[i], sizeof( float ), 1, 1, f_name ); } @@ -1136,7 +1136,7 @@ ivas_error ivas_spar_md_enc_process( static void ivas_band_mixer( float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, + const int16_t nchan, int16_t *num_bands, int16_t red_band_fact ) { @@ -1147,9 +1147,9 @@ static void ivas_band_mixer( *num_bands /= red_band_fact; rem_band = orig_band - ( *num_bands * red_band_fact ); - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < num_ch; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( k = 0; k < *num_bands - 1; k++ ) { @@ -1608,11 +1608,11 @@ static void ivas_quant_p_per_band_dtx( const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, - const int16_t num_ch ) + const int16_t nchan ) { int16_t i; - int16_t dim = num_ch - num_dmx; - if ( num_dec == num_ch - 1 ) + int16_t dim = nchan - num_dmx; + if ( num_dec == nchan - 1 ) { for ( i = 0; i < dim; i++ ) { @@ -1629,7 +1629,7 @@ static void ivas_quant_p_per_band_dtx( } for ( i = 0; i < dim; i++ ) { - ivas_quantise_real_values( &pP_mat[i], dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &ppIdx_pd[i], &pP_out[i], 1 ); + ivas_quantise_real_values( &pP_mat[i], dtx_pd_real_q_levels[nchan - num_dec - 1][i], dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &ppIdx_pd[i], &pP_out[i], 1 ); } return; } @@ -1758,9 +1758,9 @@ static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, - const int16_t num_ch ) + const int16_t nchan ) { - ivas_quantise_real_values( pband_coeffs->pred_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re, ( num_ch - 1 ) ); + ivas_quantise_real_values( pband_coeffs->pred_re, pQs->PR.q_levels[0], pQs->PR.min, pQs->PR.max, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re, ( nchan - 1 ) ); return; } @@ -1836,7 +1836,7 @@ static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, - const int16_t num_ch ) + const int16_t nchan ) { #ifdef SPAR_HOA_DBG /*fprintf(stderr, "\n\n P_d:\n"); @@ -1846,6 +1846,6 @@ static void ivas_quant_p_per_band( } fprintf(stderr, "\n\n");*/ #endif - ivas_quantise_real_values( pband_coeffs->P_re, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re, num_ch - 1 ); + ivas_quantise_real_values( pband_coeffs->P_re, pQs->P_r.q_levels[0], pQs->P_r.min, pQs->P_r.max, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re, nchan - 1 ); return; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index a4e8e1142a..d13da5794a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -634,7 +634,7 @@ typedef struct ivas_enc_cov_handler_in_buf_t { float *ppIn_FR_real[IVAS_SPAR_MAX_CH]; float *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; - int16_t num_ch; + int16_t nchan; int16_t transient_det; int16_t dtx_cov_flag; diff --git a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c index d993405b11..ee73254126 100644 --- a/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c +++ b/scripts/ivas_pytests/tests/unit_tests/crend/ivas_crend_utest_utils.c @@ -181,47 +181,47 @@ const char *ivas_crend_map_in_fmt( int16_t ivas_get_num_channels( const int16_t ch_format ) { - int16_t num_channels = 0; + int16_t nchan = 0; switch ( ch_format ) { case MONO_1: - num_channels = 1; + nchan = 1; break; case BIN_2: case STEREO_2: - num_channels = 2; + nchan = 2; break; case FOA_4: - num_channels = FOA_CHANNELS; + nchan = FOA_CHANNELS; break; case MULT_CH_5_1: - num_channels = 6; + nchan = 6; break; case MULT_CH_7_1: - num_channels = 8; + nchan = 8; break; case HOA_9: - num_channels = 9; + nchan = 9; break; case HOA_16: - num_channels = 16; + nchan = 16; break; case OBA: - num_channels = 8; + nchan = 8; break; case MULT_CH_5_1_2: - num_channels = 8; + nchan = 8; break; case MULT_CH_7_1_4: - num_channels = 12; + nchan = 12; break; default: assert( !"Not supported Input format for Common Renderer!" ); break; } - return num_channels; + return nchan; } static ivas_result_t ivas_crend_mixer( -- GitLab From 597532f1fc409338ae5465b1e97f55b4ee55ea85 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 18 Oct 2022 13:19:47 +0200 Subject: [PATCH 18/26] harmonize 'nchan' terminology --- lib_com/ivas_prot.h | 2 +- lib_dec/ivas_binauralRenderer.c | 70 ++++---- lib_dec/ivas_out_setup_conversion.c | 260 ++++++++++++++-------------- lib_dec/ivas_rotation.c | 27 ++- lib_dec/ivas_spar_decoder.c | 10 +- lib_dec/ivas_stat_dec.h | 2 +- lib_enc/ivas_spar_encoder.c | 14 +- 7 files changed, 191 insertions(+), 194 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7e280a082f..77a90ae84c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4594,7 +4594,7 @@ void rotateFrame_shd_cldfb( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part */ float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part */ float Rmat[3][3], /* i : real-space rotation matrix */ - const int16_t nInChannels, /* i : number of channels */ + const int16_t nchan_inp, /* i : number of channels */ const int16_t shd_rot_max_order /* i : split-order rotation method */ ); diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 45108a92fa..89626b7523 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -66,7 +66,7 @@ static void ivas_binRenderer_filterModule( for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nchan_inp; chIdx++ ) { filterStatesLeftRealPtr = (float *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx][0] ); filterStatesLeftImagPtr = (float *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx][0] ); @@ -140,11 +140,11 @@ static ivas_error ivas_binRenderer_convModuleOpen( if ( !isLoudspeaker ) { - hBinRenderer->nInChannels = 16; + hBinRenderer->nchan_inp = 16; } else { - hBinRenderer->nInChannels = ( audioCfg2channels( input_config ) - isLoudspeaker ); // TODO maybe an audioCfg2channels_woLFE() function? Works as long as only 1 LFE is present + hBinRenderer->nchan_inp = ( audioCfg2channels( input_config ) - isLoudspeaker ); // TODO maybe an audioCfg2channels_woLFE() function? Works as long as only 1 LFE is present } if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && hRenderConfig->roomAcoustics.use_brir ) @@ -209,22 +209,22 @@ static ivas_error ivas_binRenderer_convModuleOpen( for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } @@ -242,17 +242,17 @@ static ivas_error ivas_binRenderer_convModuleOpen( for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nInChannels * sizeof( float * ) ) ) == NULL ) + if ( ( hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **) count_malloc( hBinRenderer->nchan_inp * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) ); } - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nchan_inp; chIdx++ ) { if ( ( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *) count_malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( float ) ) ) == NULL ) { @@ -269,7 +269,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( /* set memories */ for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < hBinRenderer->nchan_inp; chIdx++ ) { int16_t tmp = 0; @@ -369,7 +369,7 @@ static void ivas_binaural_obtain_DMX( float realDMX[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float imagDMX[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX] ) { - int16_t chIdx, bandIdx, k; + int16_t ch_in, bandIdx, k; // ToDo: hBinRenderer->ivas_format is never set to ISM_FORMAT -> TBV if ( hBinRenderer->ivas_format == MC_FORMAT || hBinRenderer->ivas_format == ISM_FORMAT ) @@ -377,34 +377,34 @@ static void ivas_binaural_obtain_DMX( /* Obtain the downmix */ float P_in[CLDFB_NO_CHANNELS_MAX]; float P_out, factEQ; - int16_t chOutIdx; + int16_t ch_out; float temp1, temp2; for ( k = 0; k < numTimeSlots; k++ ) { - for ( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ ) + for ( ch_out = 0; ch_out < BINAURAL_CHANNELS; ch_out++ ) { - set_zero( realDMX[chOutIdx][k], CLDFB_NO_CHANNELS_MAX ); - set_zero( imagDMX[chOutIdx][k], CLDFB_NO_CHANNELS_MAX ); + set_zero( realDMX[ch_out][k], CLDFB_NO_CHANNELS_MAX ); + set_zero( imagDMX[ch_out][k], CLDFB_NO_CHANNELS_MAX ); } } - for ( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ ) + for ( ch_out = 0; ch_out < BINAURAL_CHANNELS; ch_out++ ) { set_zero( P_in, hBinRenderer->conv_band ); - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( ch_in = 0; ch_in < hBinRenderer->nchan_inp; ch_in++ ) { - float dmxConst = hBinRenderer->hReverb->dmxmtx[chOutIdx][chIdx]; + float dmxConst = hBinRenderer->hReverb->dmxmtx[ch_out][ch_in]; for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { for ( k = 0; k < numTimeSlots; k++ ) { - temp1 = RealBuffer[chIdx][k][bandIdx] * dmxConst; - temp2 = ImagBuffer[chIdx][k][bandIdx] * dmxConst; - realDMX[chOutIdx][k][bandIdx] += temp1; - imagDMX[chOutIdx][k][bandIdx] += temp2; + temp1 = RealBuffer[ch_in][k][bandIdx] * dmxConst; + temp2 = ImagBuffer[ch_in][k][bandIdx] * dmxConst; + realDMX[ch_out][k][bandIdx] += temp1; + imagDMX[ch_out][k][bandIdx] += temp2; P_in[bandIdx] += temp1 * temp1 + temp2 * temp2; } @@ -416,8 +416,8 @@ static void ivas_binaural_obtain_DMX( P_out = 0.f; for ( k = 0; k < numTimeSlots; k++ ) { - temp1 = realDMX[chOutIdx][k][bandIdx]; - temp2 = imagDMX[chOutIdx][k][bandIdx]; + temp1 = realDMX[ch_out][k][bandIdx]; + temp2 = imagDMX[ch_out][k][bandIdx]; P_out += temp1 * temp1 + temp2 * temp2; } factEQ = sqrtf( P_in[bandIdx] / ( P_out + 1e-20f ) ); @@ -429,8 +429,8 @@ static void ivas_binaural_obtain_DMX( factEQ = max( min( factEQ, 2.0f ), 0.5f ); for ( k = 0; k < numTimeSlots; k++ ) { - realDMX[chOutIdx][k][bandIdx] *= factEQ; - imagDMX[chOutIdx][k][bandIdx] *= factEQ; + realDMX[ch_out][k][bandIdx] *= factEQ; + imagDMX[ch_out][k][bandIdx] *= factEQ; } } } @@ -452,12 +452,12 @@ static void ivas_binaural_obtain_DMX( set_zero( outRealRightPtr, CLDFB_NO_CHANNELS_MAX ); set_zero( outImagRightPtr, CLDFB_NO_CHANNELS_MAX ); - for ( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) + for ( ch_in = 0; ch_in < hBinRenderer->nchan_inp; ch_in++ ) { - float foa_const = hBinRenderer->hReverb->foa_enc[chIdx][1]; + float foa_const = hBinRenderer->hReverb->foa_enc[ch_in][1]; - inRealPtr = (float *) &( RealBuffer[chIdx][k][0] ); - inImagPtr = (float *) &( ImagBuffer[chIdx][k][0] ); + inRealPtr = (float *) &( RealBuffer[ch_in][k][0] ); + inImagPtr = (float *) &( ImagBuffer[ch_in][k][0] ); for ( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { @@ -588,7 +588,7 @@ ivas_error ivas_binRenderer_open( /* initialize the dmx matrix */ for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { - for ( k = 0; k < hBinRenderer->nInChannels; k++ ) + for ( k = 0; k < hBinRenderer->nchan_inp; k++ ) { hBinRenderer->hReverb->dmxmtx[chIdx][k] = dmxmtx[chIdx][k]; } @@ -679,7 +679,7 @@ static void ivas_binRenderer_convModuleClose( for ( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ ) { - for ( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ ) + for ( chIdx = 0; chIdx < ( *hBinRenderer )->nchan_inp; chIdx++ ) { count_free( hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] ); hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = NULL; @@ -912,9 +912,9 @@ void ivas_binRenderer( } /* HOA decoding to CICP19 if needed*/ - if ( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nInChannels != 16 ) + if ( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nchan_inp != 16 ) { - ivas_sba2mc_cldfb( *( hBinRenderer->hInputSetup ), RealBuffer, ImagBuffer, hBinRenderer->nInChannels, hBinRenderer->conv_band, hBinRenderer->hoa_dec_mtx ); + ivas_sba2mc_cldfb( *( hBinRenderer->hInputSetup ), RealBuffer, ImagBuffer, hBinRenderer->nchan_inp, hBinRenderer->conv_band, hBinRenderer->hoa_dec_mtx ); } ivas_binRenderer_filterModule( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, RealBuffer, ImagBuffer, hBinRenderer ); diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 2a02fb56e9..10436882cb 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -307,10 +307,9 @@ ivas_error ivas_ls_setup_conversion_open( ) { LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; - int16_t chIdx, inChannels, outChannels; + int16_t chIdx, nchan_inp, nchan_out; int16_t output_frame; int32_t output_Fs; - int16_t nchan_out; output_Fs = st_ivas->hDecoderConfig->output_Fs; nchan_out = st_ivas->hDecoderConfig->nchan_out; @@ -324,12 +323,11 @@ ivas_error ivas_ls_setup_conversion_open( assert( nchan_out <= MAX_OUTPUT_CHANNELS ); - outChannels = nchan_out; if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC ) { - inChannels = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + nchan_inp = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hLsSetUpConversion->sfbCnt = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); - for ( chIdx = 0; chIdx < outChannels; chIdx++ ) + for ( chIdx = 0; chIdx < nchan_out; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) count_malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ); hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) count_malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ); @@ -344,7 +342,7 @@ ivas_error ivas_ls_setup_conversion_open( } else { - inChannels = st_ivas->nchan_transport; + nchan_inp = st_ivas->nchan_transport; /*Initialization of MDCT bands with TCX20 resolution */ ivas_lssetupconversion_mdct_init_bands( output_frame, TCX_20_CORE, &hLsSetUpConversion->sfbOffset[0], &hLsSetUpConversion->sfbCnt ); hLsSetUpConversion->targetEnergyPrev[0] = (float *) count_malloc( ( MAX_SFB + 2 ) * sizeof( float ) ); @@ -360,14 +358,14 @@ ivas_error ivas_ls_setup_conversion_open( /* Initialize the DMX conversion matrix */ - for ( chIdx = 0; chIdx < inChannels; chIdx++ ) + for ( chIdx = 0; chIdx < nchan_inp; chIdx++ ) { /* Allocate memory depending on the number of output channels */ - if ( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) count_malloc( outChannels * sizeof( float ) ) ) == NULL ) + if ( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) count_malloc( nchan_out * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for temp dmx matrix \n" ) ); } - set_zero( hLsSetUpConversion->dmxMtx[chIdx], outChannels ); + set_zero( hLsSetUpConversion->dmxMtx[chIdx], nchan_out ); } for ( ; chIdx < MAX_CICP_CHANNELS; chIdx++ ) @@ -455,7 +453,7 @@ void ivas_ls_setup_conversion( float output[][L_FRAME48k] /* i/o: LS input/output synthesis signal */ ) { - int16_t chInIdx, chOutIdx, idx; + int16_t ch_in, ch_out, idx; LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; float dmxCoeff, tmpVal; float output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -464,12 +462,12 @@ void ivas_ls_setup_conversion( hLsSetUpConversion = st_ivas->hLsSetUpConversion; - for ( chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < st_ivas->hDecoderConfig->nchan_out; ch_out++ ) { - set_zero( output_tmp[chOutIdx], output_frame ); - for ( chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++ ) + set_zero( output_tmp[ch_out], output_frame ); + for ( ch_in = 0; ch_in < st_ivas->nchan_transport; ch_in++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; if ( dmxCoeff == 0.f ) { @@ -479,24 +477,24 @@ void ivas_ls_setup_conversion( { for ( idx = 0; idx < output_frame; idx++ ) { - output_tmp[chOutIdx][idx] += output[chInIdx][idx]; + output_tmp[ch_out][idx] += output[ch_in][idx]; } } else { for ( idx = 0; idx < output_frame; idx++ ) { - tmpVal = dmxCoeff * output[chInIdx][idx]; - output_tmp[chOutIdx][idx] += tmpVal; + tmpVal = dmxCoeff * output[ch_in][idx]; + output_tmp[ch_out][idx] += tmpVal; } } } } /* Copy to output buffer */ - for ( chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < st_ivas->hDecoderConfig->nchan_out; ch_out++ ) { - mvr2r( output_tmp[chOutIdx], output[chOutIdx], output_frame ); + mvr2r( output_tmp[ch_out], output[ch_out], output_frame ); } wmops_sub_end(); @@ -517,8 +515,8 @@ void ivas_ls_setup_conversion_process_mdct( ) { /* Declaration of all required variables */ - int16_t i, bandIdx, chInIdx, chOutIdx, cpe_idx, subFrameIdx, binIdx, idx; - int16_t inChannels, outChannels, num_CPE; + int16_t i, bandIdx, ch_in, ch_out, cpe_idx, subFrameIdx, binIdx, idx; + int16_t nchan_in, nchan_out, num_CPE; int16_t transform_type[MAX_CICP_CHANNELS][2]; int16_t frameSize; float targetEnergy[MAX_SFB + 2], dmxEnergy[MAX_SFB + 2]; @@ -538,15 +536,15 @@ void ivas_ls_setup_conversion_process_mdct( wmops_sub_start( "LS_Renderer_MDCT" ); /* Assign all the declared variables */ - inChannels = st_ivas->nchan_transport; - outChannels = st_ivas->hDecoderConfig->nchan_out; + nchan_in = st_ivas->nchan_transport; + nchan_out = st_ivas->hDecoderConfig->nchan_out; num_CPE = st_ivas->nCPE; /* Assign output pointer to variable x */ - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - x[chInIdx][0] = &output[chInIdx][0]; - x[chInIdx][1] = &output[chInIdx][0] + L_FRAME48k / 2; + x[ch_in][0] = &output[ch_in][0]; + x[ch_in][1] = &output[ch_in][0] + L_FRAME48k / 2; } /* Assign all the declared handles*/ @@ -562,11 +560,11 @@ void ivas_ls_setup_conversion_process_mdct( for ( idx = 0; idx < CPE_CHANNELS; idx++ ) { /* get the channel index */ - chInIdx = cpe_idx * CPE_CHANNELS + idx; - assert( chInIdx <= inChannels ); - transform_type[chInIdx][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; - transform_type[chInIdx][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; - mct_chan_mode[chInIdx] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; + ch_in = cpe_idx * CPE_CHANNELS + idx; + assert( ch_in <= nchan_in ); + transform_type[ch_in][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; + transform_type[ch_in][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; + mct_chan_mode[ch_in] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; } } @@ -576,17 +574,17 @@ void ivas_ls_setup_conversion_process_mdct( set_zero( targetEnergy, MAX_SFB + 2 ); set_zero( dmxEnergy, MAX_SFB + 2 ); - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { /* Step 0: Set the buffers to zero */ set_zero( dmxSignalReal, frameSize ); set_zero( dmxSignalImag, frameSize ); - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; - if ( !( chInIdx == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( !( ch_in == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { /* Step 1: Compute the target energy and DMX signal (possible since we have all signals in TCX20 resolution) */ if ( dmxCoeff ) @@ -595,19 +593,19 @@ void ivas_ls_setup_conversion_process_mdct( /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0] = pTmp[0] = x[chInIdx][0]; - sig[1] = pTmp[1] = x[chInIdx][1]; + sig[0] = pTmp[0] = x[ch_in][0]; + sig[1] = pTmp[1] = x[ch_in][1]; /* convert (sub)frames to higher frequency resolution */ - if ( transform_type[chInIdx][0] != TCX_20 ) + if ( transform_type[ch_in][0] != TCX_20 ) { for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_5 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_5 ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ pTmp[subFrameIdx] = sig[subFrameIdx] = convertRes + subFrameIdx * frameSize / 2; - convert_coeffs_to_higher_res( x[chInIdx][subFrameIdx], x[chInIdx][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); + convert_coeffs_to_higher_res( x[ch_in][subFrameIdx], x[ch_in][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); } } @@ -645,7 +643,7 @@ void ivas_ls_setup_conversion_process_mdct( } /* end of band loop */ } } - } /* end of chInIdx loop */ + } /* end of ch_in loop */ for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { @@ -677,11 +675,11 @@ void ivas_ls_setup_conversion_process_mdct( } /* Step 4: Perform equalization */ - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - if ( !( chInIdx == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( !( ch_in == LFE_CHANNEL && st_ivas->hMCT->LFE_off ) && mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - if ( transform_type[chInIdx][0] == TCX_20 ) + if ( transform_type[ch_in][0] == TCX_20 ) { /* TCX20 */ for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -693,7 +691,7 @@ void ivas_ls_setup_conversion_process_mdct( ivas_lssetupconversion_computeEQFactor( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][0][binIdx] *= eqGain; + x[ch_in][0][binIdx] *= eqGain; } } } @@ -710,12 +708,12 @@ void ivas_ls_setup_conversion_process_mdct( for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_10 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_10 ) { /* TCX10 */ for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; } } else @@ -726,8 +724,8 @@ void ivas_ls_setup_conversion_process_mdct( for ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; - x[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; } } } @@ -756,7 +754,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( int16_t i; int16_t idx; int16_t nchan_transport, nchan_out, nchan_transport_format; - int16_t chInIdx, chOutIdx, cpe_idx, subFrameIdx, binIdx; + int16_t ch_in, ch_out, cpe_idx, subFrameIdx, binIdx; int16_t band, bandIdx, num_bands; int16_t num_CPE; @@ -819,11 +817,11 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( for ( idx = 0; idx < CPE_CHANNELS; idx++ ) { /* get the channel index */ - chInIdx = cpe_idx * CPE_CHANNELS + idx; - assert( chInIdx <= nchan_transport ); - transform_type[chInIdx][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; - transform_type[chInIdx][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; - mct_chan_mode[chInIdx] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; + ch_in = cpe_idx * CPE_CHANNELS + idx; + assert( ch_in <= nchan_transport ); + transform_type[ch_in][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; + transform_type[ch_in][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; + mct_chan_mode[ch_in] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; } } @@ -833,43 +831,43 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( set_zero( targetEnergy, MAX_SFB + 2 ); set_zero( dmxEnergy, MAX_SFB + 2 ); - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[chInIdx][0] = pTmp[0] = x[chInIdx][0]; - sig[chInIdx][1] = pTmp[1] = x[chInIdx][1]; + sig[ch_in][0] = pTmp[0] = x[ch_in][0]; + sig[ch_in][1] = pTmp[1] = x[ch_in][1]; /* convert (sub)frames to higher frequency resolution */ - if ( transform_type[chInIdx][0] != TCX_20 ) + if ( transform_type[ch_in][0] != TCX_20 ) { for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_5 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_5 ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[subFrameIdx] = sig[chInIdx][subFrameIdx] = convertRes[chInIdx] + subFrameIdx * frameSize / 2; - convert_coeffs_to_higher_res( x[chInIdx][subFrameIdx], x[chInIdx][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); + pTmp[subFrameIdx] = sig[ch_in][subFrameIdx] = convertRes[ch_in] + subFrameIdx * frameSize / 2; + convert_coeffs_to_higher_res( x[ch_in][subFrameIdx], x[ch_in][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); } } /* convert channel with TCX10 to TCX20 resolution */ - sig[chInIdx][0] = convertRes[chInIdx]; - convert_coeffs_to_higher_res( pTmp[0], pTmp[1], sig[chInIdx][0], frameSize / 2 ); + sig[ch_in][0] = convertRes[ch_in]; + convert_coeffs_to_higher_res( pTmp[0], pTmp[1], sig[ch_in][0], frameSize / 2 ); } } } /* precalculate MDST estimate */ - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - mdst[chInIdx][0] = mdst[chInIdx][frameSize - 1] = 0.f; + mdst[ch_in][0] = mdst[ch_in][frameSize - 1] = 0.f; for ( i = 1; i < frameSize - 1; i++ ) { - mdst[chInIdx][i] = sig[chInIdx][0][i + 1] - sig[chInIdx][0][i - 1]; + mdst[ch_in][i] = sig[ch_in][0][i + 1] - sig[ch_in][0][i - 1]; } } } @@ -925,48 +923,48 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( /* Step 1.2, get target channel energies for the transported format as in ivas_param_mc_get_mono_stereo_mixing_matrices(), Nrqq calculation */ ild_q = hParamMC->icld_q + bandIdx * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; - for ( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport_format; ch_in++ ) { float ref_ener = 0.0f; int16_t ref_channel_cnt; int16_t ref_channel_idx; - for ( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[chInIdx]; ref_channel_cnt++ ) + for ( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[ch_in]; ref_channel_cnt++ ) { - ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; + ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[ch_in][ref_channel_cnt]; ref_ener += cx[bandIdx][ref_channel_idx + ref_channel_idx * nchan_transport]; } - Nrqq[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[chInIdx]] = powf( 10.0f, ild_q[chInIdx] / 10.0f ) * hParamMC->hMetadataPMC->ild_factors[chInIdx] * ref_ener; + Nrqq[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[ch_in]] = powf( 10.0f, ild_q[ch_in] / 10.0f ) * hParamMC->hMetadataPMC->ild_factors[ch_in] * ref_ener; } /* Step 1.3 get target Cy like in ivas_param_mc_get_mono_stereo_mixing_matrices() (with dmx matrix from CICPX to MONO/STEREO saved in hParamMC) */ - for ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { for ( i = 0; i < nchan_transport_format; i++ ) { - target_ch_ener[chOutIdx] += hParamMC->ls_conv_dmx_matrix[chOutIdx + i * nchan_out] * Nrqq[i]; + target_ch_ener[ch_out] += hParamMC->ls_conv_dmx_matrix[ch_out + i * nchan_out] * Nrqq[i]; } - cy[chOutIdx + nchan_out * chOutIdx] = target_ch_ener[chOutIdx]; + cy[ch_out + nchan_out * ch_out] = target_ch_ener[ch_out]; } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ - for ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - targetEnergy[bandIdx] += cy[chOutIdx + nchan_out * chOutIdx]; + targetEnergy[bandIdx] += cy[ch_out + nchan_out * ch_out]; } /* Step 2: Calculate DMX ener */ start = hLsSetUpConversion->sfbOffset[bandIdx]; stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; - for ( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; /* Step 1: Compute the target energy and DMX signal (possible since we have all signals in TCX20 resolution) */ if ( dmxCoeff ) @@ -974,10 +972,10 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( /* Loop over all the bins in the band */ for ( binIdx = start; binIdx < stop; binIdx++ ) { - tmpDMXSig = dmxCoeff * sig[chInIdx][0][binIdx]; + tmpDMXSig = dmxCoeff * sig[ch_in][0][binIdx]; dmxSignalReal[binIdx] += tmpDMXSig; - tmpDMXSig = dmxCoeff * mdst[chInIdx][binIdx]; + tmpDMXSig = dmxCoeff * mdst[ch_in][binIdx]; dmxSignalImag[binIdx] += tmpDMXSig; } } @@ -1008,11 +1006,11 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } /* Step 4: Perform equalization */ - for ( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - if ( mct_chan_mode[chInIdx] != MCT_CHAN_MODE_IGNORE ) + if ( mct_chan_mode[ch_in] != MCT_CHAN_MODE_IGNORE ) { - if ( transform_type[chInIdx][0] == TCX_20 ) + if ( transform_type[ch_in][0] == TCX_20 ) { /*TCX20*/ for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -1024,7 +1022,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( ivas_lssetupconversion_computeEQFactor( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][0][binIdx] *= eqGain; + x[ch_in][0][binIdx] *= eqGain; } } } @@ -1041,12 +1039,12 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( for ( subFrameIdx = 0; subFrameIdx < NB_DIV; subFrameIdx++ ) { - if ( transform_type[chInIdx][subFrameIdx] == TCX_10 ) + if ( transform_type[ch_in][subFrameIdx] == TCX_10 ) { /*TCX10*/ for ( binIdx = start; binIdx < stop; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; } } else @@ -1056,12 +1054,12 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( stop_tcx5 = ( stop + 1 ) / 2; for ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx] *= eqGain; + x[ch_in][subFrameIdx][binIdx] *= eqGain; } for ( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; + x[ch_in][subFrameIdx][binIdx + ( frameSize >> 2 )] *= eqGain; } } } @@ -1086,8 +1084,8 @@ void ivas_lssetupconversion_process_param_mc( int16_t channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */ ) { - int16_t slotIdx, chOutIdx, chInIdx, bandIdx; - int16_t inChannels, outChannels; + int16_t slotIdx, ch_in, ch_out, bandIdx; + int16_t nchan_in, nchan_out; float targetEnergy[MAX_CICP_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float dmxEnergy[MAX_CICP_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float tmpDMXSig, dmxCoeff, tmpReal, tmpImag; @@ -1099,101 +1097,101 @@ void ivas_lssetupconversion_process_param_mc( wmops_sub_start( "LS_Renderer_Process_Param_MC" ); /* inits */ - inChannels = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; - outChannels = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_in = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + nchan_out = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; hLsSetUpConversion = st_ivas->hLsSetUpConversion; EQ = 0.0f; - set_s( channel_active, 0, outChannels ); + set_s( channel_active, 0, nchan_out ); /* Loop over each time slots and compute dmx for each time slot */ for ( slotIdx = 0; slotIdx < st_ivas->hParamMC->subframe_nbslots; slotIdx++ ) { /* copy buffers */ - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - mvr2r( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); - mvr2r( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_RealBuffer_InOut[ch_in][slotIdx], Cldfb_RealBuffer_tmp[ch_in], CLDFB_NO_CHANNELS_MAX ); + mvr2r( Cldfb_ImagBuffer_InOut[ch_in][slotIdx], Cldfb_ImagBuffer_tmp[ch_in], CLDFB_NO_CHANNELS_MAX ); } /* set the buffers to zero */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - set_f( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); - set_f( Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( Cldfb_RealBuffer_InOut[ch_out][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( Cldfb_ImagBuffer_InOut[ch_out][slotIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); - set_f( dmxEnergy[chOutIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); - set_f( targetEnergy[chOutIdx], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( dmxEnergy[ch_out], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( targetEnergy[ch_out], 0.0f, CLDFB_NO_CHANNELS_MAX ); } /* Compute the target energy and DMX signal */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) + for ( ch_in = 0; ch_in < nchan_in; ch_in++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx[ch_in][ch_out]; if ( dmxCoeff == 0.0f ) { continue; } else { - channel_active[chOutIdx] |= 1; + channel_active[ch_out] |= 1; for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpDMXSig = dmxCoeff * Cldfb_RealBuffer_tmp[chInIdx][bandIdx]; - Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] += tmpDMXSig; - targetEnergy[chOutIdx][bandIdx] += tmpDMXSig * tmpDMXSig; + tmpDMXSig = dmxCoeff * Cldfb_RealBuffer_tmp[ch_in][bandIdx]; + Cldfb_RealBuffer_InOut[ch_out][slotIdx][bandIdx] += tmpDMXSig; + targetEnergy[ch_out][bandIdx] += tmpDMXSig * tmpDMXSig; - tmpDMXSig = dmxCoeff * Cldfb_ImagBuffer_tmp[chInIdx][bandIdx]; - Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] += tmpDMXSig; - targetEnergy[chOutIdx][bandIdx] += tmpDMXSig * tmpDMXSig; + tmpDMXSig = dmxCoeff * Cldfb_ImagBuffer_tmp[ch_in][bandIdx]; + Cldfb_ImagBuffer_InOut[ch_out][slotIdx][bandIdx] += tmpDMXSig; + targetEnergy[ch_out][bandIdx] += tmpDMXSig * tmpDMXSig; } } } } /* Compute the DMX energy */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - if ( channel_active[chOutIdx] ) + if ( channel_active[ch_out] ) { for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; - tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpReal = Cldfb_RealBuffer_InOut[ch_out][slotIdx][bandIdx]; + tmpImag = Cldfb_ImagBuffer_InOut[ch_out][slotIdx][bandIdx]; - dmxEnergy[chOutIdx][bandIdx] = tmpReal * tmpReal + tmpImag * tmpImag; + dmxEnergy[ch_out][bandIdx] = tmpReal * tmpReal + tmpImag * tmpImag; } } } /* Peform energy smoothing */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - if ( channel_active[chOutIdx] ) + if ( channel_active[ch_out] ) { for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - targetEnergy[chOutIdx][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * targetEnergy[chOutIdx][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->targetEnergyPrev[chOutIdx][bandIdx]; - dmxEnergy[chOutIdx][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * dmxEnergy[chOutIdx][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->dmxEnergyPrev[chOutIdx][bandIdx]; - hLsSetUpConversion->targetEnergyPrev[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; - hLsSetUpConversion->dmxEnergyPrev[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; + targetEnergy[ch_out][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * targetEnergy[ch_out][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->targetEnergyPrev[ch_out][bandIdx]; + dmxEnergy[ch_out][bandIdx] = LS_OUT_CONV_SMOOTHING_FACTOR * dmxEnergy[ch_out][bandIdx] + ( 1 - LS_OUT_CONV_SMOOTHING_FACTOR ) * hLsSetUpConversion->dmxEnergyPrev[ch_out][bandIdx]; + hLsSetUpConversion->targetEnergyPrev[ch_out][bandIdx] = targetEnergy[ch_out][bandIdx]; + hLsSetUpConversion->dmxEnergyPrev[ch_out][bandIdx] = dmxEnergy[ch_out][bandIdx]; } } } /* Compute and perform equalization */ - for ( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - if ( channel_active[chOutIdx] ) + if ( channel_active[ch_out] ) { for ( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - ivas_lssetupconversion_computeEQFactor( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); - Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] *= EQ; - Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] *= EQ; + ivas_lssetupconversion_computeEQFactor( &targetEnergy[ch_out][bandIdx], &dmxEnergy[ch_out][bandIdx], &EQ ); + Cldfb_RealBuffer_InOut[ch_out][slotIdx][bandIdx] *= EQ; + Cldfb_ImagBuffer_InOut[ch_out][slotIdx][bandIdx] *= EQ; } } } diff --git a/lib_dec/ivas_rotation.c b/lib_dec/ivas_rotation.c index 77809d8270..9e6cbca8c1 100644 --- a/lib_dec/ivas_rotation.c +++ b/lib_dec/ivas_rotation.c @@ -559,7 +559,7 @@ void rotateFrame_shd_cldfb( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part */ float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part */ float Rmat[3][3], /* i : real-space rotation matrix */ - const int16_t nInChannels, /* i : number of channels */ + const int16_t nchan_inp, /* i : number of channels */ const int16_t shd_rot_max_order /* i : split-order rotation method */ ) { @@ -571,7 +571,7 @@ void rotateFrame_shd_cldfb( float realRot[2 * HEADROT_ORDER + 1], imagRot[2 * HEADROT_ORDER + 1]; float SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; - assert( nInChannels == HEADROT_SHMAT_DIM && "Number of channels must be 16!" ); + assert( nchan_inp == HEADROT_SHMAT_DIM && "Number of channels must be 16!" ); /* initialize rotation matrices with zeros */ for ( i = 0; i < HEADROT_SHMAT_DIM; i++ ) @@ -618,18 +618,18 @@ void rotateFrame_shd_cldfb( } /* unoptimized code for reference (full matrix multiplication) - for (n = 0; n < nInChannels; n++) + for (n = 0; n < nchan_inp; n++) { realRot[n] = 0.f; imagRot[n] = 0.f; - for (m = 0; m < nInChannels; m++) + for (m = 0; m < nchan_inp; m++) { realRot[n] += SHrotmat[n][m] * Cldfb_RealBuffer[m][i][iBand]; imagRot[n] += SHrotmat[n][m] * Cldfb_ImagBuffer[m][i][iBand]; } } - for (n = 0; n < nInChannels; n++) + for (n = 0; n < nchan_inp; n++) { Cldfb_RealBuffer[n][i][iBand] = realRot[n]; Cldfb_ImagBuffer[n][i][iBand] = imagRot[n]; @@ -666,14 +666,13 @@ void rotateFrame_sd_cldfb( float imagRot[MAX_CICP_CHANNELS - 1][MAX_PARAM_SPATIAL_SUBFRAMES * CLDFB_NO_CHANNELS_MAX]; float *p_realRot, *p_imagRot; float *p_real, *p_imag; - int16_t nInChannels; - int16_t isPlanar; + int16_t nchan_inp, isPlanar; wmops_sub_start( "rotateFrame_sd_cldfb" ); - nInChannels = hOutputSetup->nchan_out_woLFE; + nchan_inp = hOutputSetup->nchan_out_woLFE; isPlanar = 1; - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { if ( hOutputSetup->ls_elevation[n] != 0 ) { @@ -686,7 +685,7 @@ void rotateFrame_sd_cldfb( QuatToRotMat( hHeadTrackData->Quaternions[hHeadTrackData->num_quaternions++], Rmat ); /* rotation of Euler angles */ - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { rotateAziEle( hOutputSetup->ls_azimuth[n], hOutputSetup->ls_elevation[n], &azimuth, &elevation, Rmat, isPlanar ); if ( hEFAPdata != NULL && ( hOutputSetup->ls_azimuth[n] != azimuth || hOutputSetup->ls_elevation[n] != elevation ) ) @@ -695,17 +694,17 @@ void rotateFrame_sd_cldfb( } else { - set_zero( gains[n], nInChannels ); + set_zero( gains[n], nchan_inp ); gains[n][n] = 1.0f; } } /* Apply panning gains by mtx multiplication*/ - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { set_zero( realRot[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_band ); set_zero( imagRot[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_band ); - for ( m = 0; m < nInChannels; m++ ) + for ( m = 0; m < nchan_inp; m++ ) { g1 = gains[m][n]; p_realRot = realRot[n]; @@ -728,7 +727,7 @@ void rotateFrame_sd_cldfb( } } - for ( n = 0; n < nInChannels; n++ ) + for ( n = 0; n < nchan_inp; n++ ) { p_realRot = realRot[n]; p_imagRot = imagRot[n]; diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 8da866f194..27771a93d2 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1016,7 +1016,7 @@ void ivas_spar_dec_upmixer( *---------------------------------------------------------------------*/ /* set-up pointers */ - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { /* at this point, output channels are used as intermediate procesing buffers */ for ( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS; in_ch++ ) @@ -1076,7 +1076,7 @@ void ivas_spar_dec_upmixer( for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ - ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, nchan_out, nchan_inp, num_spar_bands, mixer_mat ); + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, nchan_out, nchan_inp, num_spar_bands, mixer_mat ); for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { @@ -1125,7 +1125,7 @@ void ivas_spar_dec_upmixer( } } - if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { ivas_dirac_dec( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im, i_sf ); } @@ -1150,7 +1150,7 @@ void ivas_spar_dec_upmixer( } else { - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA || + if ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA || !( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) @@ -1173,7 +1173,7 @@ void ivas_spar_dec_upmixer( else { /* CLDFB to time synthesis (overwrite mixer output) */ - for ( out_ch = 0; out_ch < st_ivas->hDecoderConfig->nchan_out; out_ch++ ) + for ( out_ch = 0; out_ch < hDecoderConfig->nchan_out; out_ch++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 9bfe233e8e..c856c36f31 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1327,7 +1327,7 @@ typedef struct ivas_binaural_rendering_struct int16_t max_band; /* band upto which rendering is performed */ int16_t conv_band; /* band upto which convolution in cldfb domain is performed */ int16_t timeSlots; /* number of time slots of binaural renderer */ - int16_t nInChannels; /* number input channels */ + int16_t nchan_inp; /* number input channels */ int8_t render_lfe; /* Flag to render LFE in binaural rendering*/ IVAS_FORMAT ivas_format; /* format; corresponds to st_ivas->ivas_format, unless the signal gets transormed to a different domain for rendering */ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index e863f3ded9..4c7721f095 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -48,7 +48,7 @@ * Local function prototypes *--------------------------------------------------------------------*/ -static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, const ENCODER_CONFIG_HANDLE hEncoderConfig, BSTR_ENC_HANDLE hMetaData, const int16_t front_vad_flag, float data_f[][L_FRAME48k] ); +static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, BSTR_ENC_HANDLE hMetaData, const int16_t front_vad_flag, float data_f[][L_FRAME48k] ); /*------------------------------------------------------------------------- @@ -296,7 +296,7 @@ ivas_error ivas_spar_enc( ivas_sba_zero_vert_comp( data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_planar, input_frame ); } - if ( ( error = ivas_spar_enc_process( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_enc_process( st_ivas, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) { return error; } @@ -388,11 +388,10 @@ static void ivas_spar_enc_get_windowed_fr( *-----------------------------------------------------------------------------------------*/ static ivas_error ivas_spar_enc_process( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t front_vad_flag, /* i : front-VAD decision */ - float data_f[][L_FRAME48k] /* i/o: input/transport audio channels */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const int16_t front_vad_flag, /* i : front-VAD decision */ + float data_f[][L_FRAME48k] /* i/o: input/transport audio channels */ ) { float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2]; @@ -421,6 +420,7 @@ static ivas_error ivas_spar_enc_process( const int16_t *order; SPAR_ENC_HANDLE hSpar = st_ivas->hSpar; IVAS_QMETADATA_HANDLE hQMetaData = st_ivas->hQMetaData; + ENCODER_CONFIG_HANDLE hEncoderConfig = st_ivas->hEncoderConfig; int16_t ts, l_ts, orig_dirac_bands, num_del_samples; float *ppIn_FR_real[IVAS_SPAR_MAX_CH], *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; float w_del_buf[IVAS_FB_1MS_48K_SAMP]; -- GitLab From b7b40a9bc98f7c9bcb4b6c32ffa6166cef5047cc Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 18 Oct 2022 15:42:53 +0200 Subject: [PATCH 19/26] harmonize 'nchan' terminology --- lib_com/ivas_prot.h | 2 +- lib_com/ivas_spar_com.c | 86 +++++++------- lib_dec/ivas_sba_dec.c | 4 +- lib_dec/ivas_sba_rendering.c | 6 +- lib_dec/ivas_spar_md_dec.c | 215 +++++++++++++++++------------------ lib_enc/ivas_mc_param_enc.c | 13 ++- 6 files changed, 160 insertions(+), 166 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 77a90ae84c..8f7da9933e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3977,7 +3977,7 @@ void ivas_get_spar_md_from_dirac( ivas_spar_md_com_cfg *hSpar_md_cfg, const int16_t start_band, const int16_t end_band, - const int16_t order, + const int16_t sba_order, const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] ); diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index b9abd5f778..cb6501f3be 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1645,11 +1645,11 @@ void ivas_get_spar_md_from_dirac( ivas_spar_md_com_cfg *hSpar_md_cfg, const int16_t start_band, const int16_t end_band, - const int16_t order, + const int16_t sba_order, const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] ) { - int16_t nchan, band, i, j; + int16_t nchan_md, band, i, j; int16_t block, ch; float response_avg[MAX_OUTPUT_CHANNELS]; float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; @@ -1661,15 +1661,15 @@ void ivas_get_spar_md_from_dirac( float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; - int16_t ndm, foa_ch, hoa2_ch; + int16_t ndm, nchan_foa, nchan_md_hoa2; float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; const int16_t *remix_order; remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - nchan = 2 * order + 2; - hoa2_ch = 6; - foa_ch = FOA_CHANNELS; + nchan_md = ivas_sba_get_nchan_metadata( sba_order ); + nchan_md_hoa2 = ivas_sba_get_nchan_metadata( 2 ); + nchan_foa = FOA_CHANNELS; diff_norm_order1 = 3.0f; diff_norm_order2 = 5.0f; diff_norm_order3 = 7.0f; @@ -1689,39 +1689,39 @@ void ivas_get_spar_md_from_dirac( int16_t idx; ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; P_norm[0] = 0.0f; - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + for ( i = 0; i < max( 0, nchan_foa - ndm ); i++ ) { P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); + P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, nchan_foa - ndm ) ); P_norm[1] = 0.0f; - for ( ; i < max( 0, min( nchan, hoa2_ch ) - ndm ); i++ ) + for ( ; i < max( 0, min( nchan_md, nchan_md_hoa2 ) - ndm ); i++ ) { P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( nchan, hoa2_ch ) - ndm ) ); + P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( nchan_md, nchan_md_hoa2 ) - ndm ) ); P_norm[2] = 0.0f; - for ( ; i < nchan - ndm; i++ ) + for ( ; i < nchan_md - ndm; i++ ) { P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; } - P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, nchan - ndm ) ); + P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, nchan_md - ndm ) ); - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + for ( i = 0; i < max( 0, nchan_foa - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); } - for ( ; i < max( 0, min( nchan, hoa2_ch ) - ndm ); i++ ) + for ( ; i < max( 0, min( nchan_md, nchan_md_hoa2 ) - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); } - for ( ; i < nchan - ndm; i++ ) + for ( ; i < nchan_md - ndm; i++ ) { idx = remix_order[i + ndm] - ndm; P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; @@ -1743,24 +1743,24 @@ void ivas_get_spar_md_from_dirac( if ( n_ts > 1 ) { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); + ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, sba_order ); } else { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); + ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), sba_order ); } /* average responses in all subframes*/ { float norm; - int16_t num_ch_order, hoa2_ch_order; + int16_t nchan_internal, nchan_hoa2; - num_ch_order = ivas_sba_get_nchan( order, 0 ); - hoa2_ch_order = 9; + nchan_internal = ivas_sba_get_nchan( sba_order, 0 ); + nchan_hoa2 = ivas_sba_get_nchan( 2, 0 ); - for ( ch = 0; ch < num_ch_order; ch++ ) + for ( ch = 0; ch < nchan_internal; ch++ ) { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -1771,51 +1771,51 @@ void ivas_get_spar_md_from_dirac( /*normalize 1st order*/ norm = 0.0f; - for ( ch = 1; ch < foa_ch; ch++ ) + for ( ch = 1; ch < nchan_foa; ch++ ) { norm += response_avg[ch] * response_avg[ch]; } norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = 1; ch < foa_ch; ch++ ) + for ( ch = 1; ch < nchan_foa; ch++ ) { response_avg[ch] /= norm; } /*normalize 2nd order*/ norm = 0.0f; - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + for ( ch = nchan_foa; ch < min( nchan_hoa2, nchan_internal ); ch++ ) { norm += response_avg[ch] * response_avg[ch]; } norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + for ( ch = nchan_foa; ch < min( nchan_hoa2, nchan_internal ); ch++ ) { response_avg[ch] /= norm; } /*normalize 3rd order*/ norm = 0.0f; - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + for ( ch = nchan_hoa2; ch < nchan_internal; ch++ ) { norm += response_avg[ch] * response_avg[ch]; } norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + for ( ch = nchan_hoa2; ch < nchan_internal; ch++ ) { response_avg[ch] /= norm; } } } - for ( i = FOA_CHANNELS + 1; i < nchan; i++ ) + for ( i = FOA_CHANNELS + 1; i < nchan_md; i++ ) { response_avg[i] = response_avg[HOA_keep_ind[i]]; } en_ratio_fac = ( 1.0f - diffuseness[band] ); - for ( i = 0; i < nchan; i++ ) + for ( i = 0; i < nchan_md; i++ ) { - for ( j = 0; j < nchan; j++ ) + for ( j = 0; j < nchan_md; j++ ) { if ( i == j ) { @@ -1835,11 +1835,11 @@ void ivas_get_spar_md_from_dirac( } else { - if ( i < foa_ch ) + if ( i < nchan_foa ) { cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; } - else if ( i < hoa2_ch ) + else if ( i < nchan_md_hoa2 ) { cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; } @@ -1851,11 +1851,11 @@ void ivas_get_spar_md_from_dirac( } else { - if ( i < foa_ch ) + if ( i < nchan_foa ) { cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; } - else if ( i < hoa2_ch ) + else if ( i < nchan_md_hoa2 ) { cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; } @@ -1874,9 +1874,9 @@ void ivas_get_spar_md_from_dirac( } } - for ( i = 0; i < nchan; i++ ) + for ( i = 0; i < nchan_md; i++ ) { - for ( j = 0; j < nchan; j++ ) + for ( j = 0; j < nchan_md; j++ ) { pCov_real[i][j] = cov_real_dirac[i][j]; } @@ -1892,9 +1892,9 @@ void ivas_get_spar_md_from_dirac( fid = fopen( "cov_real_dirac.txt", "wt" ); } - for ( i = 0; i < nchan; i++ ) + for ( i = 0; i < nchan_md; i++ ) { - for ( j = 0; j < nchan; j++ ) + for ( j = 0; j < nchan_md; j++ ) { for ( k = start_band; k < end_band; k++ ) { @@ -1907,7 +1907,7 @@ void ivas_get_spar_md_from_dirac( #endif ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, - nchan, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); + nchan_md, 1, hSpar_md_cfg->active_w, hSpar_md_cfg, hSpar_md, Wscale, 1 ); if ( mixer_mat != NULL ) { @@ -1917,15 +1917,15 @@ void ivas_get_spar_md_from_dirac( for ( i = 0; i < ndm; i++ ) { - for ( j = 0; j < nchan; j++ ) + for ( j = 0; j < nchan_md; j++ ) { mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band]; } } - for ( i = ndm; i < nchan; i++ ) + for ( i = ndm; i < nchan_md; i++ ) { - for ( j = 0; j < nchan; j++ ) + for ( j = 0; j < nchan_md; j++ ) { mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f; } @@ -1933,7 +1933,7 @@ void ivas_get_spar_md_from_dirac( if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) { - for ( j = 0; j < nchan; j++ ) + for ( j = 0; j < nchan_md; j++ ) { mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band]; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 2180cb79a3..c2b56f8b01 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -77,7 +77,7 @@ void ivas_mc2sba( assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" ); /* Init*/ - sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 ); + sba_num_chans = ivas_sba_get_nchan( sba_order, 0 ); for ( j = 0; j < sba_num_chans; j++ ) { set_zero( buffer_tmp[j], output_frame ); @@ -297,7 +297,7 @@ void ivas_ism2sba( assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" ); /* Init*/ - sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 ); + sba_num_chans = ivas_sba_get_nchan( sba_order, 0 ); for ( j = 0; j < sba_num_chans; j++ ) { set_zero( buffer_tmp[j], output_frame ); diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 1efde66cf5..09f8c7a1ff 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -208,12 +208,12 @@ void ivas_sba_upmixer_renderer( const int16_t output_frame /* i : output frame length */ ) { - int16_t i, nchan_internal; + int16_t i, nchan; float temp; wmops_sub_start( "ivas_sba_upmixer_renderer" ); - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); + nchan = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); if ( st_ivas->nchan_transport >= 3 ) { @@ -227,7 +227,7 @@ void ivas_sba_upmixer_renderer( } /* Upmixer + Renderer */ - ivas_spar_dec_upmixer( st_ivas, output, nchan_internal, output_frame ); + ivas_spar_dec_upmixer( st_ivas, output, nchan, output_frame ); if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) { diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index a9307ddb82..bb81448b81 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -544,7 +544,7 @@ static ivas_error ivas_spar_set_dec_config( const int16_t nchan_transport, float *pFC ) { - int16_t i, j, nchan, dmx_ch; + int16_t i, j, nchan, nchan_dmx; for ( i = 0; i < nchan_transport; i++ ) { @@ -574,15 +574,15 @@ static ivas_error ivas_spar_set_dec_config( hMdDec->spar_md_cfg.num_umx_chs = nchan; - dmx_ch = 0; + nchan_dmx = 0; for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { - dmx_ch = 0; + nchan_dmx = 0; for ( j = 0; j < nchan_transport; j++ ) { if ( pFC[i] < hMdDec->spar_md_cfg.max_freq_per_chan[j] ) { - dmx_ch += 1; + nchan_dmx += 1; } } @@ -590,7 +590,7 @@ static ivas_error ivas_spar_set_dec_config( hMdDec->spar_md_cfg.num_decorr_per_band[i] = nchan - hMdDec->spar_md_cfg.nchan_transport; } - hMdDec->spar_md_cfg.nchan_transport = dmx_ch; + hMdDec->spar_md_cfg.nchan_transport = nchan_dmx; return IVAS_ERR_OK; } @@ -750,18 +750,18 @@ void ivas_spar_smooth_md_dtx( const int16_t num_bands_out /* i : number of output bands */ ) { - int16_t j, k, b, dmx_ch; + int16_t j, k, b, nchan; float ramp, tar, prev, new_val; ramp = (float) hMdDec->dtx_md_smoothing_cntr / IVAS_DEFAULT_DTX_CNG_RAMP; for ( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + nchan = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; for ( j = 1; j < FOA_CHANNELS; j++ ) { - for ( k = dmx_ch; k < FOA_CHANNELS; k++ ) + for ( k = nchan; k < FOA_CHANNELS; k++ ) { prev = hMdDec->spar_coeffs_prev.P_re[j][k][b]; tar = hMdDec->spar_coeffs_tar.P_re[j][k][b]; @@ -772,7 +772,7 @@ void ivas_spar_smooth_md_dtx( for ( j = 0; j < FOA_CHANNELS; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan; k++ ) { prev = hMdDec->spar_coeffs_prev.C_re[j][k][b]; tar = hMdDec->spar_coeffs_tar.C_re[j][k][b]; @@ -787,12 +787,11 @@ void ivas_spar_smooth_md_dtx( { for ( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + nchan = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; for ( j = 1; j < FOA_CHANNELS; j++ ) { - for ( k = dmx_ch; k < FOA_CHANNELS; k++ ) - + for ( k = nchan; k < FOA_CHANNELS; k++ ) { hMdDec->spar_coeffs.P_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re[j][k][b]; } @@ -800,7 +799,7 @@ void ivas_spar_smooth_md_dtx( for ( j = 0; j < FOA_CHANNELS; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan; k++ ) { hMdDec->spar_coeffs.C_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re[j][k][b]; } @@ -956,12 +955,12 @@ static void ivas_get_spar_matrices( const int16_t nB, const int16_t sba_order ) { - int16_t numch_out, num_bands, dmx_ch, split_band; + int16_t nchan, num_bands, nchan_dmx, split_band; int16_t i, j, k, m, b, i_ts, active_w; const int16_t *order; float active_w_dm_fac, re; - numch_out = ivas_sba_get_nchan_metadata( sba_order ); + nchan = ivas_sba_get_nchan_metadata( sba_order ); num_bands = num_bands_out; order = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order]; @@ -970,9 +969,9 @@ static void ivas_get_spar_matrices( if ( split_band >= IVAS_MAX_NUM_BANDS ) { /*store previous 4x4 parameters for linear interpolation to current*/ - for ( i = 0; i < numch_out; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { for ( b = 0; b < num_bands; b++ ) { @@ -985,15 +984,15 @@ static void ivas_get_spar_matrices( #ifdef SPAR_HOA_DBG /*for (b = 0; b < BANDS_12; b++) { - for (i = 0; i < IVAS_SPAR_MAX_CH - 1; i++) + for (i = 0; i < IVAS_SPAR_MAX_CH - 1; i++) + { + hMdDec->spar_md.band_coeffs[b].pred_re[i] = (float)(i + 1)/10; + for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) { - hMdDec->spar_md.band_coeffs[b].pred_re[i] = (float)(i + 1)/10; - for (j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) - { - hMdDec->spar_md.band_coeffs[b].C_re[i][j] = (float)(i + j * 20 + 1)/10; - hMdDec->spar_md.band_coeffs[b].P_re[i][j] = (float)(i + j * 20 + 1)/10; - } + hMdDec->spar_md.band_coeffs[b].C_re[i][j] = (float)(i + j * 20 + 1)/10; + hMdDec->spar_md.band_coeffs[b].P_re[i][j] = (float)(i + j * 20 + 1)/10; } + } }*/ #endif @@ -1002,9 +1001,9 @@ static void ivas_get_spar_matrices( for ( i_ts = 0; i_ts < n_ts; i_ts++ ) { - for ( i = 0; i < numch_out; i++ ) + for ( i = 0; i < nchan; i++ ) { - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { set_zero( &hMdDec->spar_coeffs.C_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); set_zero( &hMdDec->spar_coeffs.P_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); @@ -1024,27 +1023,27 @@ static void ivas_get_spar_matrices( float tmp_C2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float tmp_dm_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - set_zero( tmp_C1_re[j], numch_out ); - set_zero( tmp_C2_re[j], numch_out ); - set_zero( tmp_dm_re[j], numch_out ); + set_zero( tmp_C1_re[j], nchan ); + set_zero( tmp_C2_re[j], nchan ); + set_zero( tmp_dm_re[j], nchan ); tmp_C1_re[j][j] = 1.0f; tmp_C2_re[j][j] = 1.0f; tmp_dm_re[j][j] = 1.0f; } - for ( j = 1; j < numch_out; j++ ) + for ( j = 1; j < nchan; j++ ) { tmp_C1_re[j][0] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j - 1]; } if ( active_w == 1 ) { - for ( j = 1; j < numch_out; j++ ) + for ( j = 1; j < nchan; j++ ) { tmp_C2_re[0][j] = active_w_dm_fac * -hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j - 1]; } @@ -1072,7 +1071,7 @@ static void ivas_get_spar_matrices( if ( hMdDec->spar_md_cfg.remix_unmix_order != 3 ) { - ivas_mat_col_rearrange( tmp_dm_re, order, i_ts, hMdDec->mixer_mat, b, numch_out ); + ivas_mat_col_rearrange( tmp_dm_re, order, i_ts, hMdDec->mixer_mat, b, nchan ); } else { @@ -1097,7 +1096,7 @@ static void ivas_get_spar_matrices( { if ( hMdDec->spar_md_cfg.remix_unmix_order != 3 ) { - ivas_mat_col_rearrange( tmp_C1_re, order, i_ts, hMdDec->mixer_mat, b, numch_out ); + ivas_mat_col_rearrange( tmp_C1_re, order, i_ts, hMdDec->mixer_mat, b, nchan ); } else { @@ -1119,63 +1118,62 @@ static void ivas_get_spar_matrices( } } - if ( dmx_ch > 0 ) + if ( nchan_dmx > 0 ) { float tmpC_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float tmpP_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - set_zero( tmpC_re[j], numch_out ); - set_zero( tmpP_re[j], numch_out ); + set_zero( tmpC_re[j], nchan ); + set_zero( tmpP_re[j], nchan ); } - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - set_zero( tmpC_re[j], numch_out ); + set_zero( tmpC_re[j], nchan ); } - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { tmpC_re[k][k] = 1; } - for ( j = dmx_ch; j < numch_out; j++ ) + for ( j = nchan_dmx; j < nchan; j++ ) { - for ( k = 1; k < dmx_ch; k++ ) + for ( k = 1; k < nchan_dmx; k++ ) { - tmpC_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j - dmx_ch][k - 1]; + tmpC_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j - nchan_dmx][k - 1]; } } #ifdef SPAR_HOA_DBG - /*fprintf(stdout, "C matrix1: %d x %d\n\n", numch_out, dmx_ch); - for (j = 0; j < numch_out; j++) + /*fprintf(stdout, "C matrix1: %d x %d\n\n", nchan, nchan_dmx); + for (j = 0; j < nchan; j++) { - for (k = 0; k < dmx_ch; k++) - { - fprintf(stdout, "%f, ", tmpC_re[j][k]); - } - fprintf(stdout, "\n"); - + for (k = 0; k < nchan_dmx; k++) + { + fprintf(stdout, "%f, ", tmpC_re[j][k]); + } + fprintf(stdout, "\n"); } - fprintf(stdout, "Mixer Mat: %d x %d\n\n", numch_out, numch_out); - for ( j = 0; j < numch_out; j++) + fprintf(stdout, "Mixer Mat: %d x %d\n\n", nchan, nchan); + for ( j = 0; j < nchan; j++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); - } - fprintf(stdout, "\n"); + for (k = 0; k < nchan; k++) + { + fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); + } + fprintf(stdout, "\n"); }*/ #endif - for ( j = dmx_ch; j < numch_out; j++ ) + for ( j = nchan_dmx; j < nchan; j++ ) { - for ( k = dmx_ch; k < numch_out; k++ ) + for ( k = nchan_dmx; k < nchan; k++ ) { - if ( ( j - dmx_ch ) == ( k - dmx_ch ) ) + if ( ( j - nchan_dmx ) == ( k - nchan_dmx ) ) { - tmpP_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[k - dmx_ch]; + tmpP_re[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[k - nchan_dmx]; } else { @@ -1186,34 +1184,32 @@ static void ivas_get_spar_matrices( #ifdef SPAR_HOA_DBG /*if (b == 0) { - fprintf(stdout, "tmp_P matrix: %d x %d\n\n", numch_out, dmx_ch); - for (j = 0; j < numch_out; j++) + fprintf(stdout, "tmp_P matrix: %d x %d\n\n", nchan, nchan_dmx); + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", tmpP_re[j][k]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", tmpP_re[j][k]); } - fprintf(stdout, "Mixer Mat: %d x %d\n\n", numch_out, numch_out); - for (j = 0; j < numch_out; j++) + fprintf(stdout, "\n"); + } + fprintf(stdout, "Mixer Mat: %d x %d\n\n", nchan, nchan); + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", hMdDec->mixer_mat[j][k][0][b]); } + fprintf(stdout, "\n"); + } }*/ #endif - for ( j = 1; j < numch_out; j++ ) + for ( j = 1; j < nchan; j++ ) { - for ( k = dmx_ch; k < numch_out; k++ ) + for ( k = nchan_dmx; k < nchan; k++ ) { - for ( m = 0; m < numch_out; m++ ) + for ( m = 0; m < nchan; m++ ) { IVAS_RMULT_FLOAT( hMdDec->mixer_mat[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpP_re[m][k], re ); hMdDec->spar_coeffs.P_re[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] += re; @@ -1221,11 +1217,11 @@ static void ivas_get_spar_matrices( } } - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { - for ( m = 0; m < numch_out; m++ ) + for ( m = 0; m < nchan; m++ ) { IVAS_RMULT_FLOAT( hMdDec->mixer_mat[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpC_re[m][k], re ); hMdDec->spar_coeffs.C_re[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] += re; @@ -1233,15 +1229,14 @@ static void ivas_get_spar_matrices( } } #ifdef SPAR_HOA_DBG - /*fprintf(stdout, "C matrix1: %d x %d\n\n", numch_out, dmx_ch); - for (j = 0; j < numch_out; j++) + /*fprintf(stdout, "C matrix1: %d x %d\n\n", nchan, nchan_dmx); + for (j = 0; j < nchan; j++) { - for (k = 0; k < dmx_ch; k++) + for (k = 0; k < nchan_dmx; k++) { fprintf(stdout, "%f, ", hMdDec->spar_coeffs.C_re[j][k][b]); } fprintf(stdout, "\n"); - }*/ #endif hMdDec->spar_coeffs.C_re[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = @@ -1251,27 +1246,25 @@ static void ivas_get_spar_matrices( #ifdef SPAR_HOA_DBG /* for (b = 0; b < 1; b++) { - fprintf(stdout, "C matrix: %d x %d band %d\n\n", numch_out, dmx_ch, b); - for (j = 0; j < numch_out; j++) + fprintf(stdout, "C matrix: %d x %d band %d\n\n", nchan, nchan_dmx, b); + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->spar_coeffs.C_re[j][k][b]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", hMdDec->spar_coeffs.C_re[j][k][b]); } - fprintf(stdout, "\nP matrix: %d x %d\n\n", numch_out, numch_out); + fprintf(stdout, "\n"); + } + fprintf(stdout, "\nP matrix: %d x %d\n\n", nchan, nchan); - for (j = 0; j < numch_out; j++) + for (j = 0; j < nchan; j++) + { + for (k = 0; k < nchan; k++) { - for (k = 0; k < numch_out; k++) - { - fprintf(stdout, "%f, ", hMdDec->spar_coeffs.P_re[j][k][b]); - } - fprintf(stdout, "\n"); - + fprintf(stdout, "%f, ", hMdDec->spar_coeffs.P_re[j][k][b]); } + fprintf(stdout, "\n"); + } }*/ #endif @@ -1280,18 +1273,18 @@ static void ivas_get_spar_matrices( { for ( b = 0; b < num_bands_out; b = b + bw ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; - for ( j = 0; j < numch_out; j++ ) + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + for ( j = 0; j < nchan; j++ ) { - for ( k = dmx_ch; k < numch_out; k++ ) + for ( k = nchan_dmx; k < nchan; k++ ) { hMdDec->spar_coeffs.P_re[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; } } - for ( j = 0; j < numch_out; j++ ) + for ( j = 0; j < nchan; j++ ) { - for ( k = 0; k < dmx_ch; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { hMdDec->spar_coeffs.C_re[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 844a3c19bf..396a9a5ecd 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -436,21 +436,22 @@ static void ivas_param_mc_dmx( { int16_t i; const int16_t *idx; - int16_t dmx_ch; - int16_t inp_ch; + int16_t ch_dmx, ch_inp; const float *p_dmx_fac; + float *dmx_sample; idx = Param_MC_index; for ( i = 0; i < input_frame; i++ ) { p_dmx_fac = hParamMC->dmx_factors; - for ( dmx_ch = 0; dmx_ch < nchan_transport; dmx_ch++ ) + for ( ch_dmx = 0; ch_dmx < nchan_transport; ch_dmx++ ) { - float *dmx_sample = &data_dmx[idx[dmx_ch]][i]; + dmx_sample = &data_dmx[idx[ch_dmx]][i]; *dmx_sample = 0.0f; - for ( inp_ch = 0; inp_ch < nchan_inp; inp_ch++ ) + + for ( ch_inp = 0; ch_inp < nchan_inp; ch_inp++ ) { - ( *dmx_sample ) += data_f[idx[inp_ch]][i] * ( *( p_dmx_fac++ ) ); + ( *dmx_sample ) += data_f[idx[ch_inp]][i] * ( *( p_dmx_fac++ ) ); } } } -- GitLab From 646517efeca7d1234c1748084186ed02be613580 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 18 Oct 2022 16:17:37 +0200 Subject: [PATCH 20/26] harmonize channel indexes --- lib_com/ivas_prot.h | 4 +- lib_dec/ivas_dec.c | 50 +++++++-------- lib_dec/ivas_dirac_dec.c | 10 +-- lib_dec/ivas_ism_param_dec.c | 22 +++---- lib_dec/ivas_sba_rendering.c | 35 ++++++----- lib_dec/ivas_spar_decoder.c | 114 +++++++++++++++++------------------ lib_enc/ivas_enc.c | 20 +++--- 7 files changed, 127 insertions(+), 128 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8f7da9933e..b05d7961f4 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3996,8 +3996,8 @@ void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t ts, /* i : time slot index */ - const int16_t num_ch_out, /* i : number of channels out */ - const int16_t num_ch_in, /* i : number of channels in */ + const int16_t nchan_out, /* i : number of channels out */ + const int16_t nchan_inp, /* i : number of channels in */ const int16_t num_spar_bands, /* i : number of SPAR bands */ float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ ); diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 5d3a5a10f9..fec88a37c6 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -55,7 +55,7 @@ ivas_error ivas_dec( int16_t *data /* o : output synthesis signal */ ) { - int16_t n, output_frame, nchan_out; + int16_t ch, output_frame, nchan_out; Decoder_State *st; /* used for bitstream handling */ float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; /* 'float' buffer for output synthesis, MAX_OUTPUT_CHANNELS channels */ /* IVAS_fmToDo: buffer can be allocated dynamically based on the actual number of output channels */ int16_t nchan_remapped; @@ -103,9 +103,9 @@ ivas_error ivas_dec( if ( st_ivas->bfi && st_ivas->ini_frame == 0 ) { /* zero output when first frame(s) is lost */ - for ( n = 0; n < nchan_out; n++ ) + for ( ch = 0; ch < nchan_out; ch++ ) { - set_f( output[n], 0.0f, output_frame ); + set_f( output[ch], 0.0f, output_frame ); } #ifdef DEBUG_MODE_INFO @@ -125,9 +125,9 @@ ivas_error ivas_dec( } /* HP filtering */ - for ( n = 0; n < min( nchan_out, st_ivas->nchan_transport ); n++ ) + for ( ch = 0; ch < min( nchan_out, st_ivas->nchan_transport ); ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -148,15 +148,15 @@ ivas_error ivas_dec( ivas_ism_metadata_dec( ivas_total_brate, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, NULL ); } - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - if ( ( error = ivas_sce_dec( st_ivas, n, &output[n], output_frame, nb_bits_metadata[n] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sce_dec( st_ivas, ch, &output[ch], output_frame, nb_bits_metadata[ch] ) ) != IVAS_ERR_OK ) { return error; } /* HP filtering */ - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -297,9 +297,9 @@ ivas_error ivas_dec( /* HP filtering */ #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC - for ( n = 0; n < nchan_remapped; n++ ) + for ( ch = 0; ch < nchan_remapped; ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } #endif if ( st_ivas->ivas_format == SBA_FORMAT ) @@ -320,9 +320,9 @@ ivas_error ivas_dec( { float gain = 0.8414f; /* Todo: Temporary gain for roughly matching the loudness. To be tuned later together with other outputs. */ - for ( n = 0; n < nchan_remapped; n++ ) + for ( ch = 0; ch < nchan_remapped; ch++ ) { - v_multc( output[n], gain, output[n], output_frame ); + v_multc( output[ch], gain, output[ch], output_frame ); } } @@ -368,11 +368,11 @@ ivas_error ivas_dec( mvr2r( output_lfe_ch, output[LFE_CHANNEL], output_frame ); /* HP filtering */ - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - if ( n != LFE_CHANNEL ) + if ( ch != LFE_CHANNEL ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } } @@ -427,9 +427,9 @@ ivas_error ivas_dec( } /* HP filtering */ - for ( n = 0; n < st_ivas->nchan_transport; n++ ) + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -464,10 +464,10 @@ ivas_error ivas_dec( } /* Identify the index of the separated channel */ - n = st_ivas->hOutSetup.separateChannelIndex; + ch = st_ivas->hOutSetup.separateChannelIndex; /* Decode the separated channel to output[n] to be combined with the synthesized channels */ - if ( ( error = ivas_sce_dec( st_ivas, 0, &output[n], output_frame, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sce_dec( st_ivas, 0, &output[ch], output_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -477,12 +477,12 @@ ivas_error ivas_dec( output_config == AUDIO_CONFIG_5_1_4 || output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_2 || ( output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) { - ivas_lfe_synth_with_filters( st_ivas->hMasa->hMasaLfeSynth, output, output_frame, n, LFE_CHANNEL ); + ivas_lfe_synth_with_filters( st_ivas->hMasa->hMasaLfeSynth, output, output_frame, ch, LFE_CHANNEL ); } else if ( output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 ) { /* Delay the separated channel to sync with the DirAC rendering */ - delay_signal( output[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); + delay_signal( output[ch], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size ); } } else @@ -509,9 +509,9 @@ ivas_error ivas_dec( } /* HP filtering */ - for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + for ( ch = 0; ch < getNumChanSynthesis( st_ivas ); ch++ ) { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + hp20( output[ch], output_frame, st_ivas->mem_hp20_out[ch], output_Fs ); } /* Rendering */ @@ -529,9 +529,9 @@ ivas_error ivas_dec( } else if ( st_ivas->intern_config == AUDIO_CONFIG_5_1 && ( output_config == AUDIO_CONFIG_5_1_2 || output_config == AUDIO_CONFIG_5_1_4 || output_config == AUDIO_CONFIG_7_1 ) ) { - for ( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; n++ ) + for ( ch = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ch < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; ch++ ) { - set_zero( output[n], output_frame ); + set_zero( output[ch], output_frame ); } } } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 116288299d..17d474718f 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2343,12 +2343,12 @@ void ivas_dirac_dec( { float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t outchannels; + int16_t nchan_out; idx_in = 0; idx_lfe = 0; - outchannels = hDirAC->hOutSetup.nchan_out_woLFE + hDirAC->hOutSetup.num_lfe; + nchan_out = hDirAC->hOutSetup.nchan_out_woLFE + hDirAC->hOutSetup.num_lfe; if ( hDirAC->hOutSetup.separateChannelEnabled && ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || @@ -2356,7 +2356,7 @@ void ivas_dirac_dec( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) { - outchannels++; + nchan_out++; } if ( hDirAC->hOutSetup.separateChannelEnabled && hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM ) @@ -2370,7 +2370,7 @@ void ivas_dirac_dec( mvr2r( &( output_f[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated, num_samples_subframe ); mvr2r( &( output_f[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe, num_samples_subframe ); - for ( ch = 0; ch < outchannels; ch++ ) + for ( ch = 0; ch < nchan_out; ch++ ) { if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) ) { @@ -2411,7 +2411,7 @@ void ivas_dirac_dec( } else { - for ( ch = 0; ch < outchannels; ch++ ) + for ( ch = 0; ch < nchan_out; ch++ ) { if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) ) { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 460efb7e22..03932b51d9 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -285,7 +285,7 @@ static void ivas_param_ism_rendering( const int16_t num_ch_LS, const int16_t nchan_transport ) { - int16_t outchIdx, inchIdx, bin_idx; + int16_t ch_out, ch_inp, bin_idx; float tmp_1, mixing_matrix_smooth; tmp_1 = hDirAC->hParamIsmRendering->interpolator[slot_idx]; @@ -293,15 +293,15 @@ static void ivas_param_ism_rendering( for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ ) { /* smooth the mixing matrix */ - for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) + for ( ch_out = 0; ch_out < num_ch_LS; ch_out++ ) { - for ( inchIdx = 0; inchIdx < nchan_transport; inchIdx++ ) + for ( ch_inp = 0; ch_inp < nchan_transport; ch_inp++ ) { - mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][outchIdx + inchIdx * num_ch_LS] + - ( 1 - tmp_1 ) * hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * num_ch_LS]; + mixing_matrix_smooth = tmp_1 * mixing_matrix[bin_idx][ch_out + ch_inp * num_ch_LS] + + ( 1 - tmp_1 ) * hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][ch_out + ch_inp * num_ch_LS]; - Cldfb_RealBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[inchIdx][slot_idx][bin_idx]; - Cldfb_ImagBuffer[outchIdx][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[inchIdx][slot_idx][bin_idx]; + Cldfb_RealBuffer[ch_out][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_RealBuffer_in[ch_inp][slot_idx][bin_idx]; + Cldfb_ImagBuffer[ch_out][out_slot_idx][bin_idx] += mixing_matrix_smooth * Cldfb_ImagBuffer_in[ch_inp][slot_idx][bin_idx]; } } } @@ -354,7 +354,7 @@ static void ivas_param_ism_update_mixing_matrix( const int16_t nchan_inp, const int16_t nchan_out ) { - int16_t inchIdx, outchIdx, bin_idx, band_idx; + int16_t ch_inp, ch_out, bin_idx, band_idx; int16_t brange[2]; for ( band_idx = 0; band_idx < hDirAC->hParamIsm->nbands; band_idx++ ) @@ -364,11 +364,11 @@ static void ivas_param_ism_update_mixing_matrix( for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { - for ( inchIdx = 0; inchIdx < nchan_inp; inchIdx++ ) + for ( ch_inp = 0; ch_inp < nchan_inp; ch_inp++ ) { - for ( outchIdx = 0; outchIdx < nchan_out; outchIdx++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][outchIdx + inchIdx * nchan_out] = mixing_matrix[bin_idx][outchIdx + inchIdx * nchan_out]; + hDirAC->hParamIsmRendering->mixing_matrix_lin_old[bin_idx][ch_out + ch_inp * nchan_out] = mixing_matrix[bin_idx][ch_out + ch_inp * nchan_out]; } } } diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 09f8c7a1ff..20db40d71b 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -256,7 +256,7 @@ void ivas_sba_mix_matrix_determiner( { int16_t i, ch; float temp; - int16_t num_bands_out, nchan_transport, nchan_out; + int16_t num_bands_out, nchan_transport; /* Convert numeric range */ for ( ch = 0; ch < nchan_remapped; ch++ ) @@ -281,11 +281,10 @@ void ivas_sba_mix_matrix_determiner( /* AGC */ nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - nchan_out = nchan_transport; ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); /* Convert numeric range back */ - for ( ch = 0; ch < nchan_out; ch++ ) + for ( ch = 0; ch < nchan_transport; ch++ ) { for ( i = 0; i < output_frame; i++ ) { @@ -322,7 +321,7 @@ void ivas_sba_prototype_renderer( int16_t b, ts; int16_t num_cldfb_bands, nchan_inp, nchan_out; int16_t cldfb_band; - int16_t out_ch, in_ch; + int16_t ch_out, ch_in; int16_t firstSlot, slotEnd, firstInCh, inChEnd, firstOutCh, outChEnd; int16_t sf_idx; @@ -367,17 +366,17 @@ void ivas_sba_prototype_renderer( float cldfb_par; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + for ( ch_out = firstOutCh; ch_out < outChEnd; ch_out++ ) { - out_re[out_ch] = 0.0f; - out_im[out_ch] = 0.0f; + out_re[ch_out] = 0.0f; + out_im[ch_out] = 0.0f; - for ( in_ch = firstInCh; in_ch < inChEnd; in_ch++ ) + for ( ch_in = firstInCh; ch_in < inChEnd; ch_in++ ) { if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; - cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + cldfb_par = mixer_mat[ch_out][ch_in][spar_band]; } else { @@ -385,20 +384,20 @@ void ivas_sba_prototype_renderer( for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + cldfb_par += mixer_mat[ch_out][ch_in][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; } } - out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par; - out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par; + out_re[ch_out] += inRe[ch_in][ts][cldfb_band] * cldfb_par; + out_im[ch_out] += inIm[ch_in][ts][cldfb_band] * cldfb_par; } } /*update CLDFB data with the parameter-modified data*/ - for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) + for ( ch_out = firstOutCh; ch_out < outChEnd; ch_out++ ) { - inRe[out_ch][ts][cldfb_band] = out_re[out_ch]; - inIm[out_ch][ts][cldfb_band] = out_im[out_ch]; + inRe[ch_out][ts][cldfb_band] = out_re[ch_out]; + inIm[ch_out][ts][cldfb_band] = out_im[ch_out]; } } @@ -413,13 +412,13 @@ void ivas_sba_prototype_renderer( mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + sf_idx * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev[4][ch_out][ch_in][b] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][b + sf_idx * IVAS_MAX_NUM_BANDS]; } } } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 27771a93d2..b9327c4208 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -777,12 +777,12 @@ void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t ts, - const int16_t num_ch_out, - const int16_t num_ch_in, + const int16_t nchan_out, + const int16_t nchan_inp, const int16_t num_spar_bands, float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { - int16_t spar_band, out_ch, in_ch; + int16_t spar_band, ch_out, ch_in; float weight, weight_20ms; int16_t ts0, ts1, split_band; @@ -791,30 +791,30 @@ void ivas_spar_get_parameters( split_band = SPAR_DIRAC_SPLIT_START_BAND; for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - for ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { if ( split_band < IVAS_MAX_NUM_BANDS /* 20ms cross-fade for Transport channels in all frequency bands */ - && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ + && ( 0 == ivas_is_res_channel( ch_out, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ ) { if ( hSpar->i_subframe > 3 ) { - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + - weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; + par_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][ch_out][ch_in][spar_band] + + weight * hSpar->hMdDec->mixer_mat_prev[ts1][ch_out][ch_in][spar_band]; } else { - par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + par_mat[ch_out][ch_in][spar_band] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; } } else { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + par_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][ch_out][ch_in][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; } } } @@ -832,26 +832,26 @@ void ivas_spar_get_parameters( static void ivas_spar_get_skip_mat( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const int16_t num_ch_out, - const int16_t num_ch_in, + const int16_t nchan_out, + const int16_t nchan_inp, const int16_t num_spar_bands, int16_t skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) { - int16_t spar_band, out_ch, in_ch; + int16_t spar_band, ch_out, ch_in; int16_t i_ts, skip_flag; - for ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { - skip_mat[out_ch][in_ch] = 1; + skip_mat[ch_out][ch_in] = 1; skip_flag = 1; for ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { - if ( hSpar->hMdDec->mixer_mat_prev[1 + i_ts][out_ch][in_ch][spar_band] != 0.0f || hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band + i_ts * MAX_PARAM_SPATIAL_SUBFRAMES] != 0.0f ) + if ( hSpar->hMdDec->mixer_mat_prev[1 + i_ts][ch_out][ch_in][spar_band] != 0.0f || hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band + i_ts * MAX_PARAM_SPATIAL_SUBFRAMES] != 0.0f ) { skip_flag = 0; break; @@ -860,7 +860,7 @@ static void ivas_spar_get_skip_mat( if ( skip_flag == 0 ) { - skip_mat[out_ch][in_ch] = 0; + skip_mat[ch_out][ch_in] = 0; break; } } @@ -888,7 +888,7 @@ void ivas_spar_dec_upmixer( int16_t cldfb_band, num_cldfb_bands; float *cldfb_in_ts_re[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; float *cldfb_in_ts_im[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; - int16_t i, b, ts, out_ch, in_ch; + int16_t i, b, ts, ch_out, ch_in; int16_t num_spar_bands, spar_band, num_bands_out, split_band; float Pcm_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; float *pPcm_tmp[MAX_OUTPUT_CHANNELS]; @@ -937,9 +937,9 @@ void ivas_spar_dec_upmixer( } for ( smp = 0; smp < L_FRAME48k; smp++ ) { - for ( in_ch = 0; in_ch < nchan_transport; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_transport; ch_in++ ) { - fread( &output[in_ch][smp], sizeof( float ), 1, fid_enc ); + fread( &output[ch_in][smp], sizeof( float ), 1, fid_enc ); } } } @@ -1019,23 +1019,23 @@ void ivas_spar_dec_upmixer( if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { /* at this point, output channels are used as intermediate procesing buffers */ - for ( in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS; in_ch++ ) + for ( ch_in = 0; ch_in < MAX_OUTPUT_CHANNELS; ch_in++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; + cldfb_in_ts_re[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands]; + cldfb_in_ts_im[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands + 4 * num_cldfb_bands]; } } } else { - for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { - cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; + cldfb_in_ts_re[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands]; + cldfb_in_ts_im[ch_in][ts] = &Pcm_tmp[ch_in][ts * num_cldfb_bands + 4 * num_cldfb_bands]; } } } @@ -1060,16 +1060,16 @@ void ivas_spar_dec_upmixer( for ( int16_t i_sf = 0; i_sf < MAX_PARAM_SPATIAL_SUBFRAMES; i_sf++ ) { /* CLDFB analysis of incoming frame */ - for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { cldfbAnalysis_ts( - &output[in_ch][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], - cldfb_in_ts_re[in_ch][ts], - cldfb_in_ts_im[in_ch][ts], + &output[ch_in][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], + cldfb_in_ts_re[ch_in][ts], + cldfb_in_ts_im[ch_in][ts], num_cldfb_bands, - st_ivas->cldfbAnaDec[in_ch] ); + st_ivas->cldfbAnaDec[ch_in] ); } } @@ -1085,21 +1085,21 @@ void ivas_spar_dec_upmixer( float cldfb_par; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - out_re[out_ch] = 0.0f; - out_im[out_ch] = 0.0f; + out_re[ch_out] = 0.0f; + out_im[ch_out] = 0.0f; - for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { - if ( b_skip_mat[out_ch][in_ch] ) + if ( b_skip_mat[ch_out][ch_in] ) { continue; } else if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; - cldfb_par = mixer_mat[out_ch][in_ch][spar_band]; + cldfb_par = mixer_mat[ch_out][ch_in][spar_band]; } else { @@ -1107,20 +1107,20 @@ void ivas_spar_dec_upmixer( for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; + cldfb_par += mixer_mat[ch_out][ch_in][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band]; } } - out_re[out_ch] += cldfb_in_ts_re[in_ch][ts][cldfb_band] * cldfb_par; - out_im[out_ch] += cldfb_in_ts_im[in_ch][ts][cldfb_band] * cldfb_par; + out_re[ch_out] += cldfb_in_ts_re[ch_in][ts][cldfb_band] * cldfb_par; + out_im[ch_out] += cldfb_in_ts_im[ch_in][ts][cldfb_band] * cldfb_par; } } /*update CLDFB data with the parameter-modified data*/ - for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - cldfb_in_ts_re[out_ch][ts][cldfb_band] = out_re[out_ch]; - cldfb_in_ts_im[out_ch][ts][cldfb_band] = out_im[out_ch]; + cldfb_in_ts_re[ch_out][ts][cldfb_band] = out_re[ch_out]; + cldfb_in_ts_im[ch_out][ts][cldfb_band] = out_im[ch_out]; } } } @@ -1132,12 +1132,12 @@ void ivas_spar_dec_upmixer( if ( st_ivas->hDirAC != NULL ) { - int16_t outchannels, idx_in, idx_lfe, ch; + int16_t nchan, idx_in, idx_lfe, ch; idx_in = 0; idx_lfe = 0; - outchannels = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; - for ( ch = 0; ch < outchannels; ch++ ) + nchan = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + for ( ch = 0; ch < nchan; ch++ ) { if ( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( st_ivas->hOutSetup.index_lfe[idx_lfe] == ch ) ) { @@ -1167,26 +1167,26 @@ void ivas_spar_dec_upmixer( } } #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->numOutChannels = outchannels; + hSpar->numOutChannels = nchan; #endif } else { /* CLDFB to time synthesis (overwrite mixer output) */ - for ( out_ch = 0; out_ch < hDecoderConfig->nchan_out; out_ch++ ) + for ( ch_out = 0; ch_out < hDecoderConfig->nchan_out; ch_out++ ) { for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { cldfbSynthesis( - &cldfb_in_ts_re[out_ch][ts], - &cldfb_in_ts_im[out_ch][ts], - &output[out_ch][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], + &cldfb_in_ts_re[ch_out][ts], + &cldfb_in_ts_im[ch_out][ts], + &output[ch_out][( ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES ) * num_cldfb_bands], num_cldfb_bands, - st_ivas->cldfbSynDec[out_ch] ); + st_ivas->cldfbSynDec[ch_out] ); } } #ifdef DEBUG_SBA_AUDIO_DUMP - hSpar->numOutChannels = numch_out_dirac; + hSpar->numOutChannels = nchan; #endif } #ifdef DEBUG_SBA_AUDIO_DUMP @@ -1204,13 +1204,13 @@ void ivas_spar_dec_upmixer( mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_SPAR_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - for ( out_ch = 0; out_ch < nchan_out; out_ch++ ) + for ( ch_out = 0; ch_out < nchan_out; ch_out++ ) { - for ( in_ch = 0; in_ch < nchan_inp; in_ch++ ) + for ( ch_in = 0; ch_in < nchan_inp; ch_in++ ) { for ( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + i_sf * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev[4][ch_out][ch_in][b] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][b + i_sf * IVAS_MAX_NUM_BANDS]; } } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 75ffc5212d..9482a9e003 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -55,7 +55,7 @@ ivas_error ivas_enc( const int16_t n_samples /* i : number of input samples */ ) { - int16_t i, n, input_frame, n_samples_chan, nchan_inp; + int16_t i, ch, input_frame, n_samples_chan, nchan_inp; int32_t input_Fs; IVAS_FORMAT ivas_format; ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -90,8 +90,8 @@ ivas_error ivas_enc( * convert 'short' input data to 'float' *----------------------------------------------------------------*/ - n = 0; - while ( n < nchan_inp ) + ch = 0; + while ( ch < nchan_inp ) { #ifdef DEBUG_MODE_LFE if ( n == LFE_CHANNEL ) @@ -99,23 +99,23 @@ ivas_error ivas_enc( int16_t tmp[L_FRAME48k]; for ( i = 0; i < n_samples_chan; i++ ) { - tmp[i] = data[i * nchan_inp + n]; + tmp[i] = data[i * nchan_inp + nch]; } dbgwrite( tmp, sizeof( int16_t ), n_samples_chan, 1, "./lfe_chan_in.raw" ); } #endif for ( i = 0; i < n_samples_chan; i++ ) { - data_f[n][i] = (float) data[i * nchan_inp + n]; + data_f[ch][i] = (float) data[i * nchan_inp + ch]; } - n++; + ch++; } if ( n_samples_chan < input_frame ) { - for ( n = 0; n < nchan_inp; n++ ) + for ( ch = 0; ch < nchan_inp; ch++ ) { - set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); + set_f( data_f[ch] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); } } @@ -127,10 +127,10 @@ ivas_error ivas_enc( * HP filtering *----------------------------------------------------------------*/ - n = getNumChanAnalysis( st_ivas ); + ch = getNumChanAnalysis( st_ivas ); #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ - for ( i = 0; i < n; i++ ) + for ( i = 0; i < ch; i++ ) { if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) /*TODO: is the HPF needed for LFE channel? */ { -- GitLab From cdaa9dd9cd043d1a161e6d34ecf2254a7438a4bf Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 18 Oct 2022 16:38:57 +0200 Subject: [PATCH 21/26] fix prerenderer compilation error --- lib_util/ivas_prerenderer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ivas_prerenderer.c b/lib_util/ivas_prerenderer.c index a2c0b4c710..018d8f1dc5 100644 --- a/lib_util/ivas_prerenderer.c +++ b/lib_util/ivas_prerenderer.c @@ -1715,7 +1715,7 @@ static void ivas_limiter_prerenderer( } channels = hLimiter->channel_ptrs; - num_channels = hLimiter->num_channels; + num_channels = hLimiter->nchan; for ( c = 0; c < num_channels; ++c ) { -- GitLab From 4fa66a3781fbaf08f92aada216f69cb4e63cf410 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 20 Oct 2022 15:53:59 +0200 Subject: [PATCH 22/26] change nchan -> nchan_dmx --- lib_dec/ivas_spar_md_dec.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index bb81448b81..ac950784f3 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -750,18 +750,18 @@ void ivas_spar_smooth_md_dtx( const int16_t num_bands_out /* i : number of output bands */ ) { - int16_t j, k, b, nchan; + int16_t j, k, b, nchan_dmx; float ramp, tar, prev, new_val; ramp = (float) hMdDec->dtx_md_smoothing_cntr / IVAS_DEFAULT_DTX_CNG_RAMP; for ( b = 0; b < num_bands_out; b++ ) { - nchan = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; for ( j = 1; j < FOA_CHANNELS; j++ ) { - for ( k = nchan; k < FOA_CHANNELS; k++ ) + for ( k = nchan_dmx; k < FOA_CHANNELS; k++ ) { prev = hMdDec->spar_coeffs_prev.P_re[j][k][b]; tar = hMdDec->spar_coeffs_tar.P_re[j][k][b]; @@ -772,7 +772,7 @@ void ivas_spar_smooth_md_dtx( for ( j = 0; j < FOA_CHANNELS; j++ ) { - for ( k = 0; k < nchan; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { prev = hMdDec->spar_coeffs_prev.C_re[j][k][b]; tar = hMdDec->spar_coeffs_tar.C_re[j][k][b]; @@ -787,11 +787,11 @@ void ivas_spar_smooth_md_dtx( { for ( b = 0; b < num_bands_out; b++ ) { - nchan = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + nchan_dmx = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; for ( j = 1; j < FOA_CHANNELS; j++ ) { - for ( k = nchan; k < FOA_CHANNELS; k++ ) + for ( k = nchan_dmx; k < FOA_CHANNELS; k++ ) { hMdDec->spar_coeffs.P_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re[j][k][b]; } @@ -799,7 +799,7 @@ void ivas_spar_smooth_md_dtx( for ( j = 0; j < FOA_CHANNELS; j++ ) { - for ( k = 0; k < nchan; k++ ) + for ( k = 0; k < nchan_dmx; k++ ) { hMdDec->spar_coeffs.C_re[j][k][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re[j][k][b]; } -- GitLab From 5678b8eb30858abe420cb09ed54b0150c06d0cf4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 24 Oct 2022 19:14:04 +0200 Subject: [PATCH 23/26] - revert: Merge branch 'main' into 22-terminology-for-the-number-of-channels - merge with main --- lib_com/ivas_cnst.h | 7 +- lib_com/ivas_cov_smooth.c | 2 +- lib_com/ivas_prot.h | 26 +- lib_com/ivas_sns_com.c | 4 - lib_com/ivas_stereo_psychlpc_com.c | 3 - lib_com/options.h | 4 +- lib_com/prot.h | 24 -- lib_com/tools.c | 2 +- lib_debug/mem_count.c | 4 + lib_debug/sba_debug.c | 2 +- lib_debug/sba_debug.h | 2 +- lib_dec/ACcontextMapping_dec.c | 2 +- lib_dec/acelp_core_dec.c | 16 -- lib_dec/amr_wb_dec.c | 4 - lib_dec/core_dec_init.c | 12 - lib_dec/core_dec_switch.c | 6 - lib_dec/dec_LPD.c | 8 - lib_dec/dec_acelp_tcx_main.c | 4 - lib_dec/dec_prm.c | 10 - lib_dec/dec_tcx.c | 60 ---- lib_dec/er_dec_tcx.c | 10 - lib_dec/evs_dec.c | 4 - lib_dec/fd_cng_dec.c | 79 ------ lib_dec/igf_dec.c | 23 -- lib_dec/init_dec.c | 10 - lib_dec/ivas_binauralRenderer.c | 13 +- lib_dec/ivas_binaural_reverb.c | 3 + lib_dec/ivas_core_dec.c | 22 -- lib_dec/ivas_cpe_dec.c | 4 - lib_dec/ivas_dirac_dec.c | 21 +- lib_dec/ivas_dirac_dec_binaural_functions.c | 64 ++++- lib_dec/ivas_efap.c | 106 ++++++- lib_dec/ivas_init_dec.c | 13 +- lib_dec/ivas_mct_dec_mct.c | 4 - lib_dec/ivas_mdct_core_dec.c | 44 --- lib_dec/ivas_sba_dec.c | 300 +++++++++++++++++++- lib_dec/ivas_sba_rendering.c | 14 +- lib_dec/ivas_sce_dec.c | 6 +- lib_dec/ivas_spar_decoder.c | 42 ++- lib_dec/ivas_spar_md_dec.c | 26 +- lib_dec/ivas_stat_dec.h | 6 +- lib_dec/ivas_stereo_mdct_core_dec.c | 18 -- lib_dec/ivas_stereo_switching_dec.c | 12 - lib_dec/ivas_tcx_core_dec.c | 24 -- lib_dec/stat_dec.h | 2 - lib_dec/tonalMDCTconcealment.c | 28 -- lib_enc/acelp_core_enc.c | 2 +- lib_enc/enc_prm.c | 8 - lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_dirac_enc.c | 11 +- lib_enc/ivas_enc.c | 4 + lib_enc/ivas_ism_param_enc.c | 9 +- lib_enc/ivas_mct_enc.c | 16 ++ lib_enc/ivas_mdct_core_enc.c | 10 - lib_enc/ivas_sba_enc.c | 181 +++++++++++- lib_enc/ivas_sce_enc.c | 22 +- lib_enc/ivas_sns_enc.c | 169 ----------- lib_enc/ivas_spar_encoder.c | 55 +++- lib_enc/ivas_spar_md_enc.c | 13 +- lib_enc/ivas_stat_enc.h | 4 +- lib_enc/ivas_stereo_mdct_core_enc.c | 1 + lib_enc/ivas_tcx_core_enc.c | 4 - scripts/config/self_test.prm | 16 +- scripts/pyaudio3dtools/EFAP.py | 34 ++- 64 files changed, 873 insertions(+), 788 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index fe9cb54a69..684462b41b 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -793,14 +793,11 @@ enum fea_names #define MAX_MDCT_ITD_BRATE IVAS_64k #define SNS_LOW_BR_MODE -1 -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE #define SNS_NPTS 16 /* Number of downsampled SNS parameters */ #define MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG 0.001f -#ifdef FADE_TO_ZERO_FOR_TOO_LONG_FRAMELOSS #define MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME 2 * FRAMES_PER_SEC #define MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN 20 -#endif typedef enum { EQUAL_CORES, @@ -812,7 +809,6 @@ typedef enum { ON_FIRST_LOST_FRAME, ON_FIRST_GOOD_FRAME, } TONALMDCTCONC_NOISE_SHAPE_WHITENING_MODE; -#endif /*----------------------------------------------------------------------------------* @@ -911,6 +907,9 @@ typedef enum { DIRAC_OPEN, /* initialize to default value */ DIRAC_RECONFIGURE /* HOA3 */ +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV - just dirty patch for the moment + ,DIRAC_RECONFIGURE_MODE /* HOA3 */ +#endif } DIRAC_CONFIG_FLAG; diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 49a833843c..3ebd1ba3f7 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -267,7 +267,7 @@ void ivas_cov_smooth_process( #ifdef SBA_SPAR_HARM ivas_compute_smooth_cov( hCovState, pFb, cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, nchan, transient_det ); #else - ivas_compute_smooth_cov( hCovState, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band, nchan, transient_det ); + ivas_compute_smooth_cov( hCovState, pIn_buf, pFb, pIn_buf->cov_real, hCovState->pPrior_cov_real, 1e-20f, start_band, end_band ); #endif for ( i = 0; i < nchan; i++ ) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b05d7961f4..df3c780eec 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1985,9 +1985,7 @@ void decoder_tcx_invQ( void decoder_tcx_noisefilling( Decoder_State *st, /* i/o: coder memory state */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float concealment_noise[L_FRAME48k], -#endif const float A[], /* i : coefficients NxAz[M+1] */ const int16_t L_frameTCX_glob, const int16_t L_spec, @@ -2000,9 +1998,7 @@ void decoder_tcx_noisefilling( const int16_t *prm_sqQ, int16_t nf_seed, const int16_t bfi, /* i : Bad frame indicator */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t isMCT, -#endif const int16_t frame_cnt /* i : frame counter in the super frame */ ); @@ -2085,12 +2081,8 @@ void decoder_tcx_IGF_stereo( const int16_t L_frame, /* i : frame length */ const int16_t left_rect, /* i : left part is rectangular */ const int16_t k, /* i : Subframe index */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t bfi, /* i : bad frame indicator */ const int16_t is_mct /* i : flag to signal MCT or SMDCT */ -#else - const int16_t bfi /* i : bad frame indicator */ -#endif ); void ms_processing( @@ -2123,12 +2115,8 @@ void IGFDecApplyStereo( const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ const int16_t *coreMsMask, const int16_t restrict_hopsize, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t bfi, /* i : frame loss == 1, frame good == 0 */ const int16_t bfi_apply_damping /* i : decoder element mode */ -#else - const int16_t bfi /* i : frame loss == 1, frame good == 0 */ -#endif ); void IGFEncStereoEncoder( @@ -3113,7 +3101,7 @@ void ivas_sba_getTCs( ); ivas_error ivas_sba_linear_renderer( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ const int16_t nchan_inp, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ @@ -3907,6 +3895,14 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); +#ifdef SBA_BITRATE_SWITCHING +ivas_error ivas_spar_md_enc_init( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +); +#endif + ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -3999,7 +3995,7 @@ void ivas_spar_get_parameters( const int16_t nchan_out, /* i : number of channels out */ const int16_t nchan_inp, /* i : number of channels in */ const int16_t num_spar_bands, /* i : number of SPAR bands */ - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ ); ivas_error ivas_spar_md_dec_init( @@ -5490,7 +5486,6 @@ ivas_error ivas_orient_trk_GetTrackedOrientation( float *roll ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE void TonalMdctConceal_create_concealment_noise( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, @@ -5514,7 +5509,6 @@ int16_t get_igf_startline( int16_t L_frame, int16_t L_frameTCX ); -#endif float rand_triangular_signed( int16_t *seed ); diff --git a/lib_com/ivas_sns_com.c b/lib_com/ivas_sns_com.c index d975435994..cc0f07ffe0 100644 --- a/lib_com/ivas_sns_com.c +++ b/lib_com/ivas_sns_com.c @@ -37,15 +37,12 @@ #include "ivas_prot.h" #include "rom_com.h" #include -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE #include -#endif #ifdef DEBUGGING #include "debug.h" #endif #include "wmops.h" -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE /*------------------------------------------------------------------- * sns_compute_scf() @@ -212,7 +209,6 @@ void sns_compute_scf( return; } -#endif /*------------------------------------------------------------------- * sns_interpolate_scalefactors() diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c index cdc48f5f98..3cbca73cc0 100644 --- a/lib_com/ivas_stereo_psychlpc_com.c +++ b/lib_com/ivas_stereo_psychlpc_com.c @@ -68,9 +68,6 @@ static void SpectrumWeighting_Init( * initialize a PsychoacousticParameters structure *-------------------------------------------------------------------*/ -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE -static -#endif ivas_error PsychoacousticParameters_Init( const int32_t sr_core, /* i : sampling rate of core-coder */ diff --git a/lib_com/options.h b/lib_com/options.h index 5906991cdf..ebdbd88530 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -142,8 +142,6 @@ #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 MDCT_STEREO_PLC_FADE_2_BG_NOISE /* IVAS-185 fix bug in TCX-PLC fadeout for MDCT-Stereo and improve fadeout by fading to background noise instead of white noise */ -#define FADE_TO_ZERO_FOR_TOO_LONG_FRAMELOSS /*#define FIX_I1_113*/ /* under review : MCT bit distribution optimization for SBA high bitrates*/ #define FIX_I13_TCX_TNS_ISSUE /* Issue 13: Fix reported artifacts. Bug in TNS with TCX5 */ @@ -152,7 +150,9 @@ #define ISM_BITRATE_SWITCHING /* Issue 115: Support for Bitrate Switching in ISM */ #define SBA_SPAR_HARM /* Issue 92: maintenance of the SBA SPAR functions */ #define FIX_155_HP20_ISSUE /* Issue 155: apply hp20 on all input channels instead of just 2 channels */ +#define EFAP_FIX_POLY /* Issue 167: fix bug in EFAP polygon selection */ +#define SBA_BITRATE_SWITCHING /* Issue 114: suppport bitrate switching in SBA - CORECODER_BITRATE_SWITCHING must be defined */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index cffd699e46..5bc1e39753 100755 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -5145,10 +5145,8 @@ void decod_amr_wb( ivas_error init_decoder( Decoder_State *st, /* o : Decoder static variables structure */ const int16_t idchan /* i : channel ID */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const MC_MODE mc_mode /* i : MC mode */ -#endif ); void destroy_decoder( @@ -6776,10 +6774,8 @@ void enc_acelp_tcx_main( void getTCXMode( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0 /* i : bitstream */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t MCT_flag -#endif ); void getTCXWindowing( @@ -7893,10 +7889,8 @@ void decoder_tcx_post( float *synthFB, float *A, const int16_t bfi -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t isMCT -#endif ); void coder_acelp( @@ -7949,9 +7943,7 @@ void decoder_acelp( void writeTCXMode( Encoder_State *st, /* i/o: encoder state structure */ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t is_mct, -#endif int16_t *nbits_start /* o : nbits start */ ); @@ -8140,10 +8132,8 @@ void con_tcx( const float coh, /* i : coherence of stereo signal */ int16_t *noise_seed, /* i/o: noise seed for stereo */ const int16_t only_left /* i : TD-PLC only in left channel */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const float *A_cng -#endif ); /*! r: codebook index */ @@ -8689,9 +8679,7 @@ void configureFdCngDec( void ApplyFdCng( float *timeDomainInput, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float *powerSpectrum, -#endif float **realBuffer, /* i/o: Real part of the buffer */ float **imagBuffer, /* i/o: Imaginary part of the buffer */ Decoder_State *st, @@ -8700,9 +8688,7 @@ void ApplyFdCng( void perform_noise_estimation_dec( const float *timeDomainInput, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float *power_spectrum, -#endif HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ const int16_t element_mode, /* i : element mode type */ const int16_t bwidth, /* i : audio bandwidth */ @@ -9202,9 +9188,7 @@ void open_decoder_LPD( const int32_t last_total_brate, /* i : last total bitrate */ const int16_t bwidth, /* i : audio bandwidth */ const int16_t is_mct, /* i : MCT mode flag */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t last_element_mode, -#endif const int16_t is_init /* i : indicate call during initialization */ ); @@ -9245,10 +9229,8 @@ void mode_switch_decoder_LPD( const int32_t last_total_brate, /* i : last frame total bitrate */ const int16_t frame_size_index, /* i : index determining the frame size*/ const int16_t is_mct /* i : MCT mode flag */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t last_element_mode /* i : last element mode */ -#endif ); void dec_acelp_tcx_frame( @@ -9529,10 +9511,8 @@ void TonalMDCTConceal_SaveFreqSignal( const uint16_t numSamples, const uint16_t nNewSamplesCore, const float *scaleFactors -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t infoIGFStartLine -#endif ); void TonalMDCTConceal_UpdateState( @@ -9567,10 +9547,8 @@ void TonalMDCTConceal_InsertNoise( int16_t *pSeed, /*IN/OUT*/ const float tiltCompFactor, const float crossfadeGain, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const float concealment_noise[L_FRAME48k], const float cngLevelBackgroundTrace_bfi, -#endif const int16_t crossOverFreq ); void DetectTonalComponents( @@ -9605,7 +9583,6 @@ void RefineTonalComponents( float floorPowerSpectrum, const PsychoacousticParameters *psychParamsCurrent ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ivas_error PsychoacousticParameters_Init( const int32_t sr_core, /* i : sampling rate of core-coder */ const int16_t nBins, /* i : Number of bins (spectral lines) */ @@ -9613,7 +9590,6 @@ ivas_error PsychoacousticParameters_Init( const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */ PsychoacousticParameters *pPsychParams ); -#endif void concealment_init( const int16_t L_frameTCX, diff --git a/lib_com/tools.c b/lib_com/tools.c index 3e6e56d5a0..fb2ea7689c 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1447,7 +1447,7 @@ void polezero_filter( } #define WMC_TOOL_MAN - +// VE: define complexity macros here static float fleft_shift( float input, const int16_t shift ) { return ( input * (float) pow( 2.0, (double) shift ) ); diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index b12639ae3f..4d886df70f 100644 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -93,7 +93,11 @@ typedef INT64 int64_t; /* This is the maximum number of allocations for which to keep information. It can be increased if required. */ +#ifdef SBA_BITRATE_SWITCHING +#define MAX_INFO_RECORDS 4000 +#else #define MAX_INFO_RECORDS 3000 +#endif /* This is the length after which the function name will be truncated when the summary is printed. */ diff --git a/lib_debug/sba_debug.c b/lib_debug/sba_debug.c index fb3b208f3f..68fd39f4c0 100644 --- a/lib_debug/sba_debug.c +++ b/lib_debug/sba_debug.c @@ -185,7 +185,7 @@ static void UpdateWave( void ivas_spar_dump_signal_wav( const int16_t input_frame, float **ppPcm, - float pcm_array[IVAS_MAX_NUM_CH][L_FRAME48k], + float pcm_array[IVAS_SPAR_MAX_CH][L_FRAME48k], const int16_t no_channel, WAVEFILEOUT *wave_file, char *location ) diff --git a/lib_debug/sba_debug.h b/lib_debug/sba_debug.h index 8153929286..86e07e5a41 100644 --- a/lib_debug/sba_debug.h +++ b/lib_debug/sba_debug.h @@ -50,7 +50,7 @@ extern WAVEFILEOUT *spar_foa_dec_wav[4]; void ivas_close_agc_debug_files( void ); void ivas_open_agc_debug_files( int16_t agc ); #endif -void ivas_spar_dump_signal_wav( const int16_t input_frame, float **ppPcm, float pcm_array[IVAS_MAX_NUM_CH][L_FRAME48k], const int16_t no_channel, WAVEFILEOUT *wave_file, char *location ); +void ivas_spar_dump_signal_wav( const int16_t input_frame, float **ppPcm, float pcm_array[IVAS_SPAR_MAX_CH][L_FRAME48k], const int16_t no_channel, WAVEFILEOUT *wave_file, char *location ); void ivas_close_sba_encoder_debug_files( void ); void ivas_open_sba_encoder_debug_files( const int32_t fs, const int16_t n_transport, const char *file_tag, const int32_t ivas_total_brate, const int16_t dtx_on ); void ivas_close_sba_decoder_debug_files( const int32_t fs, const int16_t n_ch, const int16_t n_transport, const int16_t pca_ingest_channels ); diff --git a/lib_dec/ACcontextMapping_dec.c b/lib_dec/ACcontextMapping_dec.c index 10fb369741..3308eb38b9 100644 --- a/lib_dec/ACcontextMapping_dec.c +++ b/lib_dec/ACcontextMapping_dec.c @@ -633,8 +633,8 @@ int16_t RCcontextMapping_decode2_no_mem_s17_LCS( /* Update bitstream pointer */ st->next_bit_pos = start_bit_pos + bits_tups + rc_uni_dec_virtual_finish( &rc_st_dec ); - /* Confirm that there is no overflow */ #ifdef DEBUGGING + /* Confirm that there is no overflow */ assert( st->next_bit_pos - start_bit_pos + rest_bits <= 0 ); #endif diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index c108c80998..4c52cdb811 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -156,11 +156,7 @@ ivas_error acelp_core_dec( st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( NULL, NULL, NULL, NULL, st, 0, 0 ); -#else - ApplyFdCng( NULL, NULL, NULL, st, 0, 0 ); -#endif } else { @@ -530,11 +526,7 @@ ivas_error acelp_core_dec( { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = STEREO_DFT_FD_FILT * st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] + ( 1 - STEREO_DFT_FD_FILT ) * st->hFdCngDec->hFdCngCom->sidNoiseEst[i]; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#else - ApplyFdCng( syn, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#endif } generate_comfort_noise_dec( NULL, NULL, st, nchan_out ); @@ -1125,11 +1117,7 @@ ivas_error acelp_core_dec( if ( st->element_mode != IVAS_CPE_TD ) { /*Noise estimate*/ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#else - ApplyFdCng( syn, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#endif } if ( !st->cna_dirac_flag ) @@ -1194,11 +1182,7 @@ ivas_error acelp_core_dec( /*Noise estimate*/ if ( st->idchan == 0 && ( nchan_out == 2 || ( st->core_brate != FRAME_NO_DATA && st->core_brate != SID_2k40 ) ) ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#else - ApplyFdCng( syn, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); -#endif } } } diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 907d90e9ab..29c4f939ed 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -621,11 +621,7 @@ ivas_error amr_wb_dec( /*VAD only for non inactive frame*/ st->VAD = ( st->VAD && ( st->coder_type != INACTIVE ) ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( syn, NULL, NULL, NULL, st, 0, 0 ); -#else - ApplyFdCng( syn, NULL, NULL, st, 0, 0 ); -#endif st->hFdCngDec->hFdCngCom->frame_type_previous = st->m_frame_type; diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index bc8d95e24f..906d24adab 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -57,9 +57,7 @@ void open_decoder_LPD( const int32_t last_total_brate, const int16_t bwidth, const int16_t is_mct, /* i : MCT mode flag */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t last_element_mode, -#endif const int16_t is_init /* i : indicate call from init_decoder() to avoid double TC initialization */ ) { @@ -552,7 +550,6 @@ void open_decoder_LPD( { st->hTcxDec->prev_widow_left_rect = 0; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( is_init || is_mct || !( st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode ) ) { st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV; @@ -563,15 +560,6 @@ void open_decoder_LPD( st->hTcxDec->cummulative_damping_tcx = 1.0f; } -#else - st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV; - st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; - st->hTcxDec->CurrLevelIndex_bfi = 0; - st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV; - set_f( st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); - - st->hTcxDec->cummulative_damping_tcx = 1.0f; -#endif } st->cummulative_damping = 1.0f; diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c index c2084f3f12..cc1619cba0 100644 --- a/lib_dec/core_dec_switch.c +++ b/lib_dec/core_dec_switch.c @@ -57,10 +57,8 @@ void mode_switch_decoder_LPD( const int32_t last_total_brate, /* i : last frame total bitrate */ const int16_t frame_size_index, /* i : index determining the frame size*/ const int16_t is_mct /* i : MCT mode flag */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t last_element_mode /* i : last element mode */ -#endif ) { int16_t fscale, switchWB; @@ -109,11 +107,7 @@ void mode_switch_decoder_LPD( if ( fscale != st->fscale || switchWB || bSwitchFromAmrwbIO || st->last_codec_mode == MODE1 || st->force_lpd_reset ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE open_decoder_LPD( st, total_brate, last_total_brate, bwidth, is_mct, last_element_mode, 0 ); -#else - open_decoder_LPD( st, total_brate, last_total_brate, bwidth, is_mct, 0 ); -#endif } else { diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index a28630886e..c06bee28f9 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -478,11 +478,7 @@ void decoder_LPD( if ( bfi && st->last_core != ACELP_CORE ) { /* PLC: [TCX: TD PLC] */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL ); -#else - con_tcx( st, &synthFB[0], -1.f, NULL, 0 ); -#endif lerp( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX ); st->con_tcx = 1; set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr ); @@ -650,11 +646,7 @@ void decoder_LPD( TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, L_frameTCX ); } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE decoder_tcx_post( st, synth, synthFB, Aq, bfi, 0 ); -#else - decoder_tcx_post( st, synth, synthFB, Aq, bfi ); -#endif if ( st->core == TCX_20_CORE ) { diff --git a/lib_dec/dec_acelp_tcx_main.c b/lib_dec/dec_acelp_tcx_main.c index 1ca75fff20..b9d3481579 100644 --- a/lib_dec/dec_acelp_tcx_main.c +++ b/lib_dec/dec_acelp_tcx_main.c @@ -198,11 +198,7 @@ static void decode_frame_type( st->rate_switching_init = 1; /* Reconf Core */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE mode_switch_decoder_LPD( st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0, st->element_mode ); -#else - mode_switch_decoder_LPD( st, st->bwidth, st->total_brate, st->last_total_brate, frame_size_index, 0 ); -#endif /* Reconf. CLDFB: check if the CLDFB works on the right sample rate */ if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame ) diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index 925b561fd6..d458d62aa4 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -55,10 +55,8 @@ void getTCXMode( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0 /* i : bitstream */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t MCT_flag -#endif ) { uint16_t ind; @@ -94,7 +92,6 @@ void getTCXMode( } st->coder_type = INACTIVE; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) { st->VAD = get_next_indice( st0, 1 ); @@ -103,9 +100,6 @@ void getTCXMode( { st->VAD = 0; } -#else - st->VAD = 0; -#endif } else { @@ -793,11 +787,7 @@ void dec_prm( *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE getTCXMode( st, st, 0 /* <- MCT_flag */ ); -#else - getTCXMode( st, st ); -#endif core = st->core; /* Decode last_core for error concealment */ diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 8f6ee52fed..d625139a47 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -100,11 +100,7 @@ void decoder_tcx( decoder_tcx_invQ( st, prm, A, Aind, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &xn_buf[0], &fUseTns, &tnsData, &gain_tcx, &prm_sqQ, &nf_seed, bfi, frame_cnt ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE decoder_tcx_noisefilling( st, NULL, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, 0, frame_cnt ); -#else - decoder_tcx_noisefilling( st, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, frame_cnt ); -#endif decoder_tcx_noiseshaping_igf( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], &gainlpc2[0], &tmp_concealment_method, bfi ); @@ -129,10 +125,8 @@ void decoder_tcx_post( float *synthFB, float *A, const int16_t bfi -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t isMCT -#endif ) { int16_t i; @@ -184,11 +178,7 @@ void decoder_tcx_post( /* PLC: [TCX: Fade-out] * PLC: update or retrieve the background level */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( bfi == 0 && st->tcxonly && ( st->element_mode != IVAS_CPE_MDCT || isMCT ) && st->clas_dec == UNVOICED_CLAS ) -#else - if ( bfi == 0 && st->tcxonly && st->clas_dec == UNVOICED_CLAS ) -#endif { minimumStatistics( hTcxDec->NoiseLevelMemory_bfi, &hTcxDec->NoiseLevelIndex_bfi, &hTcxDec->CurrLevelIndex_bfi, &hTcxDec->CngLevelBackgroundTrace_bfi, &hTcxDec->LastFrameLevel_bfi, level_syn, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); } @@ -202,7 +192,6 @@ void decoder_tcx_post( if ( st->tcxonly ) { gainCNG = hTcxDec->CngLevelBackgroundTrace_bfi / ( level_syn + 0.01f ); -#ifdef FADE_TO_ZERO_FOR_TOO_LONG_FRAMELOSS if ( st->element_mode == IVAS_CPE_MDCT && !isMCT ) { @@ -215,7 +204,6 @@ void decoder_tcx_post( gainCNG *= 1.f - (float) ( st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; } } -#endif } else { @@ -1077,9 +1065,7 @@ void decoder_tcx_invQ( void decoder_tcx_noisefilling( Decoder_State *st, /* i/o: coder memory state */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float concealment_noise[L_FRAME48k], -#endif const float A[], /* i : coefficients NxAz[M+1] */ const int16_t L_frameTCX_glob, const int16_t L_spec, @@ -1092,9 +1078,7 @@ void decoder_tcx_noisefilling( const int16_t *prm_sqQ, int16_t nf_seed, const int16_t bfi, /* i : Bad frame indicator */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t isMCT, -#endif const int16_t frame_cnt /* i : frame counter in the super frame*/ ) { @@ -1118,27 +1102,7 @@ void decoder_tcx_noisefilling( *-----------------------------------------------------------------*/ /* Init lengths */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE infoIGFStartLine = get_igf_startline( st, L_frame, L_frameTCX ); -#else - if ( st->igf == 0 ) - { - if ( st->narrowBand == 0 ) - { - /* minimum needed for output with sampling rates lower then the - nominal sampling rate */ - infoIGFStartLine = min( L_frameTCX, L_frame ); - } - else - { - infoIGFStartLine = L_frameTCX; - } - } - else - { - infoIGFStartLine = min( st->hIGFDec->infoIGFStartLine, L_frameTCX ); - } -#endif noiseFillingSize = L_spec; if ( st->igf ) @@ -1250,11 +1214,7 @@ void decoder_tcx_noisefilling( if ( !bfi && st->element_mode != IVAS_CPE_MDCT ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x, L_frameTCX, L_frame, gainlpc2, infoIGFStartLine ); -#else - TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x, L_frameTCX, L_frame, gainlpc2 ); -#endif } else if ( bfi ) { @@ -1263,11 +1223,7 @@ void decoder_tcx_noisefilling( { /* set f to 1 to not fade out */ /* set f to 0 to immediately switch to white noise */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->tcxonly && ( st->element_mode != IVAS_CPE_MDCT || isMCT ) ) -#else - if ( st->tcxonly ) -#endif { f = 1.0f; } @@ -1306,7 +1262,6 @@ void decoder_tcx_noisefilling( noiseTiltFactor = 1.0f; tcxGetNoiseFillingTilt( A, L_frame, ( total_brate >= ACELP_13k20 && !st->rf_flag ), &noiseTiltFactor ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->element_mode == IVAS_CPE_MDCT && !isMCT ) { TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, hTcxDec->CngLevelBackgroundTrace_bfi, infoIGFStartLine ); @@ -1315,9 +1270,6 @@ void decoder_tcx_noisefilling( { TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, NULL, hTcxDec->CngLevelBackgroundTrace_bfi, infoIGFStartLine ); } -#else - TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, infoIGFStartLine ); -#endif } } } @@ -1395,11 +1347,7 @@ void decoder_tcx_noiseshaping_igf( * Noise shaping in frequency domain (1/Wz) * *-----------------------------------------------------------*/ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->igf && ( !bfi || ( st->element_mode == IVAS_CPE_MDCT && st->prev_bfi ) ) ) -#else - if ( st->igf && !bfi ) -#endif { if ( ( L_frame == st->L_frame >> 1 ) && ( st->tcxonly ) ) { @@ -1964,12 +1912,8 @@ void decoder_tcx_IGF_stereo( const int16_t L_frame, /* i : frame length */ const int16_t left_rect, /* i : left part is rectangular */ const int16_t k, /* i : Subframe index */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t bfi, /* i : bad frame indicator */ const int16_t is_mct /* i : flag to signal MCT or SMDCT */ -#else - const int16_t bfi /* i : bad frame indicator */ -#endif ) { int16_t coreMsMask[N_MAX]; @@ -2022,11 +1966,7 @@ void decoder_tcx_IGF_stereo( igfGridIdx = ( sts[0]->last_core == ACELP_CORE || ( left_rect && bfi ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE IGFDecApplyStereo( sts[0]->hIGFDec, sts[1]->hIGFDec, x[0][k], x[1][k], igfGridIdx, coreMsMask, hStereoMdct->IGFStereoMode[k] == SMDCT_BW_MS, bfi, is_mct ); -#else - IGFDecApplyStereo( sts[0]->hIGFDec, sts[1]->hIGFDec, x[0][k], x[1][k], igfGridIdx, coreMsMask, hStereoMdct->IGFStereoMode[k] == SMDCT_BW_MS, bfi ); -#endif } return; diff --git a/lib_dec/er_dec_tcx.c b/lib_dec/er_dec_tcx.c index d72e88da5f..bf561c2abd 100644 --- a/lib_dec/er_dec_tcx.c +++ b/lib_dec/er_dec_tcx.c @@ -59,10 +59,8 @@ void con_tcx( const float coh, /* i : coherence of stereo signal */ int16_t *noise_seed, /* i/o: noise seed for stereo */ const int16_t only_left /* i : TD-PLC only in left channel */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const float *A_cng -#endif ) { int16_t i, n, L_frame, L_subfr, fLowPassFilter, T0; @@ -437,7 +435,6 @@ void con_tcx( /* PLC: [TCX: Fade-out] retrieve background level */ tmp = 1.0f; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( A_cng != NULL ) { gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_cng, L_frame / 4, st->preemph_fac, 1 ) / 4.f; @@ -446,14 +443,10 @@ void con_tcx( { gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 ); } -#else - gainSynthDeemph = getLevelSynDeemph( &( tmp ), A_local, L_frame / 4, st->preemph_fac, 1 ); -#endif if ( st->tcxonly ) { gainCNG = hTcxDec->CngLevelBackgroundTrace_bfi / gainSynthDeemph; -#ifdef FADE_TO_ZERO_FOR_TOO_LONG_FRAMELOSS if ( st->element_mode == IVAS_CPE_MDCT && A_cng != NULL ) { if ( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) @@ -465,7 +458,6 @@ void con_tcx( gainCNG *= 1.f - (float) ( st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; } } -#endif } else { @@ -561,7 +553,6 @@ void con_tcx( mvr2r( buf, mem_syn, M ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( A_cng != NULL ) { if ( st->plcBackgroundNoiseUpdated && alpha != 1.0f ) @@ -580,7 +571,6 @@ void con_tcx( lsp2a_stab( lsp_fade, A_local, M ); } } -#endif syn_filt( A_local, M, &exc[0], &syn[0], L_frame + ( L_frame / 2 ), mem_syn, 1 ); diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index e03b2ff2bc..299e6a31ce 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -676,11 +676,7 @@ ivas_error evs_dec( st->lp_noise = st->hFdCngDec->lp_noise; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( output, NULL, realBuffer, imagBuffer, st, concealWholeFrame, 0 ); -#else - ApplyFdCng( output, realBuffer, imagBuffer, st, concealWholeFrame, 0 ); -#endif /* Generate additional comfort noise to mask potential coding artefacts */ if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna ) diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index faaa37b52c..c1ddeeb79f 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -368,9 +368,7 @@ void deleteFdCngDec( void ApplyFdCng( float *timeDomainInput, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float *powerSpectrum, -#endif float **realBuffer, /* i/o: Real part of the buffer */ float **imagBuffer, /* i/o: Imaginary part of the buffer */ Decoder_State *st, @@ -384,7 +382,6 @@ void ApplyFdCng( int16_t j, k; float factor; float lsp_cng[M]; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE int16_t L_frame, last_L_frame; int32_t sr_core; @@ -394,7 +391,6 @@ void ApplyFdCng( L_frame = min( st->L_frame, L_FRAME16k ); last_L_frame = min( st->last_L_frame, L_FRAME16k ); sr_core = min( st->sr_core, INT_FS_16k ); -#endif if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) { @@ -419,27 +415,17 @@ void ApplyFdCng( /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */ if ( concealWholeFrame == 0 && -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ( timeDomainInput == NULL || ( *timeDomainInput( -FLT_MAX ) && *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && -#else - *timeDomainInput( -FLT_MAX ) && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) && -#endif ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD ) && !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || ( st->element_mode == IVAS_CPE_TD ) ) && ( !st->BER_detect ) ) { /* Perform noise estimation at the decoder */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#else - perform_noise_estimation_dec( timeDomainInput, hFdCngDec, st->element_mode, st->bwidth, st->L_frame, st->last_L_frame, st->last_core_brate, st->VAD ); -#endif if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) { @@ -471,7 +457,6 @@ void ApplyFdCng( } } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL ) { st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR ); @@ -480,7 +465,6 @@ void ApplyFdCng( { st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); } -#endif st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame ); } else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) @@ -488,20 +472,10 @@ void ApplyFdCng( if ( hFdCngCom->active_frame_counter > 0 ) { /* Perform noise estimation in active frames in the decoder for downward updates */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#else - perform_noise_estimation_dec( timeDomainInput, hFdCngDec, st->element_mode, st->bwidth, st->L_frame, st->last_L_frame, st->last_core_brate, st->VAD ); -#endif } } -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE - if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) && sum_f( cngNoiseLevel + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f ) - { - /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ - lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); -#else if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) ) { /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ @@ -528,15 +502,6 @@ void ApplyFdCng( } st->plcBackgroundNoiseUpdated = 1; } -#endif -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE - - a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng ); - mvr2r( lsp_cng, st->lspold_cng, M ); - - lsp2lsf( lsp_cng, st->lsf_cng, M, st->sr_core ); - st->plcBackgroundNoiseUpdated = 1; -#endif } break; @@ -549,11 +514,7 @@ void ApplyFdCng( if ( st != NULL && st->cng_type == LP_CNG ) { /* Perform noise estimation on inactive phase at the decoder */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); -#else - perform_noise_estimation_dec( timeDomainInput, hFdCngDec, st->element_mode, st->bwidth, st->L_frame, st->last_L_frame, st->last_core_brate, st->VAD ); -#endif if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT ) { @@ -564,11 +525,7 @@ void ApplyFdCng( /* This sets the new CNG levels until a SID update overwrites it */ mvr2r( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame ); -#else - st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame ); -#endif break; } @@ -650,10 +607,8 @@ void ApplyFdCng( default: break; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE wmops_sub_end(); -#endif return; } @@ -667,9 +622,7 @@ void ApplyFdCng( void perform_noise_estimation_dec( const float *timeDomainInput, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float *power_spectrum, -#endif HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ const int16_t element_mode, /* i : element mode */ const int16_t bwidth, /* i : audio bandwidth */ @@ -702,16 +655,11 @@ void perform_noise_estimation_dec( float temp, ftemp, delta; float wght; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( !( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL ) ) { /* Perform STFT analysis */ AnalysisSTFT( timeDomainInput, fftBuffer, hFdCngDec->hFdCngCom ); } -#else - /* Perform STFT analysis */ - AnalysisSTFT( timeDomainInput, fftBuffer, hFdCngDec->hFdCngCom ); -#endif if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT ) { @@ -944,7 +892,6 @@ void perform_noise_estimation_dec( } else { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL ) { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ @@ -977,32 +924,6 @@ void perform_noise_estimation_dec( /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand ); } -#else - /* Compute the squared magnitude in each FFT bin */ - if ( startBand == 0 ) - { - ( *ptr_per ) = fftBuffer[0] * fftBuffer[0]; /* DC component */ - ptr_per++; - ptr_r = fftBuffer + 2; - } - else - { - ptr_r = fftBuffer + 2 * startBand; - } - - ptr_i = ptr_r + 1; - - for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ ) - { - ( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i ); - ptr_r += 2; - ptr_i += 2; - } - /* Nyquist frequency is discarded */ - - /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ - v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand ); -#endif /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ bandcombinepow( periodog, stopFFTbin - startBand, part, npart, psize_inv, msPeriodog ); diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index d3638ea44a..f876391b2d 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -679,12 +679,8 @@ static void IGF_appl( float *pSpectralData, /* i/o: Q31 | MDCT spectrum */ const float *igf_spec, /* i : Q31 | prepared IGF spectrum */ float *virtualSpec, /* o : Q31 | virtual IGF spectrum, used for temp flattening */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE int16_t *flag_sparse, /* o : Q0 | temp flattening indicator */ const int16_t bfi_apply_damping /* i : flag to indicate if damping for lost frames should be applied */ -#else - int16_t *flag_sparse /* o : Q0 | temp flattening indicator */ -#endif ) { H_IGF_GRID hGrid; @@ -860,11 +856,7 @@ static void IGF_appl( for ( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( bfi_apply_damping && hPrivateData->frameLossCounter > 0 ) -#else - if ( hPrivateData->frameLossCounter > 0 ) -#endif { gain[sfb] = min( gain[sfb], 12.f ); @@ -1221,11 +1213,7 @@ void IGFDecApplyMono( /* apply IGF in three steps: */ IGF_prep( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat, element_mode ); IGF_calc( hPrivateData, igfGridIdx, spectrum, igf_spec ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse, 1 ); -#else - IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse ); -#endif } /* reset TCX noise indicator vector */ @@ -1251,12 +1239,8 @@ void IGFDecApplyStereo( const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ const int16_t *coreMsMask, const int16_t restrict_hopsize, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t bfi, /* i : frame loss == 1, frame good == 0 */ const int16_t bfi_apply_damping -#else - const int16_t bfi /* i : frame loss == 1, frame good == 0 */ -#endif ) { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR; @@ -1353,13 +1337,8 @@ void IGFDecApplyStereo( IGF_calc( hPrivateDataL, igfGridIdx, spectrumL, igf_specL ); IGF_calc( hPrivateDataR, igfGridIdx, spectrumR, igf_specR ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse, bfi_apply_damping ); IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse, bfi_apply_damping ); -#else - IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse ); - IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse ); -#endif } /* reset TCX noise indicator vector */ @@ -1612,7 +1591,6 @@ void init_igf_dec( return; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE int16_t get_igf_startline( Decoder_State *st, int16_t L_frame, @@ -1640,4 +1618,3 @@ int16_t get_igf_startline( return igf_startline; } -#endif diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 2e31017eaa..2598cf29b6 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -54,10 +54,8 @@ ivas_error init_decoder( Decoder_State *st, /* o : Decoder static variables structure */ const int16_t idchan /* i : channel ID */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const MC_MODE mc_mode /* i : MC mode */ -#endif ) { int16_t i; @@ -691,11 +689,7 @@ ivas_error init_decoder( st->enablePlcWaveadjust = 0; /* Init Core Decoder */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 ); -#else - open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, 1 ); -#endif /* PLC mode initialization */ st->m_decodeMode = DEC_NO_FRAM_LOSS; @@ -714,11 +708,7 @@ ivas_error init_decoder( * FD-CNG decoder *-----------------------------------------------------------------*/ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( ( st->element_mode == IVAS_CPE_MDCT || idchan == 0 ) && mc_mode != MC_MODE_MCT ) -#else - if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) -#endif { /* Create FD_CNG instance */ if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 89626b7523..a5254401a1 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -519,7 +519,7 @@ ivas_error ivas_binRenderer_open( { hBinRenderer->ivas_format = SBA_FORMAT; } - hBinRenderer->max_band = (int16_t) ( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + hBinRenderer->max_band = ( int16_t )( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); convBand = hBinRenderer->max_band; hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */ @@ -552,10 +552,17 @@ ivas_error ivas_binRenderer_open( } ivas_output_init( &out_setup, AUDIO_CONFIG_7_1_4 ); - if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + +#ifdef SBA_BITRATE_SWITCHING + if( st_ivas->hoa_dec_mtx == NULL ) +#endif { - return error; + if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } } + hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ); } diff --git a/lib_dec/ivas_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index b03c8c0053..269eff9f7d 100644 --- a/lib_dec/ivas_binaural_reverb.c +++ b/lib_dec/ivas_binaural_reverb.c @@ -538,6 +538,9 @@ void ivas_binaural_reverb_close( } count_free( ( *hReverb ) ); +#ifdef SBA_BITRATE_SWITCHING + ( *hReverb ) = NULL; +#endif return; } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index b3d5b60eca..fd5d5b3c1e 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -35,9 +35,7 @@ #ifdef DEBUGGING #include "debug.h" #endif -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE #include -#endif #include #include "cnst.h" #include "rom_com.h" @@ -183,23 +181,6 @@ ivas_error ivas_core_dec( st->flagGuidedAcelp = 0; } -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE - /* PLC: [TCX: Fade-out-recovery] - overlapping part needs to be attenuated for first good frame */ - if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) - { - if ( st->hPlcInfo != NULL ) - { - v_multc( st->hHQ_core->old_out, st->hPlcInfo->recovery_gain, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX ); - v_multc( st->hHQ_core->old_outLB, st->hPlcInfo->recovery_gain, st->hHQ_core->old_outLB, st->L_frame ); - - if ( !st->hTcxCfg->last_aldo && st->hTcxDec != NULL ) - { - v_multc( st->hTcxDec->syn_OverlFB, st->hPlcInfo->recovery_gain, st->hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB ); - v_multc( st->hTcxDec->syn_Overl, st->hPlcInfo->recovery_gain, st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window_length ); - } - } - } -#else /* PLC: [TCX: Fade-out-recovery] - overlapping part needs to be attenuated for first good frame */ if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) ) { @@ -220,7 +201,6 @@ ivas_error ivas_core_dec( } } } -#endif set_f( voice_factors[n], 0.f, NB_SUBFR16k ); set_f( hb_synth[n], 0.0f, L_FRAME48k ); @@ -422,7 +402,6 @@ ivas_error ivas_core_dec( updateBuffersForDmxMdctStereo( hCPE, output_frame, output, synth ); } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) { /* On first good frame after frameloss undo the whitening of the bg noise shape */ @@ -434,7 +413,6 @@ ivas_error ivas_core_dec( } } } -#endif } /*---------------------------------------------------------------------* diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index b008c68789..12b8fcb899 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -689,11 +689,7 @@ ivas_error create_cpe_dec( st->mct_chan_mode = MCT_CHAN_MODE_LFE; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( ( error = init_decoder( st, n, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) -#else - if ( ( error = init_decoder( st, n ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 17d474718f..3388961b0d 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -126,8 +126,12 @@ ivas_error ivas_dirac_dec_open( *-------------------------------------------------------------------------*/ ivas_error ivas_dirac_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ +#ifdef SBA_BITRATE_SWITCHING + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#else const DIRAC_CONFIG_FLAG flag_config /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +#endif ) { DIRAC_DEC_HANDLE hDirAC; @@ -146,6 +150,11 @@ ivas_error ivas_dirac_dec_config( int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_orig; +#ifdef SBA_BITRATE_SWITCHING + DIRAC_CONFIG_FLAG flag_config; + + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; +#endif error = IVAS_ERR_OK; @@ -198,7 +207,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_RECONFIGURE && st_ivas->ivas_format == SBA_FORMAT ) { int16_t tmp1, tmp2, tmp3; - ivas_sba_config( st_ivas->hDecoderConfig->last_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 ); } /*-----------------------------------------------------------------* @@ -270,6 +279,10 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef SBA_BITRATE_SWITCHING + st_ivas->nchan_transport = nchan_transport_orig; +#endif + return IVAS_ERR_OK; } @@ -653,7 +666,11 @@ ivas_error ivas_dirac_dec_config( } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) { +#ifdef SBA_BITRATE_SWITCHING + if ( nchan_transport != nchan_transport_old || hDirAC->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) +#else if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) +#endif { /* close and reopen the decorrelator */ ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index ca9f0a4587..04afb9ce2b 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -98,9 +98,21 @@ ivas_error ivas_dirac_dec_init_binaural_data( float binCenterFreq, tmpFloat; ivas_error error; - if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV - Renderer Reconfig. to be reviewed + hBinaural = st_ivas->hDiracDecBin; + + if ( hBinaural == NULL ) +#endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + } + +#ifdef SBA_BITRATE_SWITCHING + hBinaural->hTdDecorr = NULL; + hBinaural->hReverb = NULL; +#endif } nBins = st_ivas->hDirAC->num_freq_bands; @@ -189,18 +201,31 @@ ivas_error ivas_dirac_dec_init_binaural_data( { mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins ); - if ( hBinaural->useSubframeMode ) +#ifdef SBA_BITRATE_SWITCHING + /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */ + if ( hBinaural->hReverb != NULL && ( ( hBinaural->hReverb->numBins != nBins ) || + ( hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) || + ( !hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX ) ) ) { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) - { - return error; - } + ivas_binaural_reverb_close( &( hBinaural->hReverb ) ); } - else + + if ( hBinaural->hReverb == NULL ) +#endif { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + if ( hBinaural->useSubframeMode ) { - return error; + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK ) + { + return error; + } } } } @@ -219,7 +244,13 @@ ivas_error ivas_dirac_dec_init_binaural_data( { if ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_13k2 && st_ivas->ivas_format == SBA_FORMAT ) { - ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); +#ifdef SBA_BITRATE_SWITCHING + if ( hBinaural->hTdDecorr == NULL ) +#endif + { + ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); + } + if ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) { hBinaural->hTdDecorr->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; @@ -236,7 +267,11 @@ ivas_error ivas_dirac_dec_init_binaural_data( } else { +#ifdef SBA_BITRATE_SWITCHING + ivas_spar_td_decorr_dec_close( &( hBinaural->hTdDecorr ) ); +#else hBinaural->hTdDecorr = NULL; +#endif } st_ivas->hDiracDecBin = hBinaural; @@ -574,7 +609,6 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric uint8_t applyLowBitRateEQ; int16_t dirac_read_idx; - hDirAC = st_ivas->hDirAC; h = st_ivas->hDiracDecBin; separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; @@ -1159,14 +1193,14 @@ static void ivas_dirac_dec_binaural_process_output( if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { /* Process second / room effect part of binaural output when needed */ - ivas_binaural_reverb_processFrame( st_ivas->hDiracDecBin->hReverb, numInChannels, inRe, inIm, reverbRe, reverbIm, firstSlot ); + ivas_binaural_reverb_processFrame( h->hReverb, numInChannels, inRe, inIm, reverbRe, reverbIm, firstSlot ); } interpVal = 0.0f; for ( slot = firstSlot; slot < ( firstSlot + numSlots ); slot++ ) { interpVal += 1.0f / (float) numSlots; - if ( !st_ivas->hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) + if ( !h->useTdDecorr && max_band_decorr > 0 ) { ivas_dirac_dec_decorrelate_slot( st_ivas->hDirAC, slot, inRe, inIm, decSlotRe, decSlotIm ); } @@ -1181,7 +1215,7 @@ static void ivas_dirac_dec_binaural_process_output( /* Processing of the first / HRTF part of the binaural output. */ for ( chB = 0; chB < numInChannels; chB++ ) { - if ( st_ivas->hDiracDecBin->useTdDecorr ) + if ( h->useTdDecorr ) { decSlotRePointer = inRe[chB + 2][slot]; decSlotImPointer = inIm[chB + 2][slot]; diff --git a/lib_dec/ivas_efap.c b/lib_dec/ivas_efap.c index 602fd24161..482edfb643 100644 --- a/lib_dec/ivas_efap.c +++ b/lib_dec/ivas_efap.c @@ -83,7 +83,7 @@ static void get_poly_gains( const float azi, const float ele, const float aziPol static float get_tri_gain( const float A[2], const float B[2], const float C[2], const float P_minus_A[2] ); -#if defined( DEBUG_EFAP_POLY_TOFILE ) +#ifdef DEBUG_EFAP_POLY_TOFILE static void get_poly_select( EFAP_POLYSET_DATA *polyData ); #endif @@ -96,11 +96,13 @@ static void add_vertex( EFAP_VERTEX *vtxArray, const float azi, const float ele, static void efap_sort_s( int16_t *x, int16_t *idx, const int16_t len ); - static float vertex_distance( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE tri, const int16_t vtxIdx ); static float point_plane_distance( const float P1[3], const float P2[3], const float P3[3], const float X[3] ); +#ifdef EFAP_FIX_POLY +static float point_poly_distance( const EFAP_POLYSET poly, const float X[3] ); +#endif static void efap_crossp( const float *v1, const float *v2, float *v ); static int16_t find_int_in_tri( const EFAP_LS_TRIANGLE *tri, const int16_t n, const int16_t r, int16_t *pos ); @@ -125,6 +127,9 @@ static int16_t in_poly( const float P[2], const EFAP_POLYSET poly ); static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); +#ifdef EFAP_FIX_POLY +static void sph2cart( const float azi, const float ele, float *pos ); +#endif /*-----------------------------------------------------------------------* * Global function definitions @@ -462,14 +467,14 @@ static ivas_error poly_init( efap->polyData.numPoly = finalLength; -#if defined( DEBUG_EFAP_POLY_TOFILE ) +#ifdef DEBUG_EFAP_POLY_TOFILE get_poly_select( &efap->polyData ); #endif return error; } -#if defined( DEBUG_EFAP_POLY_TOFILE ) +#ifdef DEBUG_EFAP_POLY_TOFILE static void get_poly_select( EFAP_POLYSET_DATA *polyData /* o : Polygon data structure */ ) @@ -1497,9 +1502,13 @@ static void add_vertex( vtxArray[pos].ele = ( ( -180.0f > tmp ) ? -180.0f : tmp ); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ +#ifdef EFAP_FIX_POLY + sph2cart( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); +#else vtxArray[pos].pos[0] = cosf( vtxArray[pos].azi * PI_OVER_180 ) * cosf( vtxArray[pos].ele * PI_OVER_180 ); vtxArray[pos].pos[1] = sinf( vtxArray[pos].azi * PI_OVER_180 ) * cosf( vtxArray[pos].ele * PI_OVER_180 ); vtxArray[pos].pos[2] = sinf( vtxArray[pos].ele * PI_OVER_180 ); +#endif /* Computing the index defined by idx = idxAziTmp + 181 * idxEleTmp */ @@ -1591,11 +1600,32 @@ static float vertex_distance( return point_plane_distance( A, B, C, P ); } +#ifdef EFAP_FIX_POLY +/*-------------------------------------------------------------------------* + * point_plane_distance() + * + * Compute the signed distance between a point and polygon + *-------------------------------------------------------------------------*/ + +static float point_poly_distance( + const EFAP_POLYSET poly, /* i : The polygon which forms a plane */ + const float X[3] /* i : Cartesian coordinates of the point of interest */ +) +{ + float P1[3], P2[3], P3[3]; + + sph2cart( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); + sph2cart( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); + sph2cart( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); + + return point_plane_distance( P1, P2, P3, X ); +} +#endif /*-------------------------------------------------------------------------* * point_plane_distance() * - * Compute the signed distance between a point a given plane + * Compute the signed distance between a point and a given plane *-------------------------------------------------------------------------*/ static float point_plane_distance( @@ -2082,16 +2112,63 @@ static int16_t get_poly_num( ) { int16_t i; +#ifdef EFAP_FIX_POLY + int16_t num_poly, found_poly; + int16_t poly_tmp[EFAP_MAX_CHAN_NUM], poly_dist[EFAP_MAX_CHAN_NUM]; + + float dist_tmp; + float pos[3]; + + num_poly = 0; + sph2cart( P[0], P[1], &pos[0] ); + + /* Filter the polygon list with a fast 2d check */ +#endif for ( i = 0; i < polyData->numPoly; ++i ) { if ( in_poly( P, polyData->polysetArray[i] ) ) { +#ifdef EFAP_FIX_POLY + /* select only polygons which are visible from the point */ + dist_tmp = point_poly_distance( polyData->polysetArray[i], pos ); + if ( dist_tmp == 0 ) + { + return i; + } + else if ( dist_tmp > 0 ) + { + poly_tmp[num_poly] = i; + poly_dist[num_poly] = dist_tmp; + num_poly++; + } +#else return i; +#endif + } + } +#ifdef EFAP_FIX_POLY + if ( num_poly == 0 ) + { + return -1; + } + + /* select the polygon with the smallest distance */ + found_poly = poly_tmp[0]; + dist_tmp = poly_dist[0]; + for ( i = 1; i < num_poly; i++ ) + { + if ( poly_dist[i] < dist_tmp ) + { + found_poly = poly_tmp[i]; + dist_tmp = poly_dist[i]; } } + return found_poly; +#else return -1; +#endif } @@ -2216,7 +2293,7 @@ static int16_t in_tri( S[0] = ( matInv[0][0] * P_minus_A[0] ) + ( matInv[0][1] * P_minus_A[1] ); S[1] = ( matInv[1][0] * P_minus_A[0] ) + ( matInv[1][1] * P_minus_A[1] ); - /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ + /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ if ( S[0] < -thresh || S[1] < -thresh || S[0] + S[1] > 1 + thresh ) { return 0; @@ -2226,3 +2303,20 @@ static int16_t in_tri( return 1; } } + +/*-------------------------------------------------------------------------* + * sph2cart() + * + * Converts a vertex position to cartesian coordinates + *-------------------------------------------------------------------------*/ + +static void sph2cart( + const float azi, /* i : Azimuth in degrees */ + const float ele, /* i : Elevation in degrees */ + float *pos /* o : Cartesian coordinates vector (x, y, z) */ +) +{ + pos[0] = cosf( azi * PI_OVER_180 ) * cosf( ele * PI_OVER_180 ); + pos[1] = sinf( azi * PI_OVER_180 ) * cosf( ele * PI_OVER_180 ); + pos[2] = sinf( ele * PI_OVER_180 ); +} diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 2984ada3de..df05d6b0b1 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -121,11 +121,11 @@ ivas_error ivas_dec_setup( /* read Ambisonic (SBA) order */ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; /* 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 ); - - num_bits_read += SBA_ORDER_BITS; + if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) { if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) @@ -280,6 +280,7 @@ ivas_error ivas_dec_setup( st->next_bit_pos = num_bits_read; st->total_brate = ACELP_8k00; /* only temporary initialization - this is needed for get_next_indice() in the frame following NO_DATA frame */ } + return error; } @@ -594,7 +595,7 @@ ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t i, k, n; + int16_t i, n; int16_t sce_id, cpe_id; int16_t numCldfbAnalyses; int16_t numCldfbSyntheses; @@ -755,7 +756,6 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) { - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; @@ -797,10 +797,7 @@ ivas_error ivas_init_decoder( return error; } - for ( k = 0; k < DIRAC_MAX_NBANDS; k++ ) - { - st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; - } + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; } else diff --git a/lib_dec/ivas_mct_dec_mct.c b/lib_dec/ivas_mct_dec_mct.c index aaf27e6e1a..b46320cbcd 100644 --- a/lib_dec/ivas_mct_dec_mct.c +++ b/lib_dec/ivas_mct_dec_mct.c @@ -286,11 +286,7 @@ void mctStereoIGF_dec( /* stereo IGF decoding */ assert( ( sts[0]->core == sts[1]->core ) || ( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE decoder_tcx_IGF_stereo( sts, hMCT->hBlockData[b]->hStereoMdct, hMCT->hBlockData[b]->mask, p_x, L_frame[0], left_rect[0], k, bfi, 1 /* <- is_mct */ ); -#else - decoder_tcx_IGF_stereo( sts, hMCT->hBlockData[b]->hStereoMdct, hMCT->hBlockData[b]->mask, p_x, L_frame[0], left_rect[0], k, bfi ); -#endif } else { diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 24bd9e8396..14de87546d 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -102,9 +102,7 @@ static void dec_prm_tcx_sidebits( int16_t p_param[NB_DIV], /* o : pointer to parameters for next round of bs reading*/ int16_t nTnsBitsTCX10[NB_DIV], /* o : number of TNS bits per TCX10 subframe */ Decoder_State *st0, /* i/o: core decoder state handle - for bitstream */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t MCT_flag, -#endif const int16_t ch /* i : channel */ ) { @@ -134,11 +132,7 @@ static void dec_prm_tcx_sidebits( *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE getTCXMode( st, st0, MCT_flag ); -#else - getTCXMode( st, st0 ); -#endif st->flagGuidedAcelp = 0; @@ -381,11 +375,7 @@ void ivas_mdct_dec_side_bits_frame_channel( tmp = 3; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE dec_prm_tcx_sidebits( param[ch], st, ( ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) ? sts[0]->hTcxDec->tnsActive : NULL ), p_param[ch], nTnsBitsTCX10[ch], st0, MCT_flag, tmp ); -#else - dec_prm_tcx_sidebits( param[ch], st, ( ( st->element_mode == IVAS_CPE_MDCT && !MCT_flag ) ? sts[0]->hTcxDec->tnsActive : NULL ), p_param[ch], nTnsBitsTCX10[ch], st0, tmp ); -#endif assert( st->BER_detect != 1 ); } @@ -481,18 +471,14 @@ void ivas_mdct_core_invQ( const int16_t *prm_sqQ; int16_t L_frameTCX_global[CPE_CHANNELS]; float tmp_ms_sig[CPE_CHANNELS][N_MAX]; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float concealment_noise[CPE_CHANNELS][L_FRAME48k]; TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode_bfi; -#endif wmops_sub_start( "mdct_core_invQ" ); sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE noise_gen_mode_bfi = -1; -#endif set_f( xn_buf, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); set_s( total_nbbits, 0, CPE_CHANNELS ); @@ -520,7 +506,6 @@ void ivas_mdct_core_invQ( #endif } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( bfi ) { if ( sts[0]->core == sts[1]->core ) @@ -536,7 +521,6 @@ void ivas_mdct_core_invQ( noise_gen_mode_bfi = TCX20_IN_0_TCX10_IN_1; } } -#endif /* parameter decoding */ for ( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -738,15 +722,11 @@ void ivas_mdct_core_invQ( mvr2r( x[ch][k], x_0[ch][k], L_frameTCX[ch] ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( bfi && !isMCT ) { TonalMdctConceal_create_concealment_noise( concealment_noise[ch], hCPE, L_frameTCX[ch], L_frame[ch], ch, k, st->core, st->hTcxDec->cummulative_damping_tcx, noise_gen_mode_bfi ); } decoder_tcx_noisefilling( st, concealment_noise[ch], Aq[ch], L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], NULL, &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, isMCT, k ); -#else - decoder_tcx_noisefilling( st, Aq[ch], L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], NULL, &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, k ); -#endif decoder_tcx_noiseshaping_igf( st, L_spec[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x[ch][k], NULL, &tmp_concealment_method, bfi ); @@ -863,11 +843,7 @@ void ivas_mdct_core_reconstruct( TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, L_frameTCX[ch] ); } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE decoder_tcx_post( st, synth, synthFB, NULL, bfi, isMCT ); -#else - decoder_tcx_post( st, synth, synthFB, NULL, bfi ); -#endif } else /*ACELP core for ACELP-PLC */ { @@ -875,19 +851,11 @@ void ivas_mdct_core_reconstruct( /* PLC: [TCX: TD PLC] */ if ( isMCT ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL ); -#else - con_tcx( st, &synthFB[0], -1.f, NULL, 0 ); -#endif } else { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE con_tcx( st, &synthFB[0], hCPE->hStereoMdct->lastCoh, &sts[0]->seed_acelp, ( sts[1]->core != ACELP_CORE ) ? 1 : 0, &st->hFdCngDec->hFdCngCom->A_cng[0] ); -#else - con_tcx( st, &synthFB[0], hCPE->hStereoMdct->lastCoh, &sts[0]->seed_acelp, ( sts[1]->core != ACELP_CORE ) ? 1 : 0 ); -#endif } lerp( synthFB, synth, st->L_frame, st->hTcxDec->L_frameTCX ); @@ -1066,24 +1034,15 @@ void ivas_mdct_core_tns_ns( { sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( isMCT && st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) ) -#else - if ( isMCT && st->hTonalMDCTConc != NULL ) -#endif { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); -#else - TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0] ); -#endif } } else { if ( st->hTonalMDCTConc != NULL ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( !isMCT && st->hTcxDec->cummulative_damping_tcx != 1.f ) { float *scf_last, *scf_bg; @@ -1107,9 +1066,6 @@ void ivas_mdct_core_tns_ns( st->hTonalMDCTConc->scf_fadeout = 1.0f; mvr2r( st->hTonalMDCTConc->lastBlockData.scaleFactors, &sns_int_scf[0], st->hTonalMDCTConc->nScaleFactors ); } -#else - mvr2r( st->hTonalMDCTConc->lastBlockData.scaleFactors, &sns_int_scf[0], st->hTonalMDCTConc->nScaleFactors ); -#endif } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index c2b56f8b01..461f306038 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -37,6 +37,9 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" +#if 1 +#include "ivas_rom_com.h" +#endif #include "ivas_rom_dec.h" #ifdef DEBUGGING #include "debug.h" @@ -348,31 +351,47 @@ ivas_error ivas_sba_dec_reconfigure( ) { #ifdef CORECODER_BITRATE_SWITCHING - int16_t i; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old, nchan_hp20_old; + int16_t i, nSCE_old, nCPE_old, nchan_transport_old, nchan_hp20_old; #else int16_t i, n, sce_id, cpe_id; int16_t nchan_transport, nchan_transport_old; int16_t nSCE_old, nCPE_old; +#endif +#ifdef SBA_BITRATE_SWITCHING + int16_t output_frame; + SBA_MODE sba_mode_old; #endif AUDIO_CONFIG intern_config_old; int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; int16_t sba_dirac_stereo_flag_old; int32_t ivas_total_brate, last_ivas_total_brate; + DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + hDecoderConfig = st_ivas->hDecoderConfig; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = hDecoderConfig->last_ivas_total_brate; + +#ifdef SBA_BITRATE_SWITCHING + output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); +#endif /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA and rendering handles + * Set SBA high-level parameters + * Save old SBA high-level parameters *-----------------------------------------------------------------*/ +#ifdef SBA_BITRATE_SWITCHING + sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); + + st_ivas->sba_mode = sba_mode_old; +#endif ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifndef SBA_BITRATE_SWITCHING numCldfbAnalyses = 0; +#endif #ifdef CORECODER_BITRATE_SWITCHING nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -385,9 +404,146 @@ ivas_error ivas_sba_dec_reconfigure( 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, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + + + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SBA handles + *-----------------------------------------------------------------*/ + + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) + { + ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); + 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 ) + { + return error; + } - st_ivas->nchan_transport = nchan_transport; + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + } + else + { + int16_t sba_order_internal, num_channels_internal; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + + if ( st_ivas->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 !! + IVAS_FB_CFG *fb_cfg; + int16_t active_w_mixing; + + /* MD handle */ + ivas_spar_md_dec_close( &st_ivas->hSpar->hMdDec ); + + if ( ( error = ivas_spar_md_dec_open( &st_ivas->hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + st_ivas->hSpar->hMdDec->td_decorr_flag = 1; + st_ivas->hSpar->hMdDec->table_idx = -1; + + + /* TD decorr. */ + ivas_spar_td_decorr_dec_close( &st_ivas->hSpar->hTdDecorr ); + + if ( ( error = ivas_spar_td_decorr_dec_open( &st_ivas->hSpar->hTdDecorr, hDecoderConfig->output_Fs, num_channels_internal, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* FB mixer handle */ + ivas_FB_mixer_close( &st_ivas->hSpar->hFbMixer, hDecoderConfig->output_Fs ); + + /* set FB config. */ + active_w_mixing = -1; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, num_channels_internal, num_channels_internal, active_w_mixing, hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->pcm_offset = NS2SA( hDecoderConfig->output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->remix_order = remix_order_set[st_ivas->hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &st_ivas->hSpar->hFbMixer, hDecoderConfig->output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* mixer_mat intitialization */ + for ( i = 0; i < num_channels_internal; i++ ) + { + for ( int16_t j = 0; j < num_channels_internal; j++ ) + { + for ( int16_t b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + st_ivas->hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) + { + st_ivas->hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + } + } + } + } + st_ivas->hSpar->i_subframe = 0; + } + + if ( st_ivas->hSpar == NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + st_ivas->sba_dirac_stereo_flag = 0; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + + if ( st_ivas->hDirAC == NULL && st_ivas->sba_mode == SBA_MODE_DIRAC ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); + + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + + 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 ( st_ivas->nchan_transport == 1 ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } +#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 + + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ /* renderer might have changed */ intern_config_old = st_ivas->intern_config; @@ -399,9 +555,103 @@ ivas_error ivas_sba_dec_reconfigure( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } +#ifdef SBA_BITRATE_SWITCHING + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ + + if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + } + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } +#endif + + /*-----------------------------------------------------------------* + * hDirAC decoder handle configuration + *-----------------------------------------------------------------*/ + +#ifdef SBA_BITRATE_SWITCHING + if ( sba_mode_old != st_ivas->sba_mode ) // VE: TBD - possibly merge with the 'else if' branch below + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && + ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + 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 ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + + if ( st_ivas->hVBAPdata != NULL ) + { + vbap_free_data( &( st_ivas->hVBAPdata ) ); + } + } + + if ( st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + +#else + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); 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 ) { @@ -413,7 +663,7 @@ ivas_error ivas_sba_dec_reconfigure( int16_t sba_order_internal; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + ivas_spar_config( hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) { @@ -421,7 +671,7 @@ ivas_error ivas_sba_dec_reconfigure( } } - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) { @@ -451,6 +701,7 @@ ivas_error ivas_sba_dec_reconfigure( vbap_free_data( &( st_ivas->hVBAPdata ) ); } } +#endif /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles @@ -718,13 +969,24 @@ ivas_error ivas_sba_dec_reconfigure( /* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ - if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) + if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) { deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); st_ivas->cldfbAnaDec[1] = NULL; numCldfbAnalyses_old--; } +#ifdef SBA_BITRATE_SWITCHING + /* resample CLDFB analysis instances */ + for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) + { + if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != output_frame ) + { + resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs ); + } + } +#endif + /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { @@ -740,7 +1002,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -762,13 +1024,21 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } +#ifdef SBA_BITRATE_SWITCHING + /* CLDFB Interpolation weights */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses || nchan_transport_old != st_ivas->nchan_transport ) ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } +#endif + #ifndef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* * Set CNA/CNG flags @@ -813,6 +1083,7 @@ ivas_error ivas_sba_dec_reconfigure( } #endif +#ifndef SBA_BITRATE_SWITCHING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ @@ -842,6 +1113,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } +#endif return error; } diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 20db40d71b..5fbfa24e45 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -57,7 +57,7 @@ static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t outpu *-------------------------------------------------------------------*/ ivas_error ivas_sba_linear_renderer( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ const int16_t nchan_inp, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ @@ -92,7 +92,7 @@ ivas_error ivas_sba_linear_renderer( { for ( i = 0; i < output_frame; i++ ) { - output_f[0][i] += output_f[1][i]; + output[0][i] += output[1][i]; } } /* else: do nothing, MONO = W*/ @@ -106,9 +106,9 @@ ivas_error ivas_sba_linear_renderer( /*Build L/R cardioids*/ for ( i = 0; i < output_frame; i++ ) { - dmx_l = 0.5f * ( output_f[0][i] + output_f[1][i] ); /* cardioid_left = 0.5(W + Y) */ - output_f[1][i] = 0.5f * ( output_f[0][i] - output_f[1][i] ); /* cardioid_right = 0.5(W - Y) */ - output_f[0][i] = dmx_l; + dmx_l = 0.5f * ( output[0][i] + output[1][i] ); /* cardioid_left = 0.5(W + Y) */ + output[1][i] = 0.5f * ( output[0][i] - output[1][i] ); /* cardioid_right = 0.5(W - Y) */ + output[0][i] = dmx_l; } } break; @@ -118,14 +118,14 @@ ivas_error ivas_sba_linear_renderer( case AUDIO_CONFIG_5_1_4: case AUDIO_CONFIG_7_1_4: case AUDIO_CONFIG_LS_CUSTOM: - ivas_sba_mtx_mult( output_f, output_frame, nchan_hoa, output_setup, hoa_dec_mtx ); + ivas_sba_mtx_mult( output, output_frame, nchan_hoa, output_setup, hoa_dec_mtx ); break; case AUDIO_CONFIG_FOA: /* Ambisonics output, order: 1 */ case AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */ case AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */ for ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ ) { - set_zero( output_f[i], output_frame ); + set_zero( output[i], output_frame ); } break; default: diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 1aa3e083f0..3956325ff5 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -276,7 +276,7 @@ ivas_error ivas_sce_dec( dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, sce_id, DEC ) ); dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); - dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); + dbgwrite( output[0], sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); tmpF = 0; dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) ); dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) ); @@ -342,11 +342,7 @@ ivas_error create_sce_dec( st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( ( error = init_decoder( st, 0, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) -#else - if ( ( error = init_decoder( st, 0 ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index b9327c4208..a777bc9ebf 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -50,7 +50,7 @@ * Local function prototypes *--------------------------------------------------------------------*/ -static void ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); +static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); /*------------------------------------------------------------------------- @@ -258,7 +258,7 @@ ivas_error ivas_spar_dec( st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ - ivas_spar_dec_MD( st_ivas, st0 ); + error = ivas_spar_dec_MD( st_ivas, st0 ); *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig; st0->bit_stream = bit_stream_orig; @@ -617,18 +617,23 @@ int16_t ivas_is_res_channel( * IVAS SPAR MD decoder *-------------------------------------------------------------------*/ -static void ivas_spar_dec_MD( +static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ ) { int16_t nchan, table_idx, num_bands_out, bfi, sba_order; int32_t ivas_total_brate; - DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig; - SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + DECODER_CONFIG_HANDLE hDecoderConfig; + SPAR_DEC_HANDLE hSpar; + ivas_error error; wmops_sub_start( "ivas_spar_dec_MD" ); + hDecoderConfig = st_ivas->hDecoderConfig; + hSpar = st_ivas->hSpar; + error = IVAS_ERR_OK; + /*---------------------------------------------------------------------* * Initialization *---------------------------------------------------------------------*/ @@ -652,7 +657,10 @@ static void ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; - ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, nchan ); + if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, nchan ) ) != IVAS_ERR_OK ) + { + return error; + } } } @@ -670,6 +678,13 @@ static void ivas_spar_dec_MD( { ivas_pca_read_bits( st0, hSpar->hPCA ); } +#ifdef SBA_BITRATE_SWITCHING + else if ( ivas_total_brate == PCA_BRATE && sba_order == 1 ) + { + /* skip PCA bypass bit */ + get_next_indice( st0, 1 ); + } +#endif /*---------------------------------------------------------------------* * Read AGC bits @@ -706,7 +721,7 @@ static void ivas_spar_dec_MD( } wmops_sub_end(); - return; + return error; } @@ -780,7 +795,7 @@ void ivas_spar_get_parameters( const int16_t nchan_out, const int16_t nchan_inp, const int16_t num_spar_bands, - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) + float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) { int16_t spar_band, ch_out, ch_in; float weight, weight_20ms; @@ -802,19 +817,19 @@ void ivas_spar_get_parameters( { if ( hSpar->i_subframe > 3 ) { - par_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][ch_out][ch_in][spar_band] + - weight * hSpar->hMdDec->mixer_mat_prev[ts1][ch_out][ch_in][spar_band]; + mixer_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][ch_out][ch_in][spar_band] + + weight * hSpar->hMdDec->mixer_mat_prev[ts1][ch_out][ch_in][spar_band]; } else { - par_mat[ch_out][ch_in][spar_band] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; + mixer_mat[ch_out][ch_in][spar_band] = hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; } } else { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][ch_out][ch_in][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; + mixer_mat[ch_out][ch_in][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][ch_out][ch_in][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[ch_out][ch_in][spar_band]; } } } @@ -902,7 +917,7 @@ void ivas_spar_dec_upmixer( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; // VE: == st_ivas->nchan_transport num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; nchan_inp = hSpar->hFbMixer->fb_cfg->nchan_inp; @@ -990,7 +1005,6 @@ void ivas_spar_dec_upmixer( #endif } - /*---------------------------------------------------------------------* * TD decorrelation *---------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index ac950784f3..0e8f1b08e3 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -645,7 +645,7 @@ void ivas_spar_md_dec_process( ( b == 0 && frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; for ( j = 0; j < ( hMdDec->spar_md_cfg.num_decorr_per_band[bw * b] - hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] ); j++ ) { - for ( int16_t k = 0; k < hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] - 1; k++ ) + for ( k = 0; k < hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b] - 1; k++ ) { dbgwrite( &hMdDec->spar_md.band_coeffs[b].C_re[j][k], sizeof( float ), 1, 1, f_name ); } @@ -1389,23 +1389,27 @@ void ivas_spar_dec_gen_umx_mat( } } } - } -#ifdef SPAR_HOA_DBG + +#ifdef DEBUG_SBA_MD_DUMP + { + static FILE *f_mat = 0; + + if ( f_mat == 0 ) + f_mat = fopen( "mixer_mat_dec", "w" ); - /* for ( b = 0; b < 1; b++) - { - fprintf( stdout, "\n\nMixer Matrix band %d\n\n", b ); for ( i = 0; i < num_out_ch; i++ ) { - for ( j = 0; j < num_out_ch; j++ ) + for ( j = 0; j < num_out_ch; j++ ) + { + for ( b = 0; b < num_bands_out; b++ ) { - fprintf( stdout, "%.2f,\t", hMdDec->mixer_mat[i][j][0][b] ); + fprintf( f_mat, "%f\n", hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] ); } - fprintf( stdout, "\n" ); + } } - fprintf( stdout, "\n" ); - }*/ + } #endif + } ivas_spar_dec_compute_ramp_down_post_matrix( hMdDec, num_bands_out, bfi ); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index c856c36f31..1163e2a657 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -320,10 +320,8 @@ typedef struct stereo_mdct_dec_data_structure int16_t prev_ms_mask[NB_DIV][MAX_SFB]; float lastCoh; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE int16_t noise_seeds_channels[CPE_CHANNELS]; int16_t noise_seed_common; -#endif int16_t isSBAStereoMode; } STEREO_MDCT_DEC_DATA, *STEREO_MDCT_DEC_DATA_HANDLE; @@ -873,10 +871,10 @@ typedef struct ivas_spar_dec_lib_t int16_t AGC_flag; ivas_agc_dec_state_t *hAgcDec; PCA_DEC_STATE *hPCA; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ - int32_t i_subframe; + int32_t i_subframe; // VE2DB: change to int16_t #ifdef DEBUG_SBA_AUDIO_DUMP int16_t numOutChannels; diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index 1e923b5b7e..141858ccf8 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -50,9 +50,7 @@ *-------------------------------------------------------------------------*/ static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE static void run_min_stats( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ); -#endif /*-------------------------------------------------------------------* * convert_coeffs_to_higher_res() @@ -294,11 +292,7 @@ void stereo_mdct_core_dec( assert( ( sts[0]->core == sts[1]->core ) || ( hCPE->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) ); /* stereo IGF decoding */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE decoder_tcx_IGF_stereo( sts, hCPE->hStereoMdct, ms_mask, x, L_frame[0], left_rect[0], k, bfi, 0 /* <- is_mct */ ); -#else - decoder_tcx_IGF_stereo( sts, hCPE->hStereoMdct, ms_mask, x, L_frame[0], left_rect[0], k, bfi ); -#endif } else { @@ -328,17 +322,9 @@ void stereo_mdct_core_dec( sns_interpolate_scalefactors( &sns_int_scf[0], &Aq[ch][k * M], DEC ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->hTonalMDCTConc != NULL && ( ( k + 1 ) == nSubframes[ch] ) ) -#else - if ( st->hTonalMDCTConc != NULL ) -#endif { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0], get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); -#else - TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x[ch][k], L_frameTCX[ch], L_frame[ch], &sns_int_scf[0] ); -#endif } } @@ -368,9 +354,7 @@ void stereo_mdct_core_dec( ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x ); } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE run_min_stats( sts, x ); -#endif if ( hCPE->nchan_out == 1 && ( !bfi || ( bfi && sts[0]->core != ACELP_CORE && sts[1]->core != ACELP_CORE ) ) ) { @@ -589,7 +573,6 @@ static void apply_dmx_weights( return; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE /*-------------------------------------------------------------------* * run_min_stats() * @@ -669,4 +652,3 @@ static void run_min_stats( st->VAD = save_VAD[ch]; } } -#endif diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 9257f5cc3d..355eed3906 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -424,9 +424,7 @@ ivas_error stereo_memory_dec( if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) { cpy_tcx_ltp_data( hCPE->hCoreCoder[1]->hTcxLtpDec, hCPE->hStereoDft->hTcxLtpDec, output_Fs ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE deleteFdCngDec( &hCPE->hCoreCoder[1]->hFdCngDec ); -#endif } /* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */ @@ -489,12 +487,10 @@ ivas_error stereo_memory_dec( /* deallocated TCX/IGF structures for second channel */ deallocate_CoreCoder_TCX( hCPE->hCoreCoder[1] ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) { deleteFdCngDec( &hCPE->hCoreCoder[1]->hFdCngDec ); } -#endif /* allocate TD stereo data structure */ if ( hCPE->hStereoTD != NULL ) @@ -675,10 +671,6 @@ ivas_error stereo_memory_dec( /* deallocate core-decoder substructures */ deallocate_CoreCoder( st ); -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE - /* deallocate FD_CNG substructure */ - deleteFdCngDec( &st->hFdCngDec ); -#endif st->first_CNG = 0; } @@ -702,7 +694,6 @@ ivas_error stereo_memory_dec( } } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE /* allocate Fd-Cng structure for second channel */ if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK ) { @@ -711,7 +702,6 @@ ivas_error stereo_memory_dec( /* Init FD-CNG */ initFdCngDec( st ); -#endif if ( hCPE->last_element_mode == IVAS_CPE_DFT ) { @@ -1494,10 +1484,8 @@ void stereo_switching_dec( sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; sts[1]->pit_res_max = sts[0]->pit_res_max; sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; -#endif } } else if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index e46c32ddbb..9420be9eb9 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -150,11 +150,7 @@ void stereo_tcx_init_dec( } /* Reconfigure Core */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, is_mct, last_element_mode ); -#else - mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, is_mct ); -#endif } return; @@ -457,11 +453,7 @@ void stereo_tcx_core_dec( } /* PLC: [TCX: TD PLC] */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE con_tcx( st, &synthFB[0], -1.f, NULL, 0, NULL ); -#else - con_tcx( st, &synthFB[0], -1.f, NULL, 0 ); -#endif lerp( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); st->con_tcx = 1; set_f( &st->mem_pitch_gain[2], st->lp_gainp, st->nb_subfr ); @@ -589,11 +581,7 @@ void stereo_tcx_core_dec( TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, hTcxDec->L_frameTCX ); } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE decoder_tcx_post( st, synth, synthFB, Aq, bfi, 0 ); -#else - decoder_tcx_post( st, synth, synthFB, Aq, bfi ); -#endif if ( st->core == TCX_20_CORE ) { @@ -750,11 +738,7 @@ void stereo_tcx_core_dec( if ( st->element_mode != IVAS_CPE_TD ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( signal_out, NULL, NULL, NULL, st, st->bfi, 0 ); -#else - ApplyFdCng( signal_out, NULL, NULL, st, st->bfi, 0 ); -#endif } /* Generate additional comfort noise to mask potential coding artefacts */ @@ -779,11 +763,7 @@ void stereo_tcx_core_dec( if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) { -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE ApplyFdCng( signal_out, NULL, NULL, NULL, st, st->bfi, 0 ); -#else - ApplyFdCng( signal_out, NULL, NULL, st, st->bfi, 0 ); -#endif } } @@ -867,11 +847,7 @@ static void dec_prm_tcx( *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE getTCXMode( st, st, 0 /* <- MCT_flag */ ); -#else - getTCXMode( st, st ); -#endif /* last_core for error concealment */ if ( !st->use_partial_copy && st->element_mode != IVAS_CPE_MDCT ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 0c7a836cb4..d86cd42b72 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -204,7 +204,6 @@ typedef struct Float32 *secondLastPcmOut; float *secondLastPowerSpectrum; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float scaleFactorsBackground[FDNS_NPTS]; float scf_fadeout; PsychoacousticParameters *psychParams; @@ -214,7 +213,6 @@ typedef struct float last_block_nrg; float curr_noise_nrg; float faded_signal_nrg; -#endif float nFramesLost; diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 6c0203ed42..0078ca8bb4 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -93,7 +93,6 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->nSamplesCore = nSamplesCore; hTonalMDCTConc->nScaleFactors = nScaleFactors; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE set_zero( hTonalMDCTConc->scaleFactorsBackground, FDNS_NPTS ); hTonalMDCTConc->scf_fadeout = 1.0f; PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 ); @@ -103,7 +102,6 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->last_block_nrg = 0.0f; hTonalMDCTConc->curr_noise_nrg = 0.0f; hTonalMDCTConc->faded_signal_nrg = 0.0f; -#endif /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when new time samples are stored in lastPcmOut */ @@ -125,10 +123,8 @@ void TonalMDCTConceal_SaveFreqSignal( const uint16_t nNewSamples, const uint16_t nNewSamplesCore, const float *scaleFactors -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE , const int16_t infoIGFStartLine -#endif ) { float *temp; @@ -170,7 +166,6 @@ void TonalMDCTConceal_SaveFreqSignal( if ( ( nNewSamples > 0 ) && ( nNewSamples <= 2 * L_FRAME_MAX ) ) { /* Store new data */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE int16_t i; hTonalMDCTConc->last_block_nrg = 0.0f; @@ -183,9 +178,6 @@ void TonalMDCTConceal_SaveFreqSignal( { hTonalMDCTConc->lastBlockData.spectralData[i] = mdctSpectrum[i]; } -#else - mvr2r( mdctSpectrum, hTonalMDCTConc->lastBlockData.spectralData, nNewSamples ); -#endif mvr2r( scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors ); } @@ -502,28 +494,20 @@ void TonalMDCTConceal_InsertNoise( int16_t *pSeed, const float tiltCompFactor, const float crossfadeGain, -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const float concealment_noise[L_FRAME48k], const float cngLevelBackgroundTrace_bfi, -#endif const int16_t crossOverFreq ) { int16_t i, l; float x, y; Word16 rnd; float g, nrgNoiseInLastFrame, nrgWhiteNoise, tiltFactor, tilt; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE float last_block_nrg_correct; -#endif wmops_sub_start( "InsertNoise" ); g = 1.0f - crossfadeGain; -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE - if ( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) -#else if ( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) -#endif { rnd = 1977; } @@ -532,7 +516,6 @@ void TonalMDCTConceal_InsertNoise( rnd = *pSeed; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE /* based on what is done in tcx_noise_filling() */ /* always initialize these to avoid compiler warnings */ tiltFactor = (float) pow( max( 0.375f, tiltCompFactor ), 1.0f / hTonalMDCTConc->lastBlockData.nSamples ); @@ -541,14 +524,12 @@ void TonalMDCTConceal_InsertNoise( nrgWhiteNoise = 0.0f; hTonalMDCTConc->faded_signal_nrg = 0.0f; last_block_nrg_correct = 0.0f; -#endif if ( !hTonalMDCTConc->lastBlockData.blockIsValid ) { /* may just become active if the very first frame is lost */ set_f( mdctSpectrum, 0.0f, hTonalMDCTConc->nSamples ); } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE else if ( concealment_noise != NULL ) { if ( !tonalConcealmentActive ) @@ -737,15 +718,8 @@ void TonalMDCTConceal_InsertNoise( v_multc( mdctSpectrum, nrg_corr_factor, mdctSpectrum, crossOverFreq ); } } -#endif else { -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE - /* based on what is done in tcx_noise_filling() */ - tiltFactor = (float) pow( max( 0.375f, tiltCompFactor ), 1.0f / hTonalMDCTConc->lastBlockData.nSamples ); - tilt = 1.0f; - nrgNoiseInLastFrame = nrgWhiteNoise = 0.0f; -#endif if ( !tonalConcealmentActive ) { for ( i = 0; i < crossOverFreq; i++ ) @@ -992,7 +966,6 @@ void TonalMDCTConceal_SaveTimeSignal( return; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE void TonalMdctConceal_create_concealment_noise( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, @@ -1208,4 +1181,3 @@ void TonalMdctConceal_whiten_noise_shape( wmops_sub_end(); } -#endif diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 857099ed92..9cb48c2f22 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -369,6 +369,7 @@ ivas_error acelp_core_enc( nb_bits = 0; st->acelp_cfg.FEC_mode = 0; uc_two_stage_flag = 0; + if ( !nelp_mode && !ppp_mode ) { config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); @@ -551,7 +552,6 @@ ivas_error acelp_core_enc( return error; } - if ( st->hSC_VBR->bump_up ) /* PPP failed, bump up */ { /* restore memories of LSF quantizer and synthesis filter */ diff --git a/lib_enc/enc_prm.c b/lib_enc/enc_prm.c index 33c9d6fc7b..a68f95aff6 100644 --- a/lib_enc/enc_prm.c +++ b/lib_enc/enc_prm.c @@ -55,9 +55,7 @@ void writeTCXMode( Encoder_State *st, /* i/o: encoder state structure */ BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t is_mct, -#endif int16_t *nbits_start /* o : nbits start */ ) { @@ -88,12 +86,10 @@ void writeTCXMode( push_next_indice( hBstr, index, 2 ); -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE if ( st->element_mode == IVAS_CPE_MDCT && !is_mct ) { push_next_indice( hBstr, st->vad_flag, 1 ); } -#endif } else { @@ -792,11 +788,7 @@ void enc_prm( /* EVS header */ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE writeTCXMode( st, st->hBstr, 0, /* <- is_mct */ &nbits_start ); -#else - writeTCXMode( st, st->hBstr, &nbits_start ); -#endif /* write last_core for error concealment */ if ( !( core == ACELP_CORE && st->hTcxCfg->lfacNext <= 0 ) ) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 491a9ab358..25a1598183 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -686,7 +686,7 @@ ivas_error ivas_cpe_enc( } { - float tmpF = ivas_total_brate / 1000.0f; + float tmpF = hCPE->element_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, cpe_id, ENC ) ); } #endif diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 9484aa2737..30f3e22240 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -103,6 +103,7 @@ ivas_error ivas_dirac_enc_open( { return error; } + /* Allocate and initialize FB mixer handle */ if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) { @@ -125,12 +126,19 @@ ivas_error ivas_dirac_enc_open( for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) { - hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ); + if ( ( st_ivas->hDirAC->sba_synchro_buffer[i] = (float *) count_malloc( st_ivas->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[i], hDirAC->num_samples_synchro_delay ); } } else { +#ifdef SBA_BITRATE_SWITCHING + hDirAC->num_samples_synchro_delay = 0; +#endif + for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) { hDirAC->sba_synchro_buffer[i] = NULL; @@ -335,6 +343,7 @@ void ivas_dirac_enc( } ivas_dirac_param_est_enc( hDirAC, &( hQMetaData->q_direction[0] ), hQMetaData->useLowerRes, data_f, NULL, NULL, input_frame ); + /* encode parameters */ if ( sba_planar || hQMetaData->useLowerRes ) { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 9482a9e003..71972008d9 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -189,7 +189,9 @@ ivas_error ivas_enc( /* SBA/MASA configuration */ if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_BITRATE_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) +#endif { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { @@ -232,6 +234,7 @@ ivas_error ivas_enc( ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 ); } + } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { @@ -364,6 +367,7 @@ ivas_error ivas_enc( float tmpF = ivas_total_brate / 1000.0f; dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); } + dbgwrite( &st_ivas->nchan_transport, sizeof( int16_t ), 1, input_frame, "res/nchan_transport" ); #endif wmops_sub_end(); diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 66fac81674..3358e41e21 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -41,11 +41,11 @@ #include "ivas_rom_com.h" #include "wmops.h" - +#ifndef FIX_155_HP20_ISSUE #ifdef CORECODER_BITRATE_SWITCHING static ivas_error ivas_hp20_reconfig( Encoder_Struct *st_ivas, const int16_t nchan_hp20_old ); #endif - +#endif /*------------------------------------------------------------------------- * Local function definitions *------------------------------------------------------------------------*/ @@ -534,6 +534,7 @@ ivas_error ivas_ism_enc_config( st_ivas->hDirAC = NULL; } +#ifndef FIX_155_HP20_ISSUE #ifdef CORECODER_BITRATE_SWITCHING ivas_hp20_reconfig( st_ivas, nchan_transport_old ); #else @@ -574,6 +575,7 @@ ivas_error ivas_ism_enc_config( set_f( st_ivas->mem_hp20_in[sce_id], 0.0f, L_HP20_MEM ); } +#endif #endif } #else @@ -588,7 +590,7 @@ ivas_error ivas_ism_enc_config( return error; } - +#ifndef FIX_155_HP20_ISSUE #ifdef CORECODER_BITRATE_SWITCHING // VE: this is the same function as at the decoder -> harmonize them to a new file ivas_corecoder_reconfig.c /*-------------------------------------------------------------------* @@ -674,3 +676,4 @@ static ivas_error ivas_hp20_reconfig( return error; } #endif +#endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 18c3b93fb9..07825a612b 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -332,6 +332,13 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */ hMCT->num_lfe = TRUE; } +#ifdef SBA_BITRATE_SWITCHING // VE2FhG: TBV + else if ( ivas_format == SBA_FORMAT ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + hMCT->num_lfe = FALSE; + } +#else else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) // VE: this condition to be reviewed together with the following one { hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); @@ -342,6 +349,7 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); hMCT->num_lfe = FALSE; } +#endif else { assert( !"IVAS format currently not supported for MCT" ); @@ -468,6 +476,14 @@ ivas_error mct_enc_reconfigure( } } +#ifdef SBA_BITRATE_SWITCHING + hMCT->hbr_mct = 0; + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ivas_total_brate >= IVAS_256k ) + { + hMCT->hbr_mct = 1; + } +#endif + return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 0d2f5817d6..5234ae5c60 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -63,9 +63,7 @@ static void enc_prm_pre_mdct( int16_t param[], /* i : parameters */ const int16_t *no_param_tns, /* i : number of TNS parameters per subframe */ int16_t p_param[2], /* o : pointer to parameters for next round of bs writing */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE const int16_t is_mct, -#endif BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ) { @@ -80,11 +78,7 @@ static void enc_prm_pre_mdct( * Header *--------------------------------------------------------------------------------*/ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE writeTCXMode( st, hBstr, is_mct, &nbits_start ); -#else - writeTCXMode( st, hBstr, &nbits_start ); -#endif /* write last_core for core switching and error concealment */ push_next_indice( hBstr, st->last_core != ACELP_CORE, 1 ); @@ -1065,11 +1059,7 @@ void ivas_mdct_core_whitening_enc( continue; } -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE enc_prm_pre_mdct( st, param_core[ch], ( ( ( ch > 0 ) && ( sts[0]->hTcxEnc->fUseTns[0] + sts[0]->hTcxEnc->fUseTns[1] > 0 ) && !mct_on ) ? tnsSize[ch] : NULL ), p_param[ch], mct_on, hBstr ); -#else - enc_prm_pre_mdct( st, param_core[ch], ( ( ( ch > 0 ) && ( sts[0]->hTcxEnc->fUseTns[0] + sts[0]->hTcxEnc->fUseTns[1] > 0 ) && !mct_on ) ? tnsSize[ch] : NULL ), p_param[ch], hBstr ); -#endif if ( ch > 0 && sts[0]->hTcxEnc->fUseTns[0] + sts[0]->hTcxEnc->fUseTns[1] > 0 && !mct_on ) { diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index d4c7c70b21..6d8efaa6e7 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -105,18 +105,21 @@ ivas_error ivas_sba_enc_reconfigure( ) { int16_t nSCE_old, nCPE_old, nchan_transport_old; + #ifndef CORECODER_BITRATE_SWITCHING int16_t n, sce_id, cpe_id; Indice *ind_list_metadata; #endif int32_t ivas_total_brate; + ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; + hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + ivas_total_brate = hEncoderConfig->ivas_total_brate; - if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; @@ -125,10 +128,161 @@ ivas_error ivas_sba_enc_reconfigure( ind_list_metadata = NULL; #endif - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); + +#ifdef SBA_BITRATE_SWITCHING + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( st_ivas->hSpar == NULL ) + { + if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + 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 ); + } + else + { + ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp ); + st_ivas->hSpar = NULL; + } + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + /* FB mixer handle */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + // VE: TBV whether 'hFbMixer' can be reused + if ( st_ivas->hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( st_ivas->hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); + st_ivas->hDirAC->hFbMixer = NULL; + } + + { + // VE: dirty patch -> reconfiguration of SPAR MD, TD_decorr, FbMixer modules should be used instead !! + + IVAS_FB_CFG *fb_cfg; + int16_t nchan_internal, sba_order_internal; + int16_t table_idx, active_w_mixing; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + + /* Covar. State handle */ + ivas_spar_covar_enc_close( &st_ivas->hSpar->hCovEnc, st_ivas->hSpar->hFbMixer->fb_cfg->nchan_inp ); + + /* MD handle */ + ivas_spar_md_enc_close( &st_ivas->hSpar->hMdEnc ); + + if ( ( error = ivas_spar_md_enc_open( &( st_ivas->hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* FB mixer handle */ + ivas_FB_mixer_close( &st_ivas->hSpar->hFbMixer, hEncoderConfig->input_Fs ); + + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, st_ivas->nchan_transport, active_w_mixing, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->remix_order = remix_order_set[st_ivas->hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + + if ( ( error = ivas_FB_mixer_open( &( st_ivas->hSpar->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Covar. State handle */ + if ( ( error = ivas_spar_covar_enc_open( &( st_ivas->hSpar->hCovEnc ), st_ivas->hSpar->hFbMixer->pFb, hEncoderConfig->input_Fs, nchan_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + if ( st_ivas->hDirAC->hFbMixer == NULL ) + { + IVAS_FB_CFG *fb_cfg; + + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_DIRAC, DIRAC_MAX_ANA_CHANS, 0, 0, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Allocate and initialize FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &( st_ivas->hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* initalize delay for SPAR/DirAC delay synchronization */ + if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) + { + int16_t n; + + if ( st_ivas->hDirAC->num_samples_synchro_delay == 0 ) + { + st_ivas->hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + + for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( ( st_ivas->hDirAC->sba_synchro_buffer[n] = (float *) count_malloc( st_ivas->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( st_ivas->hDirAC->sba_synchro_buffer[n], st_ivas->hDirAC->num_samples_synchro_delay ); + } + for ( ; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + st_ivas->hDirAC->sba_synchro_buffer[n] = NULL; + } + } + } + else + { + for ( int16_t n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( st_ivas->hDirAC->sba_synchro_buffer[n] != NULL ) + { + count_free( st_ivas->hDirAC->sba_synchro_buffer[n] ); + st_ivas->hDirAC->sba_synchro_buffer[n] = NULL; + } + } + st_ivas->hDirAC->num_samples_synchro_delay = 0; + } +#endif - ivas_dirac_enc_reconfigure( st_ivas ); + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef SBA_BITRATE_SWITCHING + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } +#endif #ifdef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* @@ -137,8 +291,7 @@ ivas_error ivas_sba_enc_reconfigure( ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); #else - - if ( hEncoderConfig->nchan_transport == nchan_transport_old ) + if ( st_ivas->nchan_transport == nchan_transport_old ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -170,11 +323,8 @@ ivas_error ivas_sba_enc_reconfigure( else { Indice *ind_list; - int16_t nb_bits_tot; - int16_t next_ind; - int16_t last_ind; - BSTR_ENC_HANDLE hBstr; - BSTR_ENC_HANDLE hMetaData; + int16_t nb_bits_tot, next_ind, last_ind; + BSTR_ENC_HANDLE hBstr, hMetaData; ind_list = NULL; hBstr = NULL; @@ -236,12 +386,14 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nSCE_existing; nSCE_existing = min( nSCE_old, st_ivas->nSCE ); + for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; 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() */ } + for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) @@ -273,6 +425,7 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t nCPE_existing; nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -307,7 +460,7 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; } - if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) + if ( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; } @@ -411,8 +564,8 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } - initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, st_ivas->hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, st_ivas->hEncoderConfig->max_bwidth, 0, NULL, 1 ); - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } #endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 2592b578f6..856252d9f6 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -146,7 +146,7 @@ ivas_error ivas_sce_enc( { if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) { - st->bits_frame_nominal = (int16_t) ( hSCE->element_brate / FRAMES_PER_SEC ); + st->bits_frame_nominal = ( int16_t )( hSCE->element_brate / FRAMES_PER_SEC ); } else { @@ -155,11 +155,11 @@ ivas_error ivas_sce_enc( } else if ( st_ivas->hSpar != NULL ) { - st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); + st->bits_frame_nominal = ( int16_t )( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); } else { - st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); + st->bits_frame_nominal = ( int16_t )( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); } /* set "total_brate" */ @@ -238,7 +238,7 @@ ivas_error ivas_sce_enc( coder_type_modif( st, relE[0] ); /*----------------------------------------------------------------* - * Encoder + * Core Encoder *----------------------------------------------------------------*/ #ifdef CORECODER_BITRATE_SWITCHING @@ -361,17 +361,19 @@ ivas_error create_sce_enc( *-------------------------------------------------------------------------*/ void destroy_sce_enc( - SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ + SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ ) { Encoder_State *st; - st = hSCE->hCoreCoder[0]; - - if ( st != NULL ) { - destroy_core_enc( st ); - st = NULL; + st = hSCE->hCoreCoder[0]; + + if ( st != NULL ) + { + destroy_core_enc( st ); + st = NULL; + } } if ( hSCE->hMetaData != NULL ) diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index 87019b8d91..6790f0cf6d 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -43,175 +43,6 @@ #endif #include "wmops.h" -#ifndef MDCT_STEREO_PLC_FADE_2_BG_NOISE -#define SNS_NPTS 16 /* Number of downsampled SNS parameters */ - -/*------------------------------------------------------------------- - * sns_compute_scf() - * - * - *-------------------------------------------------------------------*/ - -void sns_compute_scf( - float spectrum[], - const PsychoacousticParameters *pPsychParams, - const int16_t L_frame, - float *scf ) -{ - int16_t i, n, k; - float x[FDNS_NPTS], xs[FDNS_NPTS], sum, mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; - float tilt; - const uint8_t nBands = pPsychParams->nBands; - const uint8_t *bandLengths = pPsychParams->bandLengths; - int8_t bw = 0; - - - const float w_0 = 1.0f / 12.0f; - const float w_1 = 2.0f / 12.0f; - const float w_2 = 0.25f; /* 3.0f / 12.0f */ - const float w_3 = w_2; - const float w_4 = w_1; - const float w_5 = w_0; - - const float scale_log = INV_LOG_2 * 0.5f; - - assert( nBands == 64 ); - - set_f( x, 0.0f, FDNS_NPTS ); - - if ( bandLengths == NULL ) - { - bw = (int8_t) ( L_frame / nBands ); - /* Energy per band */ - k = 0; - for ( i = 0; i < nBands; ++i ) - { - x[i] = 0.0f; - for ( n = 0; n < bw; ++n, ++k ) - { - x[i] += spectrum[k]; - } - x[i] /= bw; - } - } - else - { - /* Energy per band */ - k = 0; - for ( i = 0; i < nBands; ++i ) - { - x[i] = 0.0f; - for ( n = 0; n < bandLengths[i]; ++n, ++k ) - { - x[i] += spectrum[k]; - } - x[i] /= bandLengths[i]; - } - } - - /* Smoothing */ - xs[0] = 0.75f * x[0] + 0.25f * x[1]; - - for ( i = 1; i < FDNS_NPTS - 1; i++ ) - { - xs[i] = 0.5f * x[i] + 0.25f * x[i - 1] + 0.25f * x[i + 1]; - } - - xs[FDNS_NPTS - 1] = 0.75f * x[FDNS_NPTS - 1] + 0.25f * x[FDNS_NPTS - 2]; - - /* Pre-emphasis */ - if ( L_frame == L_FRAME16k ) - { - tilt = 18.f; - } - else if ( L_frame == L_SPEC16k_EXT ) - { - tilt = 20.f; - } - else if ( L_frame == L_FRAME25_6k ) - { - tilt = 22.f; - } - else if ( L_frame == L_FRAME32k ) - { - tilt = 26.f; - } - else if ( L_frame == L_SPEC32k_EXT ) - { - tilt = 30.f; - } - else - { - tilt = 0.f; - assert( 0 && "illegal frame length in sns_compute_scf" ); - } - - for ( i = 0; i < FDNS_NPTS; i++ ) - { - xs[i] = xs[i] * powf( 10.0f, (float) i * (float) tilt / ( (float) FDNS_NPTS - 1.0f ) / 10.0f ); - } - - /* Noise floor at -40dB */ - sum = sum_f( xs, FDNS_NPTS ); - mean = sum / FDNS_NPTS; - - nf = mean * powf( 10.0f, -4.0f ); - nf = max( nf, powf( 2.0f, -32.0f ) ); - - - for ( i = 0; i < FDNS_NPTS; i++ ) - { - if ( xs[i] < nf ) - { - xs[i] = nf; - } - } - - /* Log-domain */ - for ( i = 0; i < FDNS_NPTS; i++ ) - { - xl[i] = logf( xs[i] ) * scale_log; - } - - /* Downsampling */ - xl4[0] = w_0 * xl[0] + - w_1 * xl[0] + - w_2 * xl[1] + - w_3 * xl[2] + - w_4 * xl[3] + - w_5 * xl[4]; - - - for ( n = 1; n < SNS_NPTS - 1; n++ ) - { - int16_t n4 = 4 * n; - xl4[n] = w_0 * xl[n4 - 1] + - w_1 * xl[n4] + - w_2 * xl[n4 + 1] + - w_3 * xl[n4 + 2] + - w_4 * xl[n4 + 3] + - w_5 * xl[n4 + 4]; - } - - xl4[SNS_NPTS - 1] = w_0 * xl[FDNS_NPTS - 5] + - w_1 * xl[FDNS_NPTS - 4] + - w_2 * xl[FDNS_NPTS - 3] + - w_3 * xl[FDNS_NPTS - 2] + - w_4 * xl[FDNS_NPTS - 1] + - w_5 * xl[FDNS_NPTS - 1]; - - /* Remove mean and scaling */ - sum = sum_f( xl4, SNS_NPTS ); - mean = sum / SNS_NPTS; - - for ( i = 0; i < SNS_NPTS; i++ ) - { - scf[i] = 0.85f * ( xl4[i] - mean ); - } - - return; -} -#endif /*------------------------------------------------------------------- diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 4c7721f095..880aef08c1 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -98,7 +98,10 @@ ivas_error ivas_spar_enc_open( /* set FB config. */ active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; - ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ); + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ @@ -285,6 +288,40 @@ ivas_error ivas_spar_enc( error = IVAS_ERR_OK; hEncoderConfig = st_ivas->hEncoderConfig; +#ifdef SBA_BITRATE_SWITCHING + // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->input ? + + /* check last sba_mode */ + if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_DIRAC ) + { + Encoder_State *sts[MCT_MAX_BLOCKS]; + + /* initializations */ + for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]; + } + + for ( int16_t cpe_id = 0, i = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; + i++; + } + } + + /* update FB prior input */ + // VE: last 1ms of 'ppFilterbank_prior_input' is not correct + for ( int16_t i = 0; i < st_ivas->nchan_transport; i++ ) + { + mvr2r( sts[i]->input_buff + NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ), st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input[i] + st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length - input_frame, input_frame ); + } + + //VE: TBD - update 'st->input_buff' for SparVAD + } +#endif + /* front VAD */ if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], st_ivas->hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { @@ -676,7 +713,20 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); + +#ifdef SBA_BITRATE_SWITCHING + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) + { + if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else +#endif + { + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); + } } #ifdef SBA_SPAR_HARM @@ -789,6 +839,7 @@ static ivas_error ivas_spar_enc_process( #ifdef DEBUG_SBA_MD_DUMP { + int16_t k; static FILE *f_mat = 0; if ( f_mat == 0 ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 6b8e43ba87..a8d875a487 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -84,9 +84,12 @@ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); +#ifndef SBA_BITRATE_SWITCHING static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); +#endif static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t nchan ); + static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t nchan ); @@ -304,7 +307,11 @@ void ivas_spar_md_enc_close( * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ +#ifndef SBA_BITRATE_SWITCHING static ivas_error ivas_spar_md_enc_init( +#else +ivas_error ivas_spar_md_enc_init( +#endif ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ const int16_t sba_order /* i : Ambisonic (SBA) order */ @@ -1033,6 +1040,8 @@ ivas_error ivas_spar_md_enc_process( byte_size = sizeof( float ); for ( b = 0; b < nB; b++ ) { + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + sprintf( f_name, "spar_band_pred_coeffs.bin" ); ( b == 0 && frame == 0 ) ? dbgwrite( &nB, sizeof( nB ), 1, 1, f_name ) : false; num_elements = nchan - 1; @@ -1701,7 +1710,7 @@ static void ivas_write_parameter_bitstream_dtx( pr -= idx; pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); - value = (uint16_t) ( pr * pd_q_lvls + pd ); + value = ( uint16_t )( pr * pd_q_lvls + pd ); push_next_indice( hMetaData, value, pr_pd_bits ); } @@ -1724,7 +1733,7 @@ static void ivas_write_parameter_bitstream_dtx( pr_idx2 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1]; pr_idx2 -= idx; - value = (uint16_t) ( pr_idx2 * pr_q_lvls1 + pr_idx1 ); + value = ( uint16_t )( pr_idx2 * pr_q_lvls1 + pr_idx1 ); pr_pr_bits = ivas_get_bits_to_encode( pr_q_lvls1 * pr_q_lvls2 ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index d13da5794a..2303118e85 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -690,7 +690,7 @@ typedef struct ivas_spar_enc_lib_t ivas_enc_cov_handler_state_t *hCovEnc; ivas_trans_det_state_t *hTranDet; ivas_agc_enc_state_t *hAgcEnc; - int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; // VE2DB: could only hDirAC->dirac_to_spar_md_bands be used all the time, or it is defined as a pointer here? int16_t enc_param_start_band; PCA_ENC_STATE *hPCA; int32_t core_nominal_brate; /* Nominal bitrate for core coding */ @@ -865,7 +865,7 @@ typedef struct cpe_enc_data_structure int16_t cpe_id; /* CPE # identifier */ int32_t element_brate; /* CPE element total bitrate in bps */ - int32_t last_element_brate; /* last CPE element total bitrate in bps */ + int32_t last_element_brate; /* last CPE element bitrate in bps */ int16_t element_mode; /* element mode, in CPE it can be IVAS_CPE_DFT, IVAS_CPE_TD or IVAS_CPE_MDCT */ int16_t last_element_mode; /* last element mode */ diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 6d1e9a32b0..f9a25f3a88 100755 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -254,6 +254,7 @@ void stereo_mdct_core_enc( /*--------------------------------------------------------------* * Stereo Processing *---------------------------------------------------------------*/ + if ( !hStereoMdct->isSBAStereoMode ) { stereo_coder_tcx( hStereoMdct, sts, ms_mask, mdst_spectrum, inv_spectrum, inv_mdst_spectrum, 0 ); diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 4bd88cb00d..2c1e4a9051 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -268,11 +268,7 @@ void stereo_tcx_core_enc( *--------------------------------------------------------------------------------*/ /* TCX20/TCX10 and coder type */ -#ifdef MDCT_STEREO_PLC_FADE_2_BG_NOISE writeTCXMode( st, hBstr, 0, /* <- is_mct */ &nbits_start ); -#else - writeTCXMode( st, hBstr, &nbits_start ); -#endif /* write last_core for error concealment */ push_next_indice( hBstr, ( st->last_core != ACELP_CORE || st->core == TCX_10_CORE ), 1 ); diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm index 721e93a457..470b649ce0 100644 --- a/scripts/config/self_test.prm +++ b/scripts/config/self_test.prm @@ -280,10 +280,6 @@ ../IVAS_cod -dtx -ism 1 testv/stvISM1.csv 13200 48 testv/stv48n.pcm bit ../IVAS_dec -fec 5 BINAURAL 48 bit testv/stv48n.pcm_13200_48-48_DTX_FEC5_BINAURAL.tst -// 1 ISm with metadata at 32 kbps, 32 kHz in, 32 kHz out, DTX on, MONO out -../IVAS_cod -dtx -ism 1 testv/stvISM1.csv 32000 32 testv/stv32n.pcm bit -../IVAS_dec MONO 32 bit testv/stv32n.pcm_32000_32-32_DTX_MONO.tst - // 2 ISm with metadata at 16.4 kbps, 48 kHz in, 48 kHz out, STEREO out ../IVAS_cod -ism 2 testv/stvISM1.csv testv/stvISM2.csv 16400 48 testv/stv2ISM48s.pcm bit ../IVAS_dec STEREO 48 bit testv/stv2ISM48s.pcm_16400_48-48_STEREO.tst @@ -296,6 +292,10 @@ ../IVAS_cod -ism 3 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv 24400 48 testv/stv3ISM48s.pcm bit ../IVAS_dec -fec 5 MONO 48 bit testv/stv3ISM48s.pcm_24400_48-48_MONO_FEC5.tst +// 1 ISm with metadata at 32 kbps, 32 kHz in, 32 kHz out, DTX on, MONO out +../IVAS_cod -dtx -ism 1 testv/stvISM1.csv 32000 32 testv/stv32n.pcm bit +../IVAS_dec MONO 32 bit testv/stv32n.pcm_32000_32-32_DTX_MONO.tst + // 4 ISm with metadata at 32 kbps, 48 kHz in, 48 kHz out, FOA out ../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 32000 48 testv/stv4ISM48s.pcm bit ../IVAS_dec FOA 48 bit testv/stv4ISM48s.pcm_32000_48-48_FOA.tst @@ -400,6 +400,14 @@ ../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.pcm bit ../IVAS_dec -t testv/headrot_case03_3000_q.csv BINAURAL 48 bit testv/stv4ISM48s.pcm_256000_48-48_TDHR.tst +// 1 ISm with metadata bitrate switching from 13.2 kbps to 128 kbps, 32 kHz in, 32 kHz out, mono out, DTX on +../IVAS_cod -dtx -ism 1 testv/stvISM1.csv ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 32 testv/stv32c.pcm bit +../IVAS_dec MONO 32 bit testv/stv32c.pcm_brate_sw_32-32_mono_dtx.tst + +// 4 ISm with metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.pcm bit +../IVAS_dec BINAURAL 48 bit testv/stv4ISM48s.pcm_brate_sw_48-48_BINAURAL.tst + // SBA at 13.2 kbps, 32kHz in, 32kHz out, HOA3 out ../IVAS_cod -sba 3 13200 32 testv/stv3OA32c.pcm bit diff --git a/scripts/pyaudio3dtools/EFAP.py b/scripts/pyaudio3dtools/EFAP.py index e5b4219cc0..5014cd168c 100644 --- a/scripts/pyaudio3dtools/EFAP.py +++ b/scripts/pyaudio3dtools/EFAP.py @@ -744,18 +744,40 @@ class EFAP: raise ValueError(f"Angles cannot be NaNs : ({azimuth}, {elevation})") azimuth, elevation = wrap_angles(azimuth, elevation) + point_pos = [ + np.cos(np.deg2rad(azimuth)) * np.cos(np.deg2rad(elevation)), + np.sin(np.deg2rad(azimuth)) * np.cos(np.deg2rad(elevation)), + np.sin(np.deg2rad(elevation)), + ] - # find the polygon corresponding to the given point - found_poly = None - mod = None + # filter the polygon list with a quick 2d check + found_polys = [] for poly in self.polys: in_poly, mod = self._in_polygon(azimuth, elevation, poly) if in_poly: - found_poly = poly - break - else: + found_polys.append((poly, mod)) + + if not found_polys: raise AssertionError("Unexpected error during panning") + # find a visible polygon with the smallest distance + dist = [] + + for poly, mod in found_polys: + surface = self.verts[poly] + d = self._point_plane_dist( + surface[0].pos, + surface[1].pos, + surface[2].pos, + point_pos, + ) + if d >= 0: + dist.append(d) + else: + dist.append(np.inf) + + found_poly, mod = found_polys[np.argmin(dist)] + # compute gains for the polygon vertices poly_gain = self._pan_EFAP_poly(azimuth, elevation, found_poly, mod) -- GitLab From d5f8d8e40aa7ec1f40c283249a5a39ecc555d32b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 24 Oct 2022 19:28:09 +0200 Subject: [PATCH 24/26] - add comment --- lib_enc/ivas_sba_enc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 6d8efaa6e7..675065d95b 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -141,6 +141,8 @@ ivas_error ivas_sba_enc_reconfigure( { return error; } + + // VE: TBV - initialize 'hSpar->hFrontVad' with 'hCoreCoder[0]' instead of initializing it? } ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), -- GitLab From f2d29321b952e0120898ebbae4eaf08170a8023b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 24 Oct 2022 20:22:27 +0200 Subject: [PATCH 25/26] fix merge issue --- lib_enc/ivas_sba_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 675065d95b..2ee3201856 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -142,7 +142,7 @@ ivas_error ivas_sba_enc_reconfigure( return error; } - // VE: TBV - initialize 'hSpar->hFrontVad' with 'hCoreCoder[0]' instead of initializing it? + // 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 ), diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 0d343cee15..134b456aee 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -724,13 +724,6 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, -#ifdef SBA_HOA_HBR_IMPROV - ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND -#else - SPAR_DIRAC_SPLIT_START_BAND -#endif - ); #ifdef SBA_BITRATE_SWITCHING if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) @@ -743,7 +736,13 @@ static ivas_error ivas_spar_enc_process( else #endif { - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, SPAR_DIRAC_SPLIT_START_BAND ); + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, +#ifdef SBA_HOA_HBR_IMPROV + ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND +#else + SPAR_DIRAC_SPLIT_START_BAND +#endif + ); } } -- GitLab From a6116644625014bc38b907cd4d9afbd5abd32cc6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Oct 2022 17:17:54 +0200 Subject: [PATCH 26/26] - fix PCA for switching in FOA - accommodate updates for 'spar_hoa_md_flag' - code simplifications --- lib_com/ivas_prot.h | 3 ++ lib_debug/mem_count.c | 2 +- lib_dec/ivas_sba_dec.c | 67 +++++++++++++++++++++++++------------ lib_dec/ivas_spar_decoder.c | 4 +++ lib_dec/ivas_spar_md_dec.c | 17 ++++++++-- lib_enc/ivas_sba_enc.c | 51 +++++++++++++++------------- lib_enc/ivas_spar_md_enc.c | 8 +++++ 7 files changed, 105 insertions(+), 47 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ad61b60f84..401366a9f0 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4017,6 +4017,9 @@ void ivas_spar_get_parameters( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + const int16_t sba_order, /* i : SBA order */ +#endif const int16_t nchan /* i : number of internal channels */ ); diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index 4d886df70f..5d1da67eb7 100644 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -94,7 +94,7 @@ typedef INT64 int64_t; /* This is the maximum number of allocations for which to keep information. It can be increased if required. */ #ifdef SBA_BITRATE_SWITCHING -#define MAX_INFO_RECORDS 4000 +#define MAX_INFO_RECORDS 6000 #else #define MAX_INFO_RECORDS 3000 #endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index aa55a65a1c..6e493b7b51 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -37,7 +37,7 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" -#if 1 +#ifdef SBA_BITRATE_SWITCHING #include "ivas_rom_com.h" #endif #include "ivas_rom_dec.h" @@ -427,11 +427,13 @@ ivas_error ivas_sba_dec_reconfigure( else { int16_t sba_order_internal, nchan_internal; + DIRAC_DEC_HANDLE hDirAC = st_ivas->hDirAC; + 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 ); - if ( st_ivas->hSpar != NULL && nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, 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 !! @@ -439,9 +441,9 @@ ivas_error ivas_sba_dec_reconfigure( int16_t active_w_mixing; /* MD handle */ - ivas_spar_md_dec_close( &st_ivas->hSpar->hMdDec ); + ivas_spar_md_dec_close( &hSpar->hMdDec ); - if ( ( error = ivas_spar_md_dec_open( &st_ivas->hSpar->hMdDec, st_ivas->hDecoderConfig, nchan_internal + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, nchan_internal #ifdef SBA_HOA_HBR_IMPROV , sba_order_internal @@ -450,20 +452,19 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } - st_ivas->hSpar->hMdDec->td_decorr_flag = 1; - st_ivas->hSpar->hMdDec->table_idx = -1; - + hSpar->hMdDec->td_decorr_flag = 1; + hSpar->hMdDec->table_idx = -1; /* TD decorr. */ - ivas_spar_td_decorr_dec_close( &st_ivas->hSpar->hTdDecorr ); + ivas_spar_td_decorr_dec_close( &hSpar->hTdDecorr ); - if ( ( error = ivas_spar_td_decorr_dec_open( &st_ivas->hSpar->hTdDecorr, hDecoderConfig->output_Fs, nchan_internal, 1 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, hDecoderConfig->output_Fs, nchan_internal, 1 ) ) != IVAS_ERR_OK ) { return error; } /* FB mixer handle */ - ivas_FB_mixer_close( &st_ivas->hSpar->hFbMixer, hDecoderConfig->output_Fs ); + ivas_FB_mixer_close( &hSpar->hFbMixer, hDecoderConfig->output_Fs ); /* set FB config. */ active_w_mixing = -1; @@ -472,10 +473,10 @@ ivas_error ivas_sba_dec_reconfigure( return error; } fb_cfg->pcm_offset = NS2SA( hDecoderConfig->output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); - fb_cfg->remix_order = remix_order_set[st_ivas->hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; /* FB mixer handle */ - if ( ( error = ivas_FB_mixer_open( &st_ivas->hSpar->hFbMixer, hDecoderConfig->output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, hDecoderConfig->output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) { return error; } @@ -487,44 +488,68 @@ ivas_error ivas_sba_dec_reconfigure( { for ( int16_t b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - st_ivas->hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) { - st_ivas->hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; } } } } - st_ivas->hSpar->i_subframe = 0; + hSpar->i_subframe = 0; + } + + + /* PCA handle */ + if ( hSpar != NULL ) + { + if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 ) + { + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } + + ivas_pca_dec_init( hSpar->hPCA ); + } + else if ( hSpar->hPCA != NULL ) + { + count_free( st_ivas->hSpar->hPCA ); + hSpar->hPCA = NULL; + } } - if ( st_ivas->hSpar == NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + if ( hSpar == NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) { if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } + + hSpar = st_ivas->hSpar; } st_ivas->sba_dirac_stereo_flag = 0; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + 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 ); - if ( st_ivas->hDirAC == NULL && st_ivas->sba_mode == SBA_MODE_DIRAC ) + if ( hDirAC == NULL && st_ivas->sba_mode == SBA_MODE_DIRAC ) { if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } + + hDirAC = st_ivas->hDirAC; } - if ( st_ivas->hDirAC != NULL ) + if ( hDirAC != NULL ) { ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); - mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); - st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + 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; } 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 ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index eac631dcef..9e5dc2ec4a 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -671,7 +671,11 @@ static ivas_error ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, sba_order, nchan ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, nchan ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 3abe4280be..eac82bc20d 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -271,12 +271,18 @@ ivas_error ivas_spar_md_dec_open( return error; } +#ifndef SBA_BITRATE_SWITCHING #ifdef SBA_HOA_HBR_IMPROV hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); +#endif #endif hMdDec->table_idx = 0; /* just to initialize state variables*/ +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, sba_order, nchan ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, nchan ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -437,13 +443,20 @@ void ivas_spar_md_dec_close( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t nchan /* i : number of internal channels */ +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + const int16_t sba_order, /* i : SBA order */ +#endif + const int16_t nchan /* i : number of internal channels */ ) { int16_t i, j, k; int16_t nchan_transport; float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; +#if ( defined SBA_BITRATE_SWITCHING && defined SBA_HOA_HBR_IMPROV ) + hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); +#endif + hMdDec->spar_md_cfg.gen_bs = 1; // VE2DB : always 1 - can it be removed? #ifdef SBA_HOA_HBR_IMPROV @@ -1412,7 +1425,7 @@ void ivas_spar_dec_gen_umx_mat( } } } - + #ifdef DEBUG_SBA_MD_DUMP { static FILE *f_mat = 0; diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 2ee3201856..e3bcc251a5 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -121,6 +121,9 @@ ivas_error ivas_sba_enc_reconfigure( if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { + DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; + SPAR_ENC_HANDLE hSpar; + nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; @@ -154,6 +157,8 @@ ivas_error ivas_sba_enc_reconfigure( st_ivas->hSpar = NULL; } + hSpar = st_ivas->hSpar; + if ( st_ivas->nchan_transport == 1 ) { hEncoderConfig->element_mode_init = IVAS_SCE; @@ -167,10 +172,10 @@ ivas_error ivas_sba_enc_reconfigure( if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { // VE: TBV whether 'hFbMixer' can be reused - if ( st_ivas->hDirAC->hFbMixer != NULL ) + if ( hDirAC->hFbMixer != NULL ) { - ivas_FB_mixer_close( &( st_ivas->hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); - st_ivas->hDirAC->hFbMixer = NULL; + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); + hDirAC->hFbMixer = NULL; } { @@ -184,18 +189,18 @@ ivas_error ivas_sba_enc_reconfigure( nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); /* Covar. State handle */ - ivas_spar_covar_enc_close( &st_ivas->hSpar->hCovEnc, st_ivas->hSpar->hFbMixer->fb_cfg->nchan_inp ); + ivas_spar_covar_enc_close( &hSpar->hCovEnc, hSpar->hFbMixer->fb_cfg->nchan_inp ); /* MD handle */ - ivas_spar_md_enc_close( &st_ivas->hSpar->hMdEnc ); + ivas_spar_md_enc_close( &hSpar->hMdEnc ); - if ( ( error = ivas_spar_md_enc_open( &( st_ivas->hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) { return error; } /* FB mixer handle */ - ivas_FB_mixer_close( &st_ivas->hSpar->hFbMixer, hEncoderConfig->input_Fs ); + ivas_FB_mixer_close( &hSpar->hFbMixer, hEncoderConfig->input_Fs ); table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; @@ -203,15 +208,15 @@ ivas_error ivas_sba_enc_reconfigure( { return error; } - fb_cfg->remix_order = remix_order_set[st_ivas->hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; - if ( ( error = ivas_FB_mixer_open( &( st_ivas->hSpar->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) { return error; } /* Covar. State handle */ - if ( ( error = ivas_spar_covar_enc_open( &( st_ivas->hSpar->hCovEnc ), st_ivas->hSpar->hFbMixer->pFb, hEncoderConfig->input_Fs, nchan_internal ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, hEncoderConfig->input_Fs, nchan_internal ) ) != IVAS_ERR_OK ) { return error; } @@ -219,7 +224,7 @@ ivas_error ivas_sba_enc_reconfigure( } else { - if ( st_ivas->hDirAC->hFbMixer == NULL ) + if ( hDirAC->hFbMixer == NULL ) { IVAS_FB_CFG *fb_cfg; @@ -229,7 +234,7 @@ ivas_error ivas_sba_enc_reconfigure( } /* Allocate and initialize FB mixer handle */ - if ( ( error = ivas_FB_mixer_open( &( st_ivas->hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) { return error; } @@ -241,21 +246,21 @@ ivas_error ivas_sba_enc_reconfigure( { int16_t n; - if ( st_ivas->hDirAC->num_samples_synchro_delay == 0 ) + if ( hDirAC->num_samples_synchro_delay == 0 ) { - st_ivas->hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) { - if ( ( st_ivas->hDirAC->sba_synchro_buffer[n] = (float *) count_malloc( st_ivas->hDirAC->num_samples_synchro_delay * sizeof( float ) ) ) == NULL ) + if ( ( hDirAC->sba_synchro_buffer[n] = (float *) count_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( st_ivas->hDirAC->sba_synchro_buffer[n], st_ivas->hDirAC->num_samples_synchro_delay ); + set_zero( hDirAC->sba_synchro_buffer[n], hDirAC->num_samples_synchro_delay ); } for ( ; n < DIRAC_MAX_ANA_CHANS; n++ ) { - st_ivas->hDirAC->sba_synchro_buffer[n] = NULL; + hDirAC->sba_synchro_buffer[n] = NULL; } } } @@ -263,13 +268,13 @@ ivas_error ivas_sba_enc_reconfigure( { for ( int16_t n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) { - if ( st_ivas->hDirAC->sba_synchro_buffer[n] != NULL ) + if ( hDirAC->sba_synchro_buffer[n] != NULL ) { - count_free( st_ivas->hDirAC->sba_synchro_buffer[n] ); - st_ivas->hDirAC->sba_synchro_buffer[n] = NULL; + count_free( hDirAC->sba_synchro_buffer[n] ); + hDirAC->sba_synchro_buffer[n] = NULL; } } - st_ivas->hDirAC->num_samples_synchro_delay = 0; + hDirAC->num_samples_synchro_delay = 0; } #endif @@ -281,8 +286,8 @@ ivas_error ivas_sba_enc_reconfigure( #ifdef SBA_BITRATE_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); - st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + 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; } #endif diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index a063165005..676597d75b 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -124,8 +124,10 @@ ivas_error ivas_spar_md_enc_open( nchan = 2 * sba_order + 2; +#ifndef SBA_BITRATE_SWITCHING #ifdef SBA_HOA_HBR_IMPROV hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); +#endif #endif if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) @@ -330,6 +332,12 @@ ivas_error ivas_spar_md_enc_init( table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); +#ifdef SBA_BITRATE_SWITCHING +#ifdef SBA_HOA_HBR_IMPROV + hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); +#endif +#endif + hMdEnc->spar_md_cfg.gen_bs = 1; ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, #ifdef SBA_HOA_HBR_IMPROV -- GitLab