diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 172dbc53650f2b5945e7600a7fdd3937a92b669d..ba36229d3e095a0b72a315dd79da5de35bc6fd58 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -137,7 +137,9 @@ ivas_error ivas_dirac_config( } hConfig->enc_param_start_band = 0; hConfig->dec_param_estim = FALSE; - +#ifdef FIX_391_SBA + hConfig->dec_param_estim_old = hConfig->dec_param_estim; +#endif if ( ivas_format == SBA_FORMAT ) /* skip for MASA decoder */ { if ( ( error = ivas_dirac_sba_config( hQMetaData, nchan_transport, nSCE, nCPE, element_mode, ivas_total_brate, sba_order, sba_mode, hConfig->nbands - spar_dirac_split_band ) ) != IVAS_ERR_OK ) diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 22feb9b1648dc6d19e735024acf1587ef55cafa8..9f1fafff27b34e722d78c11288f974589010fe92 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -174,6 +174,9 @@ typedef struct ivas_dirac_config_data_struct { int16_t enc_param_start_band; int16_t dec_param_estim; +#ifdef FIX_391_SBA + int16_t dec_param_estim_old; +#endif int16_t nbands; } DIRAC_CONFIG_DATA, *DIRAC_CONFIG_DATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index adb91a2624b42773b74511e7f82cf16943943e35..a1112180273c42e84bcb97b5f5896f26b3edac4d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,8 +179,9 @@ /*#define LBR_SBA_PLANAR*/ /* Converting low bitrate SBA modes to Planar */ #define LBR_ADAP_SMOOTHING #endif -#define EUALER2QUAT_FIX /*Dlb :fix for issue 430 issue in euler2quat, sign of quat y is inverted*/ +#define FIX_391_SBA /* Dlb: Fix for issue 391 for SBA */ +#define EUALER2QUAT_FIX /*Dlb :fix for issue 430 issue in euler2quat, sign of quat y is inverted*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index dfeb946a02f4c84791e341f9f626c9d1ad8711a0..446ed23bb3b99ccd974e4ef0e4fdfd127bea4c52 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -820,7 +820,9 @@ ivas_error ivas_dirac_dec_config( hDirAC->dirac_bs_md_write_idx = 0; hDirAC->dirac_read_idx = 0; hDirAC->spar_to_dirac_write_idx = 0; - +#ifdef FIX_391_SBA + hDirAC->hConfig->dec_param_estim_old = hDirAC->hConfig->dec_param_estim; +#endif if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; @@ -984,7 +986,153 @@ ivas_error ivas_dirac_dec_config( hDirAC->dithering_seed = DIRAC_DITH_SEED; st_ivas->hDirAC = hDirAC; } +#ifdef FIX_391_SBA + else if ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) + { + int16_t num_slots_in_subfr; + num_slots_in_subfr = hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) ) + { + + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->azimuth[i] != NULL ) + { + free( hDirAC->azimuth[i] ); + hDirAC->azimuth[i] = NULL; + } + if ( hDirAC->elevation[i] != NULL ) + { + free( hDirAC->elevation[i] ); + hDirAC->elevation[i] = NULL; + } + if ( hDirAC->diffuseness_vector[i] != NULL ) + { + free( hDirAC->diffuseness_vector[i] ); + hDirAC->diffuseness_vector[i] = NULL; + } + if ( hDirAC->energy_ratio1[i] != NULL ) + { + free( hDirAC->energy_ratio1[i] ); + hDirAC->energy_ratio1[i] = NULL; + } + if ( hDirAC->spreadCoherence[i] != NULL ) + { + free( hDirAC->spreadCoherence[i] ); + hDirAC->spreadCoherence[i] = NULL; + } + if ( hDirAC->surroundingCoherence[i] != NULL ) + { + free( hDirAC->surroundingCoherence[i] ); + hDirAC->surroundingCoherence[i] = NULL; + } + } + if ( hDirAC->azimuth != NULL ) + { + free( hDirAC->azimuth ); + hDirAC->azimuth = NULL; + } + if ( hDirAC->elevation != NULL ) + { + free( hDirAC->elevation ); + hDirAC->elevation = NULL; + } + if ( hDirAC->diffuseness_vector != NULL ) + { + free( hDirAC->diffuseness_vector ); + hDirAC->diffuseness_vector = NULL; + } + if ( hDirAC->energy_ratio1 != NULL ) + { + free( hDirAC->energy_ratio1 ); + hDirAC->energy_ratio1 = NULL; + } + if ( hDirAC->spreadCoherence != NULL ) + { + free( hDirAC->spreadCoherence ); + hDirAC->spreadCoherence = NULL; + } + if ( hDirAC->surroundingCoherence != NULL ) + { + free( hDirAC->surroundingCoherence ); + hDirAC->surroundingCoherence = NULL; + } + } + hDirAC->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ) * num_slots_in_subfr; + hDirAC->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR * num_slots_in_subfr; + hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR * num_slots_in_subfr; + if ( ( hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->diffuseness_vector = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + if ( ( hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( ( hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hDirAC->azimuth[i], 0, hDirAC->num_freq_bands ); + + if ( ( hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hDirAC->elevation[i], 0, hDirAC->num_freq_bands ); + + if ( ( hDirAC->diffuseness_vector[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->diffuseness_vector[i], 1.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->spreadCoherence[i], 0.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); + } + } + } +#endif return error; }