diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 91f1127788e07d7575689fdc2c3dd96dfcc48427..f6369235a60c48b21f0f0647ed3a707740e5aae2 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1026,7 +1026,7 @@ typedef enum #define SPAR_CONFIG_BW FB -#ifndef SPAR_TUNING +#ifndef HODIRAC #define IVAS_SPAR_MAX_CH (FOA_CHANNELS + 2 * ( IVAS_MAX_SBA_ORDER - 1 )) /* FOA + planar HOA */ #else #define IVAS_SPAR_MAX_CH ((( IVAS_MAX_SBA_ORDER ) * ( IVAS_MAX_SBA_ORDER )) + 2) /* HOA2 + pHOA3*/ @@ -1034,10 +1034,9 @@ typedef enum #endif #ifdef HODIRAC -#define IVAS_SPAR_MAX_FB_IN_CHAN 11 +#define IVAS_SPAR_MAX_FB_IN_CHAN 11 #endif - #define IVAS_SPAR_P_LOWERTRI ((IVAS_SPAR_MAX_CH - 1) * (IVAS_SPAR_MAX_CH - 2)) >> 1 #define IVAS_SPAR_MAX_C_COEFF (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * ( IVAS_SPAR_MAX_DMX_CHS - 1) @@ -1267,10 +1266,10 @@ enum #define MASA_BIT_REDUCT_PARAM 10 #ifdef HR_METADATA -#define MASA_MAXIMUM_TWO_DIR_BANDS 24 -#define NBITS_HR_COH 4 +#define MASA_MAXIMUM_TWO_DIR_BANDS 24 +#define NBITS_HR_COH 4 #else -#define MASA_MAXIMUM_TWO_DIR_BANDS 18 +#define MASA_MAXIMUM_TWO_DIR_BANDS 18 #endif typedef enum { diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 2792efc1963d0578d932c6952be61d65ab88ad42..d0b4c5a4db1b3a37719ab466836e24645f3c1e2e 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -48,6 +48,32 @@ static uint16_t deindex_sph_idx_general( const int16_t idx_sph, const int16_t no_bits, float *theta_dec, float *phi_dec, uint16_t *p_id_phi, const MC_LS_SETUP mc_format ); + +#ifdef HODIRAC +/*------------------------------------------------------------------------- + * ivas_get_hodirac_flag() + * + * Return flag for HO-DirAC method at high bitrates + *------------------------------------------------------------------------*/ + +/*! r: HO-DirAC flag */ +int16_t ivas_get_hodirac_flag( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +) +{ + if ( sba_order > 1 && ivas_total_brate > IVAS_256k ) + { + return 1; + } + else + { + return 0; + } +} +#endif + + /*------------------------------------------------------------------------- * ivas_dirac_sba_config() * @@ -132,8 +158,9 @@ ivas_error ivas_dirac_config( hConfig->nbands = IVAS_MAX_NUM_BANDS; spar_dirac_split_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + #ifdef HODIRAC - if ( sba_order > 1 && ivas_total_brate > IVAS_256k ) + if ( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) ) { spar_dirac_split_band = 0; } @@ -173,8 +200,9 @@ ivas_error ivas_dirac_config( { hConfig->enc_param_start_band = spar_dirac_split_band; } + #ifdef HODIRAC - if ( sba_order > 1 && ivas_total_brate > IVAS_256k ) + if ( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) ) { hConfig->dec_param_estim = FALSE; hConfig->enc_param_start_band = 0; @@ -195,15 +223,11 @@ ivas_error ivas_dirac_config( if ( sba_mode == SBA_MODE_SPAR ) { - ivas_dirac_config_bands( band_grouping, - IVAS_MAX_NUM_BANDS, - (int16_t) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), - dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft ); + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft ); } else { - ivas_dirac_config_bands( band_grouping, hConfig->nbands, (int16_t) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), - NULL, 0, 0, hFbMdft ); + ivas_dirac_config_bands( band_grouping, hConfig->nbands, (int16_t) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), NULL, 0, 0, hFbMdft ); } return error; @@ -335,10 +359,16 @@ ivas_error ivas_dirac_sba_config( int16_t i; int16_t nbands_wb; int16_t nbands_coded; +#ifdef HODIRAC + int16_t hodirac_flag; +#endif ivas_error error; error = IVAS_ERR_OK; hQMetaData->is_masa_ivas_format = 0; +#ifdef HODIRAC + hodirac_flag = ivas_get_hodirac_flag( sba_total_brate, sba_order ); +#endif if ( sba_mode == SBA_MODE_SPAR ) { @@ -376,7 +406,7 @@ ivas_error ivas_dirac_sba_config( { hQMetaData->useLowerBandRes = 0; #ifdef HODIRAC - if ( !( sba_order > 1 && sba_total_brate > IVAS_256k ) ) + if ( hodirac_flag == 0 ) #endif { nbands_coded = nbands - 1; /* always combine the last two bands */ @@ -386,7 +416,7 @@ ivas_error ivas_dirac_sba_config( { int16_t no_dirs = 1; #ifdef HODIRAC - if ( sba_order > 1 && sba_total_brate > IVAS_256k ) + if ( hodirac_flag ) { no_dirs = 2; } @@ -396,8 +426,7 @@ ivas_error ivas_dirac_sba_config( { return error; } -#if defined( HODIRAC_FIX_BR_SWITCHING_DTX ) && !defined( FIX_DTX_428 ) - if ( sba_order > 1 && sba_total_brate > IVAS_256k ) +#if defined( HODIRAC ) && !defined( FIX_DTX_428 ) { int16_t dir, j; for ( dir = 0; dir < hQMetaData->no_directions; dir++ ) @@ -508,7 +537,7 @@ ivas_error ivas_dirac_sba_config( { int16_t no_dirs = 1; #ifdef HODIRAC - if ( sba_order > 1 && sba_total_brate > IVAS_256k ) + if ( hodirac_flag ) { no_dirs = 2; } @@ -545,8 +574,9 @@ ivas_error ivas_dirac_sba_config( for ( i = 0; i < hQMetaData->no_directions; i++ ) { hQMetaData->q_direction[i].cfg.search_effort = 1; + #ifdef HODIRAC - if ( sba_order > 1 && sba_total_brate > IVAS_256k ) + if ( hodirac_flag ) { hQMetaData->q_direction[i].cfg.start_band = 0; } @@ -857,19 +887,26 @@ void deindex_spherical_component( return; } + #ifdef HODIRAC +/*---------------------------------------------------------------- + * calculate_hodirac_sector_parameters() + * + * + *-----------------------------------------------------------------*/ + void calculate_hodirac_sector_parameters( - float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i: signal vector (L+1)^2 x N_bins, real part */ - float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i: signal vector, imaginary part*/ - const int16_t N_bins, /* i: number of bins */ - const float beta, /* i: forgetting factor for average filtering */ - const int16_t *band_grouping, /* i: indices of band groups */ - const int16_t N_bands, /* i: number of bands (groups) */ - const int16_t enc_param_start_band, /* i: first band to process */ - float *azi, /* o: array of sector azimuth angles, flat */ - float *ele, /* o: array of sector elevation angles, flat */ - float *diff, /* o: array of sector diffuseness values, flat*/ - float *ene /* o: array of sector energy values, flat*/ + float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + const int16_t N_bins, /* i : number of bins */ + const float beta, /* i : forgetting factor for average filtering */ + const int16_t *band_grouping, /* i : indices of band groups */ + const int16_t N_bands, /* i : number of bands (groups) */ + const int16_t enc_param_start_band, /* i : first band to process */ + float *azi, /* o : array of sector azimuth angles, flat */ + float *ele, /* o : array of sector elevation angles, flat */ + float *diff, /* o : array of sector diffuseness values, flat */ + float *ene /* o : array of sector energy values, flat */ ) { int16_t i_sec, i_bin, i_band; @@ -1060,14 +1097,12 @@ void calculate_hodirac_sector_parameters( *p_azi_prev = *p_azi; *p_ele_prev = *p_ele; } -#ifdef HODIRAC_CHECK_VALUE_RANGE - assert( *p_azi >= -180.f && *p_azi <= 180.f ); - assert( *p_ele >= -90.f && *p_ele <= 90.f ); -#endif - } // i_band - } // i_sec + } + } firstrun_sector_params = 0; + + return; } #endif @@ -1083,7 +1118,7 @@ void calculate_hodirac_sector_parameters( * deindex the spherical index for more than 2 bits for the spherical grid *----------------------------------------------------------------------*/ -/* !r: decoded elevation index */ +/*! r: decoded elevation index */ static uint16_t deindex_sph_idx_general( const int16_t idx_sph, /* i : spherical index */ const int16_t no_bits, /* i : number of bits in the spherical grid*/ diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 3f54709bfff0ffafa5551aed85cbf27900f4c1d2..2598a43d3001e02c7cdcca3c011fa74bf2f47bb2 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -99,16 +99,16 @@ static int16_t ivas_get_num_bands( *---------------------------------------------------------------------*/ 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 active_w_mixing, /* i : active_w_mixing flag */ - const int32_t sampling_rate /* i : sampling rate */ + 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 active_w_mixing, /* i : active_w_mixing flag */ + const int32_t sampling_rate /* i : sampling rate */ #ifdef HODIRAC , - const int16_t nchan_fb_in /* i: number of dirac analysis channels */ + const int16_t nchan_fb_in /* i : number of dirAC analysis channels*/ #endif ) { @@ -526,7 +526,7 @@ void ivas_fb_mixer_pcm_ingest( float pcm_in[][L_FRAME48k], /* i : input audio channels */ float **ppOut_pcm, /* o : output audio channels */ const int16_t frame_len /* i : frame length */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] #endif @@ -553,7 +553,7 @@ void ivas_fb_mixer_pcm_ingest( { mvr2r( &hFbMixer->ppFilterbank_prior_input[i][fb_cfg->prior_input_length - frame_len], ppOut_pcm[i], frame_len ); #ifdef HODIRAC -#ifdef SPAR_TUNING +#ifdef HODIRAC mvr2r( pcm_in[HOA_md_ind[i]], &ppOut_pcm[i][frame_len], frame_len ); #else mvr2r( pcm_in[HOA_keep_ind_spar[i]], &ppOut_pcm[i][frame_len], frame_len ); @@ -579,12 +579,12 @@ void ivas_fb_mixer_pcm_ingest( *-----------------------------------------------------------------------------------------*/ void ivas_fb_mixer_update_prior_input( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float *pcm_in[], /* i : input audio channels */ - const int16_t length /* i : length of time slot */ + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float *pcm_in[], /* i : input audio channels */ + const int16_t length /* i : length of time slot */ #ifdef HODIRAC , - const int16_t nchan_fb_in + const int16_t nchan_fb_in /* i : number of analysis channels */ #endif ) { @@ -621,7 +621,7 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t mdft_len /* i : MDFT frame length */ #ifdef HODIRAC , - int16_t nchan_fb_in + const int16_t nchan_fb_in /* i : number of analysis channels */ #endif ) { diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 02d9939dc49ef33e237293183fec208494287dd3..7c0955436d02a2fbcadaaa565dd5c5bfd2d967d8 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -412,12 +412,19 @@ void masa_sample_rate_band_correction( return; } + #ifdef HR_METADATA -/* !r: output index for direction */ +/*------------------------------------------------------------------------- + * index_theta_phi_16() + * + * + *------------------------------------------------------------------------*/ + +/*! r: output index for direction */ uint16_t index_theta_phi_16( - float *p_theta, /* i/o : input elevation to be indexed */ - float *p_phi, /* i/o : input azimuth to be indexed */ - SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ + float *p_theta, /* i/o: input elevation to be indexed */ + float *p_phi, /* i/o: input azimuth to be indexed */ + const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ ) { float abs_theta; @@ -501,14 +508,21 @@ uint16_t index_theta_phi_16( } } - return idx_sph; } + +/*------------------------------------------------------------------------- + * quantize_phi_masa() + * + * + *------------------------------------------------------------------------*/ + +/*! r: output index */ int16_t quantize_theta( - float x, /* i : theta value to be quantized */ - int16_t no_cb, /* i : number of codewords */ - float *xhat /* o : quantized value */ + float x, /* i : theta value to be quantized */ + const int16_t no_cb, /* i : number of codewords */ + float *xhat /* o : quantized value */ ) { int16_t imin; @@ -540,12 +554,18 @@ int16_t quantize_theta( } -/* !r: index azimuth */ +/*------------------------------------------------------------------------- + * quantize_phi_masa() + * + * + *------------------------------------------------------------------------*/ + +/*! r: index azimuth */ int16_t quantize_phi_masa( - float phi, /* i : azimuth value */ - int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - float *phi_hat, /* o : quantized azimuth */ - const int16_t n /* i : azimuth codebook size */ + float phi, /* i : azimuth value */ + const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + float *phi_hat, /* o : quantized azimuth */ + const int16_t n /* i : azimuth codebook size */ ) { int16_t id_phi; @@ -587,4 +607,159 @@ int16_t quantize_phi_masa( return id_phi; } + +/*------------------------------------------------------------------------- + * deindex_sph_idx() + * + * deindex the MASA metadata from the input metadata file + *------------------------------------------------------------------------*/ + +void deindex_sph_idx( + const uint16_t sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + float *theta, /* o : Elevation */ + float *phi /* o : Azimuth */ +) +{ + float ba_crt, del_crt, div_crt, a4_crt; + float estim; + int32_t base_low, base_up; + int16_t n_crt; + int16_t id_th; + int16_t sign_theta; + int16_t id_phi; + int16_t no_th = gridData->no_theta; + const int16_t *n = gridData->no_phi; + const float ba[3] = { + 2.137991118026424e+02f, + 1.244854404591542e+02f, + 1.228408647140870e+02f, + }; + const float del[3] = { 7.998262115303199e+05f, 1.300883976959332e+06f, 1.424072242426373e+06f }; + const float div[3] = { -0.237662341081474f, -0.100938185496887f, -0.092050209205032f }; + const float a4[3] = { -8.415300425381099f, -19.814106922515204f, -21.727272727270197f }; + const uint16_t limit_index1 = 64964, limit_index2 = 47870; + + if ( sphIndex >= limit_index1 ) + { + ba_crt = ba[2]; + div_crt = div[2]; + a4_crt = a4[2]; + del_crt = del[2]; + } + else if ( sphIndex >= limit_index2 ) + { + ba_crt = ba[1]; + div_crt = div[1]; + a4_crt = a4[1]; + del_crt = del[1]; + } + else + { + ba_crt = ba[0]; + div_crt = div[0]; + a4_crt = a4[0]; + del_crt = del[0]; + } + estim = ba_crt + div_crt * sqrtf( del_crt + a4_crt * sphIndex ); + + if ( estim > MASA_NO_CIRCLES ) + { + estim = MASA_NO_CIRCLES; + } + + assert( estim > 0 ); + id_th = (int16_t) roundf( estim ) - 1; + if ( id_th < 0 ) + { + id_th = 0; + } + + if ( id_th == 0 ) + { + base_low = 0; + base_up = n[0]; + } + else + { + estim = MASA_ANGLE_AT_EQUATOR * (float) ( id_th - 0.5f ); + base_low = n[0]; + if ( id_th >= 2 ) + { + if ( id_th == 2 ) + { + base_low += 2 * (int16_t) ceilf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) ); + } + else + { + base_low += 2 * (int16_t) roundf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) ); + } + } + base_up = base_low + 2 * n[id_th]; + } + + sign_theta = 1; + + n_crt = n[id_th]; + if ( sphIndex < base_low ) + { + id_th--; + n_crt = n[id_th]; + if ( id_th == 0 ) + { + base_low = 0; + base_up = n_crt; + } + else + { + base_up = base_low; + base_low -= 2 * n[id_th]; + } + assert( sphIndex >= base_low ); + } + else if ( sphIndex >= base_up ) + { + id_th++; + n_crt = n[id_th]; + base_low = base_up; + base_up += 2 * n_crt; + assert( sphIndex < base_up ); + } + + id_phi = (int16_t) ( sphIndex - base_low ); + if ( sphIndex - base_low >= n_crt ) + { + id_phi -= n_crt; + sign_theta = -1; + } + + if ( id_th == 0 ) + { + *theta = 0.f; + *phi = (float) sphIndex * 360 / (float) n_crt - 180; + } + else + { + if ( id_th == no_th - 1 ) + { + id_phi = 0; + *phi = -180; + *theta = 90 * (float) sign_theta; + } + else + { + *theta = id_th * MASA_ANGLE_AT_EQUATOR_DEG * (float) sign_theta; + if ( id_th % 2 == 0 ) + { + *phi = (float) id_phi * 360 / (float) n_crt - 180; + } + else + { + *phi = ( (float) id_phi + 0.5f ) * 360 / (float) n_crt - 180; + } + } + } + + return; +} #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index dc803e58cb2a5adc6a9f6c77af5496441acbe571..672b5a7441735223fbdc3befbf75c92c674bcefe 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3102,53 +3102,45 @@ ivas_error ivas_qmetadata_enc_encode( IVAS_QMETADATA *hQMetaData /* i/o: q_metadata handle */ #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); #ifdef HR_METADATA - ivas_error ivas_qmetadata_enc_encode_hr_384_512( - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ - int16_t bits_sph_idx, - int16_t bits_sp_coh -); -int16_t ivas_qmetadata_dec_decode_hr_384_512( - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - uint16_t *bitstream, /* i : bitstream */ - int16_t *index, /* i/o: bitstream position */ - SPHERICAL_GRID_DATA *sph_grid16, /* i: spherical grid for deindexing */ - int16_t bits_sph_idx, - int16_t bits_sp_coh + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ + const int16_t bits_sph_idx, + const int16_t bits_sp_coh ); void deindex_sph_idx( - const uint16_t sphIndex, /* i : Spherical index */ - const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ - float *theta, /* o : Elevation */ - float *phi /* o : Azimuth */ + const uint16_t sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + float *theta, /* o : Elevation */ + float *phi /* o : Azimuth */ ); - +/*! r: output index for direction */ uint16_t index_theta_phi_16( - float * p_theta, /* i/o : input elevation to be indexed */ - float * p_phi, /* i/o : input azimuth to be indexed */ - SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ + float * p_theta, /* i/o: input elevation to be indexed */ + float * p_phi, /* i/o: input azimuth to be indexed */ + const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ ); - int16_t quantize_theta( - float x, /* i : theta value to be quantized */ - int16_t no_cb, /* i : number of codewords */ - float *xhat /* o : quantized value */ +/*! r: output index */ +int16_t quantize_theta( + float x, /* i : theta value to be quantized */ + const int16_t no_cb, /* i : number of codewords */ + float *xhat /* o : quantized value */ ); -/* !r: index azimuth */ - int16_t quantize_phi_masa( - float phi, /* i : azimuth value */ - int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - float *phi_hat, /* o : quantized azimuth */ - const int16_t n /* i : azimuth codebook size */ +/*! r: index azimuth */ +int16_t quantize_phi_masa( + float phi, /* i : azimuth value */ + const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + float *phi_hat, /* o : quantized azimuth */ + const int16_t n /* i : azimuth codebook size */ ); #endif @@ -3178,11 +3170,21 @@ int16_t ivas_qmetadata_dec_decode( int16_t *index /* i/o: bitstream position */ #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); - +#ifdef HR_METADATA +/*! r: number of bits read */ +int16_t ivas_qmetadata_dec_decode_hr_384_512( + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ + uint16_t *bitstream, /* i : bitstream */ + int16_t *index, /* i/o: bitstream position */ + const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */ + const int16_t bits_sph_idx, + const int16_t bits_sp_coh +); +#endif /*! r: number of bits read */ int16_t ivas_qmetadata_dec_sid_decode( @@ -3202,7 +3204,7 @@ void ivas_qmetadata_to_dirac( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const SBA_MODE sba_mode, /* i : SBA mode */ #ifdef HODIRAC - const int16_t sba_analysis_order, /* i sba order*/ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ #endif int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); @@ -3229,7 +3231,7 @@ void restore_metadata_buffer( const int16_t bit_pos_start ); -/* !r: codeword index */ +/*! r: codeword index */ int16_t masa_sq( const float in, /* i : input value */ const float *threshold, /* i : partition */ @@ -3263,11 +3265,11 @@ void quantize_direction_frame( float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ #endif ); -/* !r: quantized spherical index */ +/*! r: quantized spherical index */ uint16_t quantize_direction( const float theta, /* i : input elevation value */ float phi, /* i : input azimuth value */ @@ -3287,7 +3289,7 @@ int16_t quantize_direction2D( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -/* !r :companded azimuth value */ +/*! r :companded azimuth value */ float companding_azimuth( const float azi, /* i : input azimuth value */ const MC_LS_SETUP mc_format, /* i : input channel format */ @@ -3295,14 +3297,14 @@ float companding_azimuth( const int16_t direction /* i : direction of companding (direct or inverse)*/ ); -/* !r: index azimuth */ +/*! r: index azimuth */ int16_t quantize_phi_chan_lbr( const float phi, /* i : azimuth value */ float *phi_hat, /* o : quantized azimuth */ const int16_t n /* i : azimuth codebook size */ ); -/* !r: index azimuth */ +/*! r: index azimuth */ int16_t quantize_phi_chan_compand( float phi, /* i : azimuth value */ float *phi_hat, /* o : quantized azimuth */ @@ -3326,7 +3328,7 @@ void small_requantize_direction_frame( int16_t *diff /* i/o: number of bits to be reduced */ ); -/*!r : index azimuth */ +/*! r: index azimuth */ int16_t quantize_phi( float phi, /* i : azimuth value */ const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ @@ -3406,7 +3408,7 @@ void ivas_dirac_param_est_enc( const SBA_MODE sba_mode #ifdef HODIRAC , - const int16_t hodirac, + const int16_t hodirac_flag, const int16_t nchan_fb_in #endif ); @@ -3484,24 +3486,26 @@ int16_t ivas_sba_get_nchan( /*! r: number of ambisonics metadata channels */ int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order /* i : Ambisonic (SBA) order */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int32_t ivas_total_brate #endif ); -#ifdef SPAR_TUNING +#ifdef HODIRAC void ivas_sba_get_spar_hoa_ch_ind( - const int16_t num_md_chs, /* i : number of MD channels */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); + const int16_t num_md_chs, /* i : number of MD channels */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] +); /*! r: flag indicating to code SPAR HOA MD for all bands */ void ivas_sba_get_spar_hoa_md_flag( - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ int16_t *spar_hoa_md_flag, - int16_t *spar_hoa_dirac2spar_md_flag ); + int16_t *spar_hoa_dirac2spar_md_flag +); #else /*! r: flag indicating to code SPAR HOA MD for all bands */ int16_t ivas_sba_get_spar_hoa_md_flag( @@ -3509,6 +3513,7 @@ int16_t ivas_sba_get_spar_hoa_md_flag( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); #endif + void ivas_sba_zero_vert_comp( float sba_data[][L_FRAME48k], /* i/o: SBA data frame */ const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -3539,6 +3544,14 @@ void ivas_sba_dirac_stereo_config( STEREO_DFT_CONFIG_DATA_HANDLE hConfig /* o : DFT stereo configuration */ ); +#ifdef HODIRAC +/*! r: HO-DirAC flag */ +int16_t ivas_get_hodirac_flag( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +); +#endif + int16_t ivas_get_sba_dirac_stereo_flag( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -3622,6 +3635,13 @@ ivas_error ivas_dirac_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef DIRAC_ALLOC_HARM +ivas_error ivas_dirac_allocate_parameters( + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + const int16_t params_flag /* i : set of parameters flag */ +); +#endif + ivas_error ivas_dirac_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ @@ -3631,6 +3651,13 @@ void ivas_dirac_dec_close( DIRAC_DEC_HANDLE *hDirAC /* i/o: decoder DirAC handle */ ); +#ifdef DIRAC_ALLOC_HARM +void ivas_dirac_deallocate_parameters( + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + const int16_t params_flag /* i : set of parameters flag */ +); +#endif + void ivas_dirac_dec_read_BS( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ Decoder_State *st, /* i/o: decoder Core state structure */ @@ -3639,7 +3666,7 @@ void ivas_dirac_dec_read_BS( int16_t *nb_bits, /* o : number of bits read */ const SBA_MODE sba_mode, /* i : SBA mode */ #ifdef HODIRAC - const int16_t sba_analysis_order, /* i sba order*/ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ #endif int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); @@ -3790,7 +3817,6 @@ void ivas_dirac_dec_decorr_close( HANDLE_DIRAC_DECORR_STATE *ph_dirac_decorr_state ); - ivas_error ivas_dirac_dec_output_synthesis_open( DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ const RENDERER_TYPE renderer_type, /* i : renderer type */ @@ -3798,7 +3824,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open( const int32_t output_Fs /* i : output sampling rate */ #ifdef HODIRAC , - const int16_t hodirac /* i : flag to indicate HO-DirAC mode*/ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); @@ -3807,7 +3833,7 @@ void ivas_dirac_dec_output_synthesis_init( const int16_t nchan_out_woLFE /* i : number of output audio channels without LFE */ #ifdef HODIRAC , - const int16_t hodirac /* flag to indicate HO-DirAC mode */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); @@ -3837,7 +3863,7 @@ void ivas_dirac_dec_output_synthesis_process_slot( #endif #ifdef HODIRAC , - const int16_t hodirac + const int16_t hodirac_flag #endif ); @@ -3855,7 +3881,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( #ifdef JBM_TSM_ON_TCS const int16_t md_idx, #endif - const int16_t hodirac /* i: flag for sector-based processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); @@ -3915,7 +3941,7 @@ void ivas_dirac_dec_compute_directional_responses( const float *p_Rmat /* i : rotation matrix */ #ifdef HODIRAC , - const int16_t hodirac /* i : flag for sector based dirac processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); @@ -3926,53 +3952,60 @@ void ivas_dirac_dec_get_frequency_axis( #ifdef HODIRAC void calculate_hodirac_sector_parameters( - float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i: signal vector (L+1)^2 x N_bins, real part */ - float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i: signal vector, imaginary part*/ - const int16_t N_bins, /* i: number of bins */ - const float beta, /* i: forgetting factor for average filtering */ - const int16_t *band_grouping, /* i: indices of band groups */ - const int16_t N_bands, /* i: number of bands (groups) */ - const int16_t enc_param_start_band, /* i: first band to process */ - float *azi, /* o: array of sector azimuth angles, flat */ - float *ele, /* o: array of sector elevation angles, flat */ - float *diff, /* o: array of sector diffuseness values, flat*/ - float *ene /* o: array of sector energy values, flat*/ + float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + const int16_t N_bins, /* i : number of bins */ + const float beta, /* i : forgetting factor for average filtering */ + const int16_t *band_grouping, /* i : indices of band groups */ + const int16_t N_bands, /* i : number of bands (groups) */ + const int16_t enc_param_start_band, /* i : first band to process */ + float *azi, /* o : array of sector azimuth angles, flat */ + float *ele, /* o : array of sector elevation angles, flat */ + float *diff, /* o : array of sector diffuseness values, flat */ + float *ene /* o : array of sector energy values, flat */ ); #endif #ifdef MC_PARAMUPMIX_MODE void ivas_mc_paramupmix_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ - float data_f[][L_FRAME48k], /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */ - const int16_t input_frame /* i : input frame length */ + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + float data_f[][L_FRAME48k], /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */ + const int16_t input_frame /* i : input frame length */ ); + ivas_error ivas_mc_paramupmix_enc_open( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + void ivas_mc_paramupmix_enc_close( - MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ const int32_t sampling_rate ); + void ivas_mc_paramupmix_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels/DirAC output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels/DirAC output */ ); + int16_t ivas_mc_paramupmix_getNumTransportChannels( void ); + ivas_error ivas_mc_paramupmix_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); + void ivas_mc_paramupmix_dec_close( - MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ + MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ ); + void ivas_mc_paramupmix_dec_read_BS( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ - int16_t *nb_bits /* o : number of bits written */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + Decoder_State *st, /* i/o: decoder state structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + int16_t *nb_bits /* o : number of bits written */ ); #endif @@ -4174,7 +4207,7 @@ int16_t computeMixingMatricesResidual( float *mixing_matrix /* o : resulting residual mixing matrix */ ); -/* !r: error or success */ +/*! r: error or success */ int16_t svd( float InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ float singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* o : left singular vectors (U) */ @@ -4444,7 +4477,7 @@ int16_t ivas_get_bw_idx_from_sample_rate( const int32_t sampling_rate /* i : sampling rate */ ); -/* !r: config. table index */ +/*! r: config. table index */ int16_t ivas_get_spar_table_idx( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t sba_order, /* i : IVAS SBA order */ @@ -4516,7 +4549,7 @@ void ivas_spar_get_cldfb_gains( const DECODER_CONFIG_HANDLE hDecoderConfig ); -/* !r: 1 if prediction residual channel */ +/*! r: 1 if prediction residual channel */ int16_t ivas_is_res_channel( const int16_t ch, /* i : ch index in WYZX ordering */ const int16_t nchan_transport /* i : number of transport channels (1-4) */ @@ -4658,7 +4691,7 @@ void ivas_get_spar_md_from_dirac( const int16_t active_w_vlbr ); -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t ivas_get_spar_dec_md_num_subframes( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate ); @@ -4716,7 +4749,7 @@ void ivas_spar_update_md_hist( void ivas_spar_smooth_md_dtx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out /* i : number of output bands */ - #ifdef SPAR_TUNING + #ifdef HODIRAC , const int16_t num_md_sub_frames /* i : number of metadata subframes */ #endif @@ -4725,7 +4758,7 @@ void ivas_spar_smooth_md_dtx( void ivas_spar_setup_md_smoothing( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out /* i : number of output bands */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames /* i : number of metadata subframes */ #endif @@ -4736,7 +4769,7 @@ void ivas_spar_dec_gen_umx_mat( const int16_t nchan_transport, /* i : number of transport channels */ const int16_t num_bands_out, /* i : number of output bands */ const int16_t bfi /* i : bad frame indicator */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif @@ -4769,7 +4802,7 @@ void ivas_enc_cov_handler_process( const int16_t nchan_inp, const int16_t dtx_vad, const int16_t transient_det[2] -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] #endif @@ -5148,7 +5181,7 @@ void masa_compensate_two_dir_energy_ratio_index( int16_t *ratio_index_mod2 /* o : Output modified ratio for direction 2 */ #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ); @@ -5160,21 +5193,21 @@ void ivas_set_qmetadata_maxbit_req( #ifdef HODIRAC /*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ int16_t ivas_get_df_ratio_bits_hodirac( - int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ + const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ ); #endif /*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ int16_t ivas_get_df_ratio_bits( - int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ + const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ ); void masa_sample_rate_band_correction( MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */ int16_t *band_mapping, /* i/o: Band mapping used and modified */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */ - const int32_t sampling_rate /* i : sampling rate */ - , MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ + const int32_t sampling_rate, /* i : sampling rate */ + MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ ); void invdct4_transform( @@ -5552,7 +5585,7 @@ void computeReferencePower_enc( const SBA_MODE sba_mode /* i : SBA mode */ #ifdef HODIRAC , - int16_t nchan_ana /* i : no of analysis channels */ + const int16_t nchan_ana /* i : number of analysis channels */ #endif ); @@ -5691,7 +5724,7 @@ ivas_error ivas_fb_set_cfg( const int32_t sampling_Fs /* i : sampling rate */ #ifdef HODIRAC , - const int16_t nachan_dirac_ana /* i: number of dirac analysis channels */ + const int16_t nachan_dirac_ana /* i : number of DirAR analysis channels */ #endif ); @@ -5713,7 +5746,7 @@ void ivas_fb_mixer_pcm_ingest( float pcm_in[][L_FRAME48k], /* i : input audio channels */ float **ppOut_pcm, /* o : output audio channels */ const int16_t frame_length /* i : frame length */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] #endif @@ -5731,7 +5764,7 @@ void ivas_fb_mixer_update_prior_input( const int16_t length /* i : length of time slot */ #ifdef HODIRAC , - const int16_t nchan_fb_in + const int16_t nchan_fb_in /* i : number of analysis channels */ #endif ); @@ -5744,7 +5777,7 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t mdft_len /* i : MDFT frame length */ #ifdef HODIRAC , - int16_t nchan_fb_in + const int16_t nchan_fb_in /* i : number of analysis channels */ #endif ); @@ -5764,7 +5797,7 @@ void ivas_fb_mixer_get_in_out_mapping( int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); -/* !r: number of spectral bands */ +/*! r: number of spectral bands */ int16_t ivas_get_num_bands_from_bw_idx( const int16_t bwidth /* i : audio bandwidth */ ); diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 4bd135ec981ad288f319f6543c1718bfa54d5c16..380723604403c671773c0f6881c9f09782b95a4e 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -263,7 +263,7 @@ void ivas_qmetadata_close( * scalar quantization using partition *------------------------------------------------------------------------*/ -/* r: codeword index */ +/*! r: codeword index */ int16_t masa_sq( const float in, /* i : input value */ const float *threshold, /* i : partition */ @@ -510,26 +510,20 @@ void masa_compensate_two_dir_energy_ratio_index( int16_t *ratio_index_mod2 /* o : Output modified ratio for direction 2 */ #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { float ratio1, ratio2; -#ifndef HODIRAC float ratioSum; -#endif ratio1 = 1.0f - diffuseness_reconstructions[ratio_index_1]; ratio2 = 1.0f - diffuseness_reconstructions[ratio_index_2]; #ifdef HODIRAC - if ( !hodirac ) + if ( !hodirac_flag ) #endif { -#ifdef HODIRAC - float ratioSum; -#endif - ratioSum = ratio1 + ratio2; if ( ratio1 >= ratio2 ) { @@ -626,10 +620,17 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation( return; } + #ifdef HODIRAC +/*------------------------------------------------------------------------- + * ivas_get_df_ratio_bits_hodirac() + * + * + *------------------------------------------------------------------------*/ + /*! r: bits to be used for quantizing ratio of ratios */ int16_t ivas_get_df_ratio_bits_hodirac( - int16_t index_diff /* i : index of quantized diffuse-to-total ratio */ + const int16_t index_diff /* i : index of quantized diffuse-to-total ratio */ ) { int16_t dfRatio_bits; @@ -661,7 +662,7 @@ int16_t ivas_get_df_ratio_bits_hodirac( /*! r: bits to be used for quantizing ratio of ratios */ int16_t ivas_get_df_ratio_bits( - int16_t index_diff /* i : index of quantized diffuse-to-total ratio */ + const int16_t index_diff /* i : index of quantized diffuse-to-total ratio */ ) { int16_t dfRatio_bits; diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index 039dea53eb97d18f2537058c841560ae1a90719a..874f66d05910606c7197034c36e8aef9491c628b 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -71,7 +71,7 @@ uint16_t ivas_qmetadata_reorder_generic( * Returns the original value of the array "folded" by ReorderGeneric *------------------------------------------------------------------------*/ -/* !r: "Unfolded" value, positive or negative depending on the value of the input */ +/*! r: "Unfolded" value, positive or negative depending on the value of the input */ int16_t ivas_qmetadata_dereorder_generic( const uint16_t uns_value /* i : unsigned value result of ReorderGeneric */ ) @@ -234,7 +234,7 @@ void small_reduction_direction( * Input phi expected to be an angle in degree between 0 and 360. *-----------------------------------------------------------------------*/ -/* !r: index azimuth */ +/*! r: index azimuth */ int16_t quantize_phi( float phi, /* i : azimuth value */ const int16_t flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ @@ -401,7 +401,7 @@ float companding_azimuth( * Input phi expected to be an angle in degree between 0 and 360. *-----------------------------------------------------------------------*/ -/* !r: index azimuth */ +/*! r: index azimuth */ int16_t quantize_phi_chan_lbr( const float phi, /* i : azimuth value */ float *phi_hat, /* o : quantized azimuth */ @@ -445,7 +445,7 @@ int16_t quantize_phi_chan_lbr( * Input phi expected to be an angle in degree between 0 and 360. *-----------------------------------------------------------------------*/ -/* !r: index azimuth */ +/*! r: index azimuth */ int16_t quantize_phi_chan_compand( float phi, /* i : azimuth value */ float *phi_hat, /* o : quantized azimuth */ diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 7ed0ec4a827c377d327ecab4b4edad4de6a620d3..e0ccc3005b93e08c2c645fc2feebd632b82bb416 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -944,7 +944,7 @@ const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] = { 512000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 }, {118450, 118450, 128000 } }, // not yet optimized { { 31, 1, 1, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, -#ifdef SPAR_TUNING +#ifdef HODIRAC { 512000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 124000, 124000, 128000 },{ 124000, 124000, 128000 },{ 125200, 118450, 128000 },{ 76300, 73000, 128000 } }, // not yet optimized { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, @@ -1482,14 +1482,14 @@ const int16_t remix_order_set[1][IVAS_SPAR_MAX_CH] = { /* WYZX --> WYXZ... */ { 0, 1, 3, 2, 4, 5, 6, 7} }; #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t keep_planar[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS] = { 1, 1, 1, 1, 1, 1 }; #else const int16_t keep_planar[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS] = { 1, 1, 1, 1 }; #endif #ifdef HODIRAC const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15}; -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 10, 10, 10, 10}; const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; #else diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index f5e0c53e3a6b5414a0dca415caf2c9f3b6726c63..d0b153260b5412cc5688f0e18c93fc3f4ed4bfb1 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -222,7 +222,7 @@ int16_t ivas_sba_get_nchan( /*! r: number of ambisonics metadata channels */ int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order /* i : Ambisonic (SBA) order */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int32_t ivas_total_brate #endif @@ -236,7 +236,7 @@ int16_t ivas_sba_get_nchan_metadata( } else { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( ivas_total_brate >= IVAS_512k ) { nb_channels = ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ); @@ -261,7 +261,7 @@ int16_t ivas_sba_get_nchan_metadata( *-------------------------------------------------------------------*/ /*! r: flag indicating to code SPAR HOA MD for all bands */ -#ifdef SPAR_TUNING +#ifdef HODIRAC void ivas_sba_get_spar_hoa_ch_ind( const int16_t num_md_chs, /* i : number of MD channels */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 7ca2d417159fb59b38284516609240168f887111..73d8030651fd1d8b92bc1ac5e5733ab032981fe6 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -368,7 +368,7 @@ void ivas_spar_config( * Get SPAR table index *-----------------------------------------------------------------------------------------*/ -/* !r: config. table index */ +/*! r: config. table index */ int16_t ivas_get_spar_table_idx( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -1687,14 +1687,14 @@ void ivas_get_spar_md_from_dirac( remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; num_ch = ivas_sba_get_nchan_metadata( order -#ifdef SPAR_TUNING +#ifdef HODIRAC , IVAS_256k /*dummy value as order is always 1 in this function*/ #endif ); hoa2_ch = ivas_sba_get_nchan_metadata( SBA_HOA2_ORDER -#ifdef SPAR_TUNING +#ifdef HODIRAC , IVAS_256k /*dummy value as order is always 1 in this function*/ #endif diff --git a/lib_com/options.h b/lib_com/options.h old mode 100755 new mode 100644 index 6f7547635813c3274c3b1520ddce7e9868539340..09e65fa5abe4ca62f3b25b1698ff97724885160a --- a/lib_com/options.h +++ b/lib_com/options.h @@ -140,9 +140,6 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define NON_DIEGETIC_PAN /* Orange: Contribution 34: non diegetic panning in decoder */ #define ISM_NON_DIEGETIC_PAN /* Orange: Contribution 34: non diegetic panning for ism objects */ -#define FIX_103_RA_PARAMS_PARAM_BIN_REND /* Issue 103: Digest room acoustics parameters for Parametric Binaural Renderer*/ -/*#define SBA_HPF_TUNING_DEC*/ -#define SMOOTH_WITH_TRANS_DET #define FIX_331_ALL_BRS /*Enable the fix_331 across all the bitrates and sba modes*/ #define FIX_ISM_DTX_CNG_BWIDTH_ALT /* VA: issue 396 - alternative fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ @@ -164,10 +161,7 @@ #define FIX_419_ISM_BRATE_SW_DTX /* VA: issue 419: fix ISM Bitrate Switching with dtx */ #define FIX_422 /* FhG: Issue 422: re-introduce fix for noisy speech buffer in ParamISM */ - #define ERI_MSVQ_CLEANUP /* Eri: Contribution #31 BE modularization of msvq encoder side DCT21&DCT24 within msvq_enc() */ - - #define FIX_416_ISM_BR_SWITCHING /* FhG: add missing CLDFB reconfig to ISM BR switching */ #define FIX_SP2A /* VA: Issue 412: Adjust threshold for the S_p2a feature in the tonal detector */ @@ -182,7 +176,7 @@ #define FIX_425_MASA_BRSW_RENDERER /* Nokia: Issue 425: renderer not reconfigure in MASA bitrate switching */ #define EUALER2QUAT_FIX /* Dlb :fix for issue 430 issue in euler2quat, sign of quat y is inverted */ -#define HR_METADATA /* Nok: encode directional MASA metadata with more bits at 384k and 512k */ +#define HR_METADATA /* Nok: Contribution #45: encode directional MASA metadata with more bits at 384k and 512k */ #define SBA_TD_RESIDUAL /* Dlb : Issue 426: SBA encoder complexity optimization */ #define FIX_357_DTX_32K /* Eri: issue 357 - Forced LP-CNG at 32k */ @@ -196,27 +190,15 @@ #define FIX_440_PARAM_ISM_DIR_NOISE /* FhG: Issue 440: Fix directional background noise becoming diffuse in ParamISM */ #define LBR_SBA_DIRAC_FIX /* DLB: Bug fix for DirAC at low bitrates */ -#define FIX_445_SNS_BUGFIXES /* FhG: bug fix for spectral tilt in SNS computation + necessary update of codebooks and converison to fixedpoint-compatible tables */ +#define FIX_445_SNS_BUGFIXES /* FhG: bug fix for spectral tilt in SNS computation + necessary update of codebooks and converison to fixedpoint-compatible tables */ #define FIX_447_PARAMBIN_MASA_REGU_FAC /* Nokia: Issue 447: Fix issue by adjusting regularization factor minimum value. */ #define FIX_441_SBA_PARAMBIN_GAINS /* Nokia: Fix issue 441 by changing gains in SBA path of parametric binauralizer */ #define MC_PARAMUPMIX_MODE /* Dlb: Contribution 39: Multichannel Parametric Upmix */ +#define HODIRAC /* FhG: Contribution 32: Sector-based HO-DirAC method for SBA at high bitrates */ +#define DIRAC_ALLOC_HARM /* VA: harmonize DirAC parameters allocation/deallocation */ -#define HODIRAC /* FhG: Sector-based HO-DirAC method for SBA at high bitrates */ - -#ifdef HODIRAC -#define SPAR_TUNING /* Dlb: tune SPAR for better quality */ -#define HODIRAC_FIX_BR_SWITCHING_DTX -#endif - -/*#define HODIRAC_DEBUG*/ - -#ifdef HODIRAC_DEBUG -//#define HODIRAC_CHECK_VALUE_RANGE -//#define HODIRAC_WRITE_PARAMS -//#define HODIRAC_READ_PARAMS -#endif #define COMPLEXITY_LEVEL_INDICATION diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 62dab78ef5d7977c0a86c8a06c3c83c2730bf0aa..0af1699564180f2878a152d52d20f2829c56c816 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -344,7 +344,7 @@ ivas_error ivas_dec( { ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], st_ivas->sba_mode, #ifdef HODIRAC - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k, + ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ), #endif 0 ); } @@ -361,17 +361,12 @@ ivas_error ivas_dec( if ( st_ivas->hQMetaData != NULL ) { st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; - ivas_dirac_dec_read_BS( - ivas_total_brate, - st, - st_ivas->hDirAC, - st_ivas->hQMetaData, - &nb_bits_metadata[0], - st_ivas->sba_mode, + + ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], st_ivas->sba_mode, #ifdef HODIRAC - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k, + ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ), #endif - st_ivas->hSpar->dirac_to_spar_md_bands ); + st_ivas->hSpar->dirac_to_spar_md_bands ); } if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK ) @@ -439,7 +434,7 @@ ivas_error ivas_dec( } ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate ) #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index cb7c9f5b9afe00a869f2a6d93fcadef4e3caa299..c5485119ba67ad4b86a52602b732b5b63119e1fa 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -54,7 +54,7 @@ static ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem #ifdef HODIRAC , - int16_t hodirac + const int16_t hodirac_flag #endif ); @@ -71,7 +71,7 @@ static void protoSignalComputation1( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRA static void protoSignalComputation2( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, float *proto_direct_buffer_f, float *reference_power, float *proto_power_smooth, const int16_t isloudspeaker, const int16_t slot_index, const int16_t num_freq_bands, MASA_STEREO_TYPE_DETECT *stereo_type_detect ); static void protoSignalComputation4( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, float *proto_direct_buffer_f, float *reference_power, float *proto_power_smooth, const int16_t slot_index, const int16_t num_outputs_diff, const int16_t num_freq_bands, const float *mtx_hoa_decoder, const int16_t nchan_transport -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t *sba_map_tc_ind #endif @@ -113,6 +113,146 @@ ivas_error ivas_dirac_dec_open( } +#ifdef DIRAC_ALLOC_HARM +/*------------------------------------------------------------------------- + * ivas_dirac_allocate_parameters() + * + * Allocate and initialize DirAC parameters + *-------------------------------------------------------------------------*/ + +ivas_error ivas_dirac_allocate_parameters( + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + const int16_t params_flag /* i : set of parameters flag */ +) +{ + int16_t i; + + if ( params_flag == 1 ) + { + 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 ); + } + } + else if ( params_flag == 2 ) + { + if ( ( hDirAC->azimuth2 = (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->elevation2 = (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->energy_ratio2 = (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->spreadCoherence2 = (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->azimuth2[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->azimuth2[i], 0, hDirAC->num_freq_bands ); + + if ( ( hDirAC->elevation2[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->elevation2[i], 0, hDirAC->num_freq_bands ); + + if ( ( hDirAC->energy_ratio2[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_ratio2[i], 0.0f, hDirAC->num_freq_bands ); + + if ( ( hDirAC->spreadCoherence2[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->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands ); + } + } + + return IVAS_ERR_OK; +} +#endif + + /*------------------------------------------------------------------------- * ivas_dirac_dec_config() * @@ -140,6 +280,9 @@ ivas_error ivas_dirac_dec_config( int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_orig; +#ifdef HODIRAC + int16_t hodirac_flag; +#endif DIRAC_CONFIG_FLAG flag_config; flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; @@ -148,6 +291,9 @@ ivas_error ivas_dirac_dec_config( hDirAC = NULL; output_Fs = st_ivas->hDecoderConfig->output_Fs; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; +#ifdef HODIRAC + hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); +#endif if ( flag_config == DIRAC_RECONFIGURE ) @@ -187,7 +333,7 @@ ivas_error ivas_dirac_dec_config( if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR && !( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif @@ -288,24 +434,65 @@ ivas_error ivas_dirac_dec_config( { if ( st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k && hDirAC->azimuth2 == NULL ) { - hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); +#ifdef DIRAC_ALLOC_HARM + if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( hDirAC->azimuth2 = (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->elevation2 = (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->energy_ratio2 = (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->spreadCoherence2 = (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++ ) { - hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + if ( ( hDirAC->azimuth2[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->azimuth2[i], 0, hDirAC->num_freq_bands ); - hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + + if ( ( hDirAC->elevation2[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->elevation2[i], 0, hDirAC->num_freq_bands ); - hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->energy_ratio2[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_ratio2[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->spreadCoherence2[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->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands ); } +#endif } else if ( st_ivas->hDecoderConfig->ivas_total_brate <= IVAS_256k && hDirAC->azimuth2 != NULL ) { +#ifdef DIRAC_ALLOC_HARM + ivas_dirac_deallocate_parameters( hDirAC, 2 ); +#else for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { free( hDirAC->azimuth2[i] ); @@ -323,6 +510,7 @@ ivas_error ivas_dirac_dec_config( hDirAC->elevation2 = NULL; hDirAC->energy_ratio2 = NULL; hDirAC->spreadCoherence2 = NULL; +#endif } } #endif @@ -330,8 +518,7 @@ 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 HODIRAC - /*DLB : why is this needed ?*/ - && ivas_total_brate < IVAS_256k + && !hodirac_flag #endif ) { @@ -490,7 +677,7 @@ ivas_error ivas_dirac_dec_config( } set_s( hDirAC->proto_index_diff, 0, hDirAC->num_outputs_diff ); -#ifdef SPAR_TUNING +#ifdef HODIRAC hDirAC->sba_map_tc = sba_map_tc; if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) { @@ -606,7 +793,7 @@ ivas_error ivas_dirac_dec_config( for ( k = 0; k < min( hDirAC->num_outputs_dir, hDirAC->num_protos_dir ); k++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hDirAC->sba_map_tc[k] < hDirAC->num_outputs_dir ) { hDirAC->proto_index_dir[hDirAC->sba_map_tc[k]] = k; @@ -795,7 +982,7 @@ ivas_error ivas_dirac_dec_config( if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k + hodirac_flag #endif ) ) != IVAS_ERR_OK ) { @@ -810,7 +997,7 @@ ivas_error ivas_dirac_dec_config( if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k + hodirac_flag #endif ) ) != IVAS_ERR_OK ) { @@ -909,7 +1096,7 @@ ivas_error ivas_dirac_dec_config( ivas_dirac_dec_output_synthesis_init( hDirAC, nchan_out_woLFE #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k + hodirac_flag #endif ); @@ -921,7 +1108,7 @@ ivas_error ivas_dirac_dec_config( if ( ( error = ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ) #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k + hodirac_flag #endif ) ) != IVAS_ERR_OK ) { @@ -1001,6 +1188,12 @@ ivas_error ivas_dirac_dec_config( #endif } +#ifdef DIRAC_ALLOC_HARM + if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else 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" ) ); @@ -1069,6 +1262,7 @@ ivas_error ivas_dirac_dec_config( } set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); } +#endif if ( st_ivas->ivas_format == MASA_FORMAT #ifdef HODIRAC @@ -1076,6 +1270,12 @@ ivas_error ivas_dirac_dec_config( #endif ) { +#ifdef DIRAC_ALLOC_HARM + if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( hDirAC->azimuth2 = (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" ) ); @@ -1122,6 +1322,7 @@ ivas_error ivas_dirac_dec_config( } set_f( hDirAC->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands ); } +#endif } else { @@ -1145,7 +1346,9 @@ ivas_error ivas_dirac_dec_config( { if ( ( hDirAC->hConfig->dec_param_estim_old != hDirAC->hConfig->dec_param_estim ) ) { - +#ifdef DIRAC_ALLOC_HARM + ivas_dirac_deallocate_parameters( hDirAC, 1 ); +#else for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { if ( hDirAC->azimuth[i] != NULL ) @@ -1209,12 +1412,20 @@ ivas_error ivas_dirac_dec_config( free( hDirAC->surroundingCoherence ); hDirAC->surroundingCoherence = NULL; } +#endif } 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; hDirAC->dirac_read_idx = 0; hDirAC->dirac_estimator_idx = 0; + +#ifdef DIRAC_ALLOC_HARM + if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else 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" ) ); @@ -1282,6 +1493,7 @@ ivas_error ivas_dirac_dec_config( } set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); } +#endif } } #endif @@ -1415,6 +1627,10 @@ void ivas_dirac_dec_close( hDirAC->buffer_energy = NULL; } +#ifdef DIRAC_ALLOC_HARM + ivas_dirac_deallocate_parameters( hDirAC, 1 ); + ivas_dirac_deallocate_parameters( hDirAC, 2 ); +#else for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { if ( hDirAC->azimuth[i] != NULL ) @@ -1547,6 +1763,7 @@ void ivas_dirac_dec_close( free( hDirAC->surroundingCoherence ); hDirAC->surroundingCoherence = NULL; } +#endif if ( hDirAC->masa_stereo_type_detect != NULL ) { @@ -1563,6 +1780,173 @@ void ivas_dirac_dec_close( } +#ifdef DIRAC_ALLOC_HARM +/*------------------------------------------------------------------------- + * ivas_dirac_deallocate_parameters() + * + * Deallocate DirAC parameters + *-------------------------------------------------------------------------*/ + +void ivas_dirac_deallocate_parameters( + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + const int16_t params_flag /* i : set of parameters flag */ +) +{ + int16_t i; + + if ( params_flag == 1 ) + { + if ( hDirAC->azimuth != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->azimuth[i] != NULL ) + { + free( hDirAC->azimuth[i] ); + hDirAC->azimuth[i] = NULL; + } + } + + free( hDirAC->azimuth ); + hDirAC->azimuth = NULL; + } + + if ( hDirAC->elevation != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->elevation[i] != NULL ) + { + free( hDirAC->elevation[i] ); + hDirAC->elevation[i] = NULL; + } + } + + free( hDirAC->elevation ); + hDirAC->elevation = NULL; + } + + if ( hDirAC->energy_ratio1 != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->energy_ratio1[i] != NULL ) + { + free( hDirAC->energy_ratio1[i] ); + hDirAC->energy_ratio1[i] = NULL; + } + } + free( hDirAC->energy_ratio1 ); + hDirAC->energy_ratio1 = NULL; + } + + if ( hDirAC->diffuseness_vector != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->diffuseness_vector[i] != NULL ) + { + free( hDirAC->diffuseness_vector[i] ); + hDirAC->diffuseness_vector[i] = NULL; + } + } + + free( hDirAC->diffuseness_vector ); + hDirAC->diffuseness_vector = NULL; + } + + if ( hDirAC->spreadCoherence != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->spreadCoherence[i] != NULL ) + { + free( hDirAC->spreadCoherence[i] ); + hDirAC->spreadCoherence[i] = NULL; + } + } + free( hDirAC->spreadCoherence ); + hDirAC->spreadCoherence = NULL; + } + + if ( hDirAC->surroundingCoherence != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->surroundingCoherence[i] != NULL ) + { + free( hDirAC->surroundingCoherence[i] ); + hDirAC->surroundingCoherence[i] = NULL; + } + } + free( hDirAC->surroundingCoherence ); + hDirAC->surroundingCoherence = NULL; + } + } + else if ( params_flag == 2 ) + { + if ( hDirAC->azimuth2 != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->azimuth2[i] != NULL ) + { + free( hDirAC->azimuth2[i] ); + hDirAC->azimuth2[i] = NULL; + } + } + free( hDirAC->azimuth2 ); + hDirAC->azimuth2 = NULL; + } + + if ( hDirAC->elevation2 != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->elevation2[i] != NULL ) + { + free( hDirAC->elevation2[i] ); + hDirAC->elevation2[i] = NULL; + } + } + free( hDirAC->elevation2 ); + hDirAC->elevation2 = NULL; + } + + if ( hDirAC->energy_ratio2 != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->energy_ratio2[i] != NULL ) + { + free( hDirAC->energy_ratio2[i] ); + hDirAC->energy_ratio2[i] = NULL; + } + } + free( hDirAC->energy_ratio2 ); + hDirAC->energy_ratio2 = NULL; + } + + if ( hDirAC->spreadCoherence2 != NULL ) + { + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + { + if ( hDirAC->spreadCoherence2[i] != NULL ) + { + free( hDirAC->spreadCoherence2[i] ); + hDirAC->spreadCoherence2[i] = NULL; + } + } + free( hDirAC->spreadCoherence2 ); + hDirAC->spreadCoherence2 = NULL; + } + } + + return; +} +#endif + + /*------------------------------------------------------------------------- * ivas_dirac_alloc_mem() * @@ -1575,7 +1959,7 @@ static ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem #ifdef HODIRAC , - int16_t hodirac + const int16_t hodirac_flag #endif ) { @@ -1597,7 +1981,7 @@ static ivas_error ivas_dirac_alloc_mem( size = num_freq_bands * num_outputs_dir; #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { size_ho = size * DIRAC_HO_NUMSECTORS; size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS; @@ -1868,16 +2252,16 @@ static void ivas_dirac_free_mem( *------------------------------------------------------------------------*/ void ivas_dirac_dec_read_BS( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */ - int16_t *nb_bits, /* o : number of bits read */ - const SBA_MODE sba_mode, /* i : SBA mode */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + Decoder_State *st, /* i/o: decoder state structure */ + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */ + int16_t *nb_bits, /* o : number of bits read */ + const SBA_MODE sba_mode, /* i : SBA mode */ #ifdef HODIRAC - const int16_t hodirac, /* i : HO-Dirac flag */ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ #endif - int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ) { int16_t i, j, b, dir, orig_dirac_bands; @@ -1974,7 +2358,7 @@ void ivas_dirac_dec_read_BS( *nb_bits += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ) #ifdef HODIRAC , - hodirac + hodirac_flag #endif ); } @@ -2046,7 +2430,7 @@ void ivas_dirac_dec_read_BS( ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, ivas_total_brate, sba_mode #ifdef HODIRAC , - hodirac + hodirac_flag #endif , dirac_to_spar_md_bands ); @@ -2069,7 +2453,7 @@ void ivas_qmetadata_to_dirac( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const SBA_MODE sba_mode, /* i : SBA mode */ #ifdef HODIRAC - const int16_t hodirac, /* i : HO-DirAC flag*/ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ #endif int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ) @@ -2092,14 +2476,6 @@ void ivas_qmetadata_to_dirac( int16_t no_secs = 1; #endif -#ifdef HODIRAC_READ_PARAMS - static FILE *f_secparams = 0; - if ( f_secparams == 0 ) - { - f_secparams = fopen( "sector_params.txt", "r" ); - } -#endif - q_direction = &( hQMetaData->q_direction[0] ); hDirAC->numSimultaneousDirections = hQMetaData->no_directions; @@ -2235,38 +2611,6 @@ void ivas_qmetadata_to_dirac( } } -#ifdef HODIRAC_READ_PARAMS - /* popular sector parameters from file */ - int16_t idx_f; - int idx_f_f, idx_sec_f; - float azi_secs[4][4][DIRAC_MAX_NBANDS], ele_secs[4][4][DIRAC_MAX_NBANDS], ene_secs[4][4][DIRAC_MAX_NBANDS], diff_secs[4][4][DIRAC_MAX_NBANDS], diff[4][DIRAC_MAX_NBANDS]; - assert( hDirAC->nb_subframes <= 4 ); - for ( block = 0; block < hDirAC->nb_subframes; block++ ) - { - int16_t block_qmetadata; - - block_qmetadata = min( block, nblocks - 1 ); - block_qmetadata = max( block_qmetadata, 0 ); - - assert( block_qmetadata == block ); // does this ever happen? - for ( idx_f = 0; idx_f < nbands; idx_f++ ) - { - for ( idx_sec = 0; idx_sec < 4; idx_sec++ ) - { - if ( 7 != fscanf( f_secparams, "%i %i %f %f %f %f %f\n", &idx_f_f, &idx_sec_f, &azi_secs[block_qmetadata][idx_sec][idx_f], &ele_secs[block_qmetadata][idx_sec][idx_f], &ene_secs[block_qmetadata][idx_sec][idx_f], &diff_secs[block_qmetadata][idx_sec][idx_f], &diff[block_qmetadata][idx_f] ) ) - { - printf( "ERROR reading parameters!\n" ); - exit( -1 ); - } - if ( azi_secs[block_qmetadata][idx_sec][idx_f] < 0.f ) - { - azi_secs[block_qmetadata][idx_sec][idx_f] += 360.f; - } - } - } - } -#endif - /* Low-Bands with no spatial data transmitted, analysis at decoder side */ for ( band = 0; band < start_band; band++ ) { @@ -2324,10 +2668,11 @@ void ivas_qmetadata_to_dirac( /* Bands with spatial data transmitted */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { no_secs = DIRAC_HO_NUMSECTORS; } + for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ ) #endif { @@ -2377,9 +2722,8 @@ void ivas_qmetadata_to_dirac( } #endif - #ifdef HODIRAC - if ( hMasa == NULL && hodirac ) + if ( hMasa == NULL && hodirac_flag ) { azimuth = q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata]; elevation = q_direction[idx_sec].band_data[qBand_idx].elevation[block_qmetadata]; @@ -2394,28 +2738,12 @@ void ivas_qmetadata_to_dirac( elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata]; } -#ifdef HODIRAC_READ_PARAMS - int16_t tmp_i; - tmp_i = 0; - ( idx_sec == 0 ) ? ( tmp_i = 1 ) : ( ( idx_sec == 1 ) ? ( tmp_i = 2 ) : ( tmp_i = -99 ) ); - assert( tmp_i < 3 ); - azimuth = azi_secs[block_qmetadata][tmp_i][qBand_idx]; - elevation = ele_secs[block_qmetadata][tmp_i][qBand_idx]; - diffuseness = diff[block_qmetadata][qBand_idx]; - - if ( azimuth < 0.f ) - { - azimuth += 360.f; - } - diffuseness_sec = 1.f - ( diff_secs[block_qmetadata][1][qBand_idx] / ( diff_secs[block_qmetadata][1][qBand_idx] + diff_secs[block_qmetadata][2][qBand_idx] + EPSILON ) ); -#endif - for ( b = band_start; b < band_end; b++ ) { tmp_write_idx_band = tmp_write_idx_param_band; #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { azi = (int16_t) ( azimuth + 0.5f ); ele = (int16_t) ( elevation + 0.5f ); @@ -2457,7 +2785,7 @@ void ivas_qmetadata_to_dirac( hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness; #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { if ( idx_sec == 0 ) { @@ -2546,38 +2874,6 @@ void ivas_qmetadata_to_dirac( } } -#ifdef HODIRAC_WRITE_PARAMS - if ( hMasa == NULL && sba_analysis_order > 1 && ivas_total_brate > IVAS_256k ) - { - static FILE *f_params = 0; - int16_t tmp_write_idx_band = 0; - - if ( f_params == 0 ) - f_params = fopen( "param_dec", "w" ); - - tmp_write_idx_band = hDirAC->dirac_bs_md_write_idx; - for ( block = 0; block < hDirAC->nb_subframes; block++ ) - { - int16_t block_qmetadata; - - block_qmetadata = min( block, nblocks - 1 ); - block_qmetadata = max( block_qmetadata, 0 ); - - for ( band = 0; band < hDirAC->num_freq_bands; band++ ) - { - fprintf( f_params, "%d ", hDirAC->azimuth[tmp_write_idx_band][band] ); - fprintf( f_params, "%d ", hDirAC->elevation[tmp_write_idx_band][band] ); - fprintf( f_params, "%f ", hDirAC->diffuseness_vector[tmp_write_idx_band][band] ); - - fprintf( f_params, "%d ", hDirAC->azimuth2[tmp_write_idx_band][band] ); - fprintf( f_params, "%d ", hDirAC->elevation2[tmp_write_idx_band][band] ); - fprintf( f_params, "%f\n", 1.0f - hDirAC->energy_ratio2[tmp_write_idx_band][band] ); - } - tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length; - } - } -#endif - /* update buffer write index */ if ( hDirAC->hConfig->dec_param_estim == FALSE ) { @@ -2819,6 +3115,9 @@ void ivas_dirac_dec_render_sf( int16_t sf1, sf2; #endif int16_t slot_idx, index_slot; +#ifdef HODIRAC + int16_t hodirac_flag; +#endif float *p_Rmat; #ifdef JBM_TSM_ON_TCS int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; @@ -2859,6 +3158,10 @@ void ivas_dirac_dec_render_sf( onset_filter = DirAC_mem.onset_filter; onset_filter_subframe = DirAC_mem.onset_filter + hDirAC->num_freq_bands; +#ifdef HODIRAC + hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); +#endif + if ( st_ivas->hQMetaData != NULL && st_ivas->sba_mode != SBA_MODE_SPAR ) { coherence_flag = st_ivas->hQMetaData->coherence_flag; @@ -3102,7 +3405,7 @@ void ivas_dirac_dec_render_sf( p_Rmat #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k + hodirac_flag #endif ); } @@ -3121,7 +3424,7 @@ void ivas_dirac_dec_render_sf( NULL #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k + hodirac_flag #endif ); } @@ -3162,7 +3465,7 @@ void ivas_dirac_dec_render_sf( for ( ch = 0; ch < nchan_transport; ch++ ) { #ifdef JBM_TSM_ON_TCS -#ifdef SPAR_TUNING +#ifdef HODIRAC cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirAC->sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ), Cldfb_RealBuffer[ch][0], Cldfb_ImagBuffer[ch][0], @@ -3176,7 +3479,7 @@ void ivas_dirac_dec_render_sf( st_ivas->cldfbAnaDec[ch] ); #endif #else -#ifdef SPAR_TUNING +#ifdef HODIRAC cldfbAnalysis_ts( &( output_f[hDirAC->sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ), Cldfb_RealBuffer[ch][0], Cldfb_ImagBuffer[ch][0], @@ -3281,7 +3584,7 @@ void ivas_dirac_dec_render_sf( hDirAC->num_freq_bands, hDirAC->hoa_decoder, nchan_transport -#ifdef SPAR_TUNING +#ifdef HODIRAC , hDirAC->sba_map_tc #endif @@ -3539,8 +3842,7 @@ void ivas_dirac_dec_render_sf( nchan_transport, md_idx, #ifdef HODIRAC - st_ivas->sba_analysis_order > 1 && - st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k + hodirac_flag #endif ); @@ -3560,8 +3862,7 @@ void ivas_dirac_dec_render_sf( nchan_transport, md_idx, #ifdef HODIRAC - st_ivas->sba_analysis_order > 1 && - st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k + hodirac_flag #endif ); } @@ -3640,7 +3941,7 @@ void ivas_dirac_dec_render_sf( #ifdef JBM_TSM_ON_TCS md_idx, #endif - st_ivas->sba_analysis_order > 1 && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k + hodirac_flag #endif ); } @@ -4595,7 +4896,7 @@ static void protoSignalComputation4( const int16_t num_freq_bands, const float *mtx_hoa_decoder, const int16_t nchan_transport -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t *sba_map_tc_ind #endif @@ -4625,7 +4926,7 @@ static void protoSignalComputation4( proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; for ( n = 0; n < nchan_transport; n++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; #else diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c old mode 100644 new mode 100755 index a7bb8e504d67758f2111602c107bf46ffcae078e..f88b5f5f3ab0b8bc463a9e479d5d583fc0e82567 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -87,13 +87,13 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha *------------------------------------------------------------------------*/ ivas_error ivas_dirac_dec_output_synthesis_open( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - RENDERER_TYPE renderer_type, /* i : renderer type */ - const int16_t nchan_transport, /* i : number of transport channels*/ - const int32_t output_Fs /* i : output sampling rate */ + DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ + RENDERER_TYPE renderer_type, /* i : renderer type */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs /* i : output sampling rate */ #ifdef HODIRAC , - const int16_t hodirac /* i : flag to indicate HO-DirAC mode*/ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { @@ -179,7 +179,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open( /* target PSD buffers */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS; } @@ -389,7 +389,7 @@ void ivas_dirac_dec_output_synthesis_init( const int16_t nchan_out_woLFE /* i : number of output audio channels without LFE */ #ifdef HODIRAC , - const int16_t hodirac /* flag to indicate HO-DirAC mode */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { @@ -414,7 +414,7 @@ void ivas_dirac_dec_output_synthesis_init( } #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS; } @@ -426,6 +426,7 @@ void ivas_dirac_dec_output_synthesis_init( #else set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir ); #endif + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff ); @@ -596,7 +597,7 @@ void ivas_dirac_dec_output_synthesis_process_slot( #endif #ifdef HODIRAC , - const int16_t hodirac + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { @@ -635,7 +636,7 @@ void ivas_dirac_dec_output_synthesis_process_slot( } #ifdef HODIRAC - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD && hodirac ) + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD && hodirac_flag ) { ivas_dirac_dec_compute_directional_responses( hDirAC, hVBAPdata, @@ -648,9 +649,10 @@ void ivas_dirac_dec_output_synthesis_process_slot( NULL, 2, p_Rmat, - hodirac ); + hodirac_flag ); } - if ( hDirAC->hConfig->dec_param_estim == FALSE && hodirac ) + + if ( hDirAC->hConfig->dec_param_estim == FALSE && hodirac_flag ) { if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { @@ -727,19 +729,7 @@ void ivas_dirac_dec_output_synthesis_process_slot( p_Rmat #ifdef HODIRAC , - hodirac /* i : flag for sector based dirac processing */ -#endif - ); -#else - ivas_dirac_dec_compute_directional_responses( hDirAC, - hVBAPdata, - NULL, - NULL, - 2, - p_Rmat -#ifdef HODIRAC - , - 0 + hodirac_flag #endif ); #endif @@ -888,7 +878,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( #ifdef JBM_TSM_ON_TCS const int16_t md_idx, #endif - const int16_t hodirac /* i: flag for sector-based processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { @@ -909,7 +899,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( DIRAC_OUTPUT_SYNTHESIS_STATE h_dirac_output_synthesis_state; int16_t nchan_transport_foa; int16_t ch_idx_diff; - #ifdef HODIRAC float aux_buf[CLDFB_NO_CHANNELS_MAX]; float ratio[DIRAC_HO_NUMSECTORS * CLDFB_NO_CHANNELS_MAX]; @@ -941,7 +930,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( *-----------------------------------------------------------------*/ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { assert( hDirAC->hConfig->dec_param_estim == FALSE ); /*Direct gain*/ @@ -1042,9 +1031,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( p_cy_cross_dir_smooth = h_dirac_output_synthesis_state.cy_cross_dir_smooth; p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev; -/*Direct gains*/ + /* Direct gains */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { for ( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { @@ -1089,10 +1078,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( *( p_gains_dir++ ) = g2; } } + #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { - // wkr: additional gains for second sector, hard coded to two sectors p_cy_cross_dir_smooth = h_dirac_output_synthesis_state.cy_cross_dir_smooth + num_freq_bands * num_channels_dir; p_gains_dir = h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev + num_freq_bands * num_channels_dir; @@ -1122,7 +1111,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( } #endif - /*Diffuse gains*/ p_cy_auto_diff_smooth = h_dirac_output_synthesis_state.cy_auto_diff_smooth + nchan_transport_foa * num_freq_bands_diff; p_gains_diff = h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev + nchan_transport_foa * num_freq_bands_diff; @@ -1170,7 +1158,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( for ( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) { #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { if ( proto_direct_index[ch_idx] == 0 ) { @@ -1256,7 +1244,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( for ( l = 0; l < num_freq_bands_diff; l++ ) { g = g1 * ( *( p_gains_diff++ ) ) + g2 * ( *( p_gains_diff_prev++ ) ); -#ifdef SPAR_TUNING +#ifdef HODIRAC output_real[l * num_channels_dir + hDirAC->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); /* maps ch_idx 5 to 8 */ output_imag[l * num_channels_dir + hDirAC->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); #else @@ -1321,13 +1309,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( } } -/*-----------------------------------------------------------------* - * update buffers - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * update buffers + *-----------------------------------------------------------------*/ -/* store estimates for next synthesis block */ + /* store estimates for next synthesis block */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { mvr2r( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev, num_freq_bands * num_channels_dir * DIRAC_HO_NUMSECTORS ); } @@ -1339,9 +1327,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( mvr2r( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev, num_freq_bands_diff * num_channels_diff ); -/* reset values */ + /* reset values */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { set_zero( h_dirac_output_synthesis_state.cy_cross_dir_smooth, num_freq_bands * num_channels_dir * DIRAC_HO_NUMSECTORS ); } @@ -1351,7 +1339,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( set_zero( h_dirac_output_synthesis_state.cy_cross_dir_smooth, num_freq_bands * num_channels_dir ); } - set_zero( h_dirac_output_synthesis_state.cy_auto_diff_smooth, num_freq_bands_diff * num_channels_diff ); return; @@ -1904,7 +1891,7 @@ void ivas_dirac_dec_compute_directional_responses( const float *p_Rmat /* i : rotation matrix */ #ifdef HODIRAC , - const int16_t hodirac /* i : flag for sector based dirac processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { @@ -1987,10 +1974,12 @@ void ivas_dirac_dec_compute_directional_responses( #ifdef HODIRAC set_f( direct_response_hoa, 1.0f, MAX_OUTPUT_CHANNELS ); set_f( direct_response_dir2, 1.0f, MAX_OUTPUT_CHANNELS ); + if ( p_Rmat != 0 ) { ivas_dirac_dec_get_response_split_order( azimuth[k], elevation[k], direct_response_hoa, shd_rot_max_order, p_Rmat ); - if ( hodirac ) + + if ( hodirac_flag ) { ivas_dirac_dec_get_response_split_order( azimuth2[k], elevation2[k], direct_response_dir2, shd_rot_max_order, p_Rmat ); } @@ -1998,7 +1987,8 @@ void ivas_dirac_dec_compute_directional_responses( else { ivas_dirac_dec_get_response( azimuth[k], elevation[k], direct_response_hoa, hDirAC->hOutSetup.ambisonics_order ); - if ( hodirac ) + + if ( hodirac_flag ) { ivas_dirac_dec_get_response( azimuth2[k], elevation2[k], direct_response_dir2, hDirAC->hOutSetup.ambisonics_order ); } @@ -2007,7 +1997,8 @@ void ivas_dirac_dec_compute_directional_responses( if ( hMasa == NULL && hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { mvr2r_inc( direct_response_hoa, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir ); - if ( hodirac ) + + if ( hodirac_flag ) { mvr2r_inc( direct_response_dir2, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k + hDirAC->num_freq_bands * num_channels_dir], hDirAC->num_freq_bands, num_channels_dir ); } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 26895a5d1f5094b4a1f1956c15144a4e7045b682..ef9cbdf54bf9fe4e1237807f4f65175111bac9e3 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -944,7 +944,7 @@ ivas_error ivas_init_decoder( st_ivas->sba_analysis_order, st_ivas->sba_mode, #ifdef HODIRAC - st_ivas->sba_analysis_order > 1 && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) + ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) #else IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND #endif @@ -972,7 +972,7 @@ ivas_error ivas_init_decoder( st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); #ifdef HODIRAC - if ( st_ivas->sba_analysis_order > 1 && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k ) + if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index d58887f2da3f5c94448a97e47b1295dbea144bcb..7e0f65a66332762e561897da24c43a907acd446a 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -689,6 +689,17 @@ ivas_error ivas_param_ism_dec_open( #ifndef JBM_TSM_ON_TCS hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; #endif +#ifdef DIRAC_ALLOC_HARM + if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else 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 Param ISM Rendering handle\n" ) ); @@ -790,6 +801,7 @@ ivas_error ivas_param_ism_dec_open( } set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); } +#endif } st_ivas->hISMDTX.dtx_flag = 0; @@ -860,7 +872,9 @@ void ivas_param_ism_dec_close( AUDIO_CONFIG output_config /* i : output audio configuration */ ) { +#ifndef DIRAC_ALLOC_HARM int16_t i; +#endif DIRAC_DEC_HANDLE hDirAC; if ( hDirAC_out == NULL || *hDirAC_out == NULL ) @@ -879,6 +893,10 @@ void ivas_param_ism_dec_close( if ( ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) { +#ifdef DIRAC_ALLOC_HARM + ivas_dirac_deallocate_parameters( hDirAC, 1 ); + ivas_dirac_deallocate_parameters( hDirAC, 2 ); +#else for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { if ( hDirAC->azimuth[i] != NULL ) @@ -1002,6 +1020,7 @@ void ivas_param_ism_dec_close( free( hDirAC->surroundingCoherence ); hDirAC->surroundingCoherence = NULL; } +#endif } if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 13a062fd9312a68e0d2b27d22c07c5a2f7a180e5..f33a5e01e6cf6a459ddd4b88f9df85127c80a776 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -276,7 +276,7 @@ ivas_error ivas_jbm_dec_tc( } ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate ) #endif diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index e69cedc6a2f2e5ff24a6631f7297b20d50720d8a..2c9fcbd008e0b289dd3359a479835ad9ab9eb4f8 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -47,9 +47,11 @@ /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ + #define SPAR_META_DELAY_SUBFRAMES 2 /* Number of subframes to delay the SPAR metadata */ #define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */ + /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ @@ -58,7 +60,9 @@ static int16_t quantize_theta( float x, int16_t no_cb, float *xhat ); static uint16_t index_theta_phi_16( float theta, float phi, SPHERICAL_GRID_DATA *Sph_Grid16 ); static int16_t quantize_phi_masa( float phi, int16_t flag_delta, float *phi_hat, const int16_t n ); #endif + static void index_16bits( IVAS_QMETADATA_HANDLE hQMetaData, SPHERICAL_GRID_DATA *Sph_Grid16 ); + static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, const int16_t nchan_transport ); static void replicate_subframes( IVAS_QMETADATA_HANDLE hQMetaData ); @@ -216,6 +220,7 @@ ivas_error ivas_masa_decode( #ifdef HR_METADATA } #endif + /* Get direction decoding quality. EC 1 and 2 are handled by the default value. */ if ( hQMetaData->ec_flag == 2 ) { diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index 02cab10026fdc8f41722b058b4429401e0287f8c..4092142a9a1b9b5606c9723e325bd70edcbefdf2 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -153,7 +153,7 @@ void ivas_renderer_select( { nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 3774c06799e017a6eec0b32e61abefbe6717bdbd..5480f73a33538aefb9ee7974e07342b04bccc430 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -52,14 +52,14 @@ static int16_t ivas_qmetadata_entropy_decode_df_ratio( uint16_t *bitstream, int1 static int16_t ivas_qmetadata_entropy_decode_dir( IVAS_QDIRECTION *q_direction, uint16_t *bitstream, int16_t *index, const uint16_t diffuseness_index_max_ec_frame, const int16_t nbands, const int16_t start_band #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); static int16_t ivas_qmetadata_raw_decode_dir( IVAS_QDIRECTION *q_direction, uint16_t *bitstream, int16_t *index, const int16_t nbands, const int16_t start_band #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); @@ -90,7 +90,7 @@ static ivas_error read_huf( int16_t *num_bits_read, const uint16_t *bitstream, u static int16_t read_coherence_data( uint16_t *bitstream, int16_t *p_bit_pos, IVAS_QMETADATA *hQMetaData, const int16_t idx_dir #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); @@ -99,7 +99,7 @@ static int16_t read_surround_coherence( uint16_t *bitstream, int16_t *p_bit_pos, static void decode_spread_coherence( IVAS_QMETADATA_HANDLE hQMetaData, int16_t idx_d, const int16_t no_frames #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); @@ -112,43 +112,18 @@ static int16_t read_GR_min_removed_data( uint16_t *bitstream, int16_t *p_bit_pos static int16_t decode_fixed_rate_composed_index_coherence( uint16_t *bitstream, int16_t *p_bit_pos, const int16_t no_bands, int16_t *no_cv_vec, uint16_t *decoded_index, const int16_t no_symb ); #ifdef HR_METADATA +static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr( uint16_t *bitstream, int16_t *index, IVAS_QDIRECTION *q_direction, uint16_t *diffuseness_index_max_ec_frame ); -static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr( - uint16_t *bitstream, /* i : bitstream */ - int16_t *index, - IVAS_QDIRECTION *q_direction, - uint16_t *diffuseness_index_max_ec_frame ); - - -static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( - uint16_t *bitstream, /* i : bitstream */ - int16_t *index, - IVAS_QDIRECTION *q_direction ); +static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( uint16_t *bitstream, int16_t *index, IVAS_QDIRECTION *q_direction ); -static int16_t ivas_qmetadata_raw_decode_dir_512( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - uint16_t *bitstream, /* i : bitstream */ - int16_t *index, - const int16_t nbands, - const int16_t start_band, - SPHERICAL_GRID_DATA *sph_grid16 /* i: spherical grid for deindexing */ -); -static int16_t read_surround_coherence_hr( - uint16_t *bitstream, /* i : bitstream */ - int16_t *p_bit_pos, /* i : position in the bitstream */ - IVAS_QMETADATA *hQMetaData /* i/o: quantized metadata structure */ -); +static int16_t ivas_qmetadata_raw_decode_dir_512( IVAS_QDIRECTION *q_direction, uint16_t *bitstream, int16_t *index, const int16_t nbands, const int16_t start_band, const SPHERICAL_GRID_DATA *sph_grid16 ); -/* !r: number of bits read */ -static int16_t read_coherence_data_hr_512( - uint16_t *bitstream, /* i : bitstream */ - int16_t *p_bit_pos, /* i : position in the bitstream */ - IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const int16_t idx_dir, /* i : direction index */ - int16_t nbits_coh ); +static int16_t read_surround_coherence_hr( uint16_t *bitstream, int16_t *p_bit_pos, IVAS_QMETADATA *hQMetaData ); +static int16_t read_coherence_data_hr_512( uint16_t *bitstream, int16_t *p_bit_pos, IVAS_QMETADATA *hQMetaData, const int16_t idx_dir, const int16_t nbits_coh ); #endif + /*-----------------------------------------------------------------------* * Global function definitions *-----------------------------------------------------------------------*/ @@ -159,15 +134,14 @@ static int16_t read_coherence_data_hr_512( * Main function for decoding Spatial Metadata *-----------------------------------------------------------------------*/ - /*! r: number of bits read */ int16_t ivas_qmetadata_dec_decode( - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - uint16_t *bitstream, /* i : bitstream */ - int16_t *index /* i/o: bitstream position */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ + uint16_t *bitstream, /* i : bitstream */ + int16_t *index /* i/o: bitstream position */ #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ #endif ) { @@ -198,7 +172,6 @@ int16_t ivas_qmetadata_dec_decode( int16_t reduce_bits; int16_t ind_order[MASA_MAXIMUM_CODING_SUBBANDS]; - #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; static FILE *pF_azi = NULL; @@ -255,11 +228,10 @@ int16_t ivas_qmetadata_dec_decode( } bits_diff_sum = 0; - bits_diff_sum += ivas_qmetadata_entropy_decode_diffuseness( bitstream, index, &( hQMetaData->q_direction[0] ), &diffuseness_index_max_ec_frame_pre[0] ); #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { if ( hQMetaData->no_directions == 2 ) { @@ -311,8 +283,8 @@ int16_t ivas_qmetadata_dec_decode( diffRatio = diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; dfRatio_qsteps = 1 << dfRatio_bits[dir2band]; #ifdef HODIRAC - /* already encoded as total and ratios in HODIRAC*/ - if ( hodirac ) + /* already encoded as total and ratios in HO-DirAC */ + if ( hodirac_flag ) { dfRatio = usdequant( hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0], 0.0f, 1.f / ( dfRatio_qsteps - 1 ) ); dir1ratio = 1.f - diffRatio; @@ -331,7 +303,7 @@ int16_t ivas_qmetadata_dec_decode( /* Requantize the 1 - dirRatio separately for each direction to obtain inverted dirRatio index. These are used in further decoding. */ hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq( 1.0f - dir1ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { float tmp; hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant( dir2ratio, &tmp, 0.0f, 1.f / ( DIRAC_DIFFUSE_LEVELS - 1 ), DIRAC_DIFFUSE_LEVELS ); @@ -399,7 +371,7 @@ int16_t ivas_qmetadata_dec_decode( masa_compensate_two_dir_energy_ratio_index( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod #ifdef HODIRAC , - hodirac + hodirac_flag #endif ); @@ -741,6 +713,7 @@ int16_t ivas_qmetadata_dec_decode( } #endif } + /* move 2 dir data to its correct subband */ if ( hQMetaData->no_directions == 2 ) { @@ -792,7 +765,7 @@ int16_t ivas_qmetadata_dec_decode( /* Scale energy ratios that sum to over one */ #ifdef HODIRAC - if ( !hodirac ) + if ( !hodirac_flag ) #endif { for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) @@ -820,24 +793,27 @@ int16_t ivas_qmetadata_dec_decode( hQMetaData->dir_comp_ratio = 1.0f; } - return ( start_index_0 - *index ); } #ifdef HR_METADATA +/*-----------------------------------------------------------------------* + * ivas_qmetadata_dec_decode_hr_384_512() + * + * Main function for decoding Spatial Metadata at HRs + *-----------------------------------------------------------------------*/ /*! r: number of bits read */ int16_t ivas_qmetadata_dec_decode_hr_384_512( - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - uint16_t *bitstream, /* i : bitstream */ - int16_t *index, /* i/o: bitstream position */ - SPHERICAL_GRID_DATA *sph_grid16, /* i: spherical grid for deindexing */ - int16_t bits_sph_idx, - int16_t bits_sp_coh ) + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ + uint16_t *bitstream, /* i : bitstream */ + int16_t *index, /* i/o: bitstream position */ + const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */ + const int16_t bits_sph_idx, + const int16_t bits_sp_coh ) { int16_t d, b, m; - int16_t bits_diff_sum; int16_t nbands, start_band; IVAS_QDIRECTION *q_direction; @@ -956,7 +932,6 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( } } - if ( all_coherence_zero == 0 ) { bits_sur_coherence = read_surround_coherence_hr( bitstream, index, hQMetaData ); @@ -975,14 +950,12 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( } bits_no_dirs_coh += bits_sur_coherence; - for ( d = 0; d < hQMetaData->no_directions; d++ ) { q_direction = &hQMetaData->q_direction[d]; nbands = q_direction->cfg.nbands; start_band = q_direction->cfg.start_band; - /* Read coherence, if any */ if ( all_coherence_zero == 0 ) { @@ -1005,11 +978,9 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( } } - /* Decode quantized directions frame-wise */ ivas_qmetadata_raw_decode_dir_512( q_direction, bitstream, index, nbands, start_band, sph_grid16 ); - #ifdef DEBUG_MODE_QMETADATA fprintf( pF, "frame %d: diff %d surcoh %d ", frame, bits_diff_sum, bits_sur_coherence ); @@ -1019,7 +990,6 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( fprintf( pF_spcoh, "frame %d/dir %d: ", frame, d ); fprintf( pF_ratio, "frame %d/dir %d: ", frame, d ); - for ( b = start_band; b < nbands; b++ ) { for ( m = 0; m < q_direction->cfg.nblocks; m++ ) @@ -1079,6 +1049,7 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( } } } + /* Scale energy ratios that sum to over one */ for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { @@ -1096,7 +1067,6 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( } } - #ifdef DEBUG_MODE_QMETADATA for ( d = 0; d < hQMetaData->no_directions; d++ ) { @@ -1139,7 +1109,6 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( hQMetaData->dir_comp_ratio = 1.0f; } - return ( start_index_0 - *index ); } @@ -1412,6 +1381,12 @@ static int16_t ivas_diffuseness_huff_ec_decode( } +/*-------------------------------------------------------------------* + * ivas_qmetadata_entropy_decode_diffuseness() + * + * + *-------------------------------------------------------------------*/ + static int16_t ivas_qmetadata_entropy_decode_diffuseness( uint16_t *bitstream, /* i : bitstream */ int16_t *index, @@ -1509,6 +1484,12 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness( #ifdef HR_METADATA +/*-------------------------------------------------------------------* + * ivas_qmetadata_entropy_decode_diffuseness_hr() + * + * + *-------------------------------------------------------------------*/ + static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr( uint16_t *bitstream, /* i : bitstream */ int16_t *index, @@ -1583,6 +1564,13 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr( return ( index_start - *index ); } + +/*-------------------------------------------------------------------* + * ivas_qmetadata_entropy_decode_diffuseness_hr_512() + * + * + *-------------------------------------------------------------------*/ + static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( uint16_t *bitstream, /* i : bitstream */ int16_t *index, @@ -1612,7 +1600,6 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( return MASA_BITS_ER_HR; } - for ( b = start_band; b < nbands; b++ ) { for ( k = 0; k < nblocks; k++ ) @@ -1625,6 +1612,13 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( } #endif + +/*-------------------------------------------------------------------* + * ivas_qmetadata_entropy_decode_df_ratio() + * + * + *-------------------------------------------------------------------*/ + static int16_t ivas_qmetadata_entropy_decode_df_ratio( uint16_t *bitstream, int16_t *index, @@ -1753,7 +1747,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( const int16_t start_band #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ #endif ) { @@ -1783,7 +1777,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( for ( b = start_band; b < nbands; b++ ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { diff_idx = 0; } @@ -1794,6 +1788,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( #ifdef HR_METADATA } #endif + diff_idx_min = min( diff_idx_min, diff_idx ); if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) { @@ -1803,6 +1798,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( { elev_alph[b] = no_theta_masa[bits_direction_masa[diff_idx] - 3] * 2 - 1; } + #ifdef HR_METADATA if ( q_direction->band_data[b].energy_ratio_index_mod[0] > diffuseness_index_max_ec_frame ) #else @@ -1861,7 +1857,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( { int16_t tmp_index; #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { diff_idx = 0; } @@ -1880,6 +1876,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( else { avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + /*reorder elevation indexing*/ tmp_index = avg_elevation_index_projected - ( elev_alph[b] >> 1 ); if ( tmp_index < 0 ) @@ -1896,6 +1893,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( for ( m = 0; m < nblocks; m++ ) { q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; + /*deduce aplhabet for azimuth*/ if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) { @@ -1920,18 +1918,18 @@ static int16_t ivas_qmetadata_entropy_decode_dir( if ( bands_entropic[b] ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { diff_idx = 0; } else { - #endif diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; #ifdef HR_METADATA } #endif + for ( m = 0; m < nblocks; m++ ) { int16_t tmp_index; @@ -1954,7 +1952,6 @@ static int16_t ivas_qmetadata_entropy_decode_dir( } else { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); @@ -1991,18 +1988,18 @@ static int16_t ivas_qmetadata_entropy_decode_dir( if ( bands_entropic[b] ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { diff_idx = 0; } else { - #endif diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; #ifdef HR_METADATA } #endif + for ( m = 0; m < nblocks; m++ ) { q_direction->band_data[b].elevation_index[m] = 0; @@ -2062,6 +2059,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( set_zero( avg_direction_vector, 3 ); use_adapt_avg = 0; idx = 0; + for ( b = start_band; b < nbands; b++ ) { if ( bands_entropic[b] ) @@ -2120,6 +2118,7 @@ static int16_t ivas_qmetadata_entropy_decode_dir( return ( index_start - *index ); } + #ifdef HR_METADATA /*------------------------------------------------------------------------- * ivas_qmetadata_raw_decode_dir() @@ -2133,7 +2132,7 @@ static int16_t ivas_qmetadata_raw_decode_dir_512( int16_t *index, const int16_t nbands, const int16_t start_band, - SPHERICAL_GRID_DATA *sph_grid16 /* i: spherical grid for deindexing */ + const SPHERICAL_GRID_DATA *sph_grid16 /* i : spherical grid for deindexing */ ) { int16_t b, m, i; @@ -2154,6 +2153,7 @@ static int16_t ivas_qmetadata_raw_decode_dir_512( value = ( value << 1 ) + bitstream[( *index )--]; } q_direction->band_data[b].spherical_index[m] = value; + if ( q_direction->band_data[b].bits_sph_idx[m] == 16 ) { deindex_sph_idx( value, sph_grid16, &( q_direction->band_data[b].elevation[m] ), &( q_direction->band_data[b].azimuth[m] ) ); @@ -2167,11 +2167,11 @@ static int16_t ivas_qmetadata_raw_decode_dir_512( } } - return ( index_start - *index ); } #endif + /*------------------------------------------------------------------------- * ivas_qmetadata_raw_decode_dir() * @@ -2186,7 +2186,7 @@ static int16_t ivas_qmetadata_raw_decode_dir( const int16_t start_band #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ #endif ) { @@ -2207,7 +2207,7 @@ static int16_t ivas_qmetadata_raw_decode_dir( else { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { diff_idx = 0; } @@ -2241,7 +2241,7 @@ static int16_t ivas_qmetadata_raw_decode_dir( * Read the bitstream following the encoding scheme of EncodeQuasiUniform *------------------------------------------------------------------------*/ -/* !r: Value read from the bitstream */ +/*! r: Value read from the bitstream */ static uint16_t ivas_qmetadata_DecodeQuasiUniform( const uint16_t *bitstream, /* i : pointer to the bitstream to read */ int16_t *index, /* i : position in the bitstream to start reading (gets updated with reading) */ @@ -2282,7 +2282,7 @@ static uint16_t ivas_qmetadata_DecodeQuasiUniform( * Reads the bitstream and decodes the value using the ExtendedGR algorithm *------------------------------------------------------------------------*/ -/* !r: Value decoded from the bitstream */ +/*! r: Value decoded from the bitstream */ static int16_t ivas_qmetadata_DecodeExtendedGR( uint16_t *bitstream, /* i : pointer to the bitstream to read */ int16_t *index, /* i/o: position in the bitstream to start reading (gets updated with reading) */ @@ -2341,7 +2341,7 @@ static int16_t ivas_qmetadata_DecodeExtendedGR( * Calculates the correct elevation index from the decoded data *------------------------------------------------------------------------*/ -/* !r: Elevation index as it will be read by the dequantizer */ +/*! r: Elevation index as it will be read by the dequantizer */ static int16_t ivas_qmetadata_ReorderElevationDecoded( const int16_t elev_dist, /* i : Distance to the average extracted from the bitstream */ const int16_t elev_avg, /* i : Average value over time-blocks extracted from the bitstream */ @@ -2371,7 +2371,7 @@ static int16_t ivas_qmetadata_ReorderElevationDecoded( * Local functions: requentizeEC3 *-----------------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t read_directions( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ const uint8_t coding_subbands, /* i : number of directions */ @@ -2423,6 +2423,7 @@ static int16_t read_directions( max_nb_idx = k; } } + if ( q_direction->cfg.nblocks == 1 ) { byteBuffer = 0; @@ -2602,7 +2603,7 @@ static int16_t read_directions( * read and decode the azimuth indexes for one subband *-------------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t decode_azimuth( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ uint16_t *bitstream, /* i : bitstream to be read */ @@ -2771,7 +2772,7 @@ static int16_t decode_azimuth( * Reads the bitstream and decode the elevation index *-------------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t decode_elevation( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ uint16_t *bitstream, /* i : input bitstream */ @@ -2899,7 +2900,7 @@ static int16_t decode_elevation( * decoding in fixed rate case, i.e. when using the spherical indexes *-----------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t decode_fixed_rate( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata */ const uint16_t *bitstream, /* i : bitstream to be read */ @@ -2939,7 +2940,7 @@ static int16_t decode_fixed_rate( * Azimuth bitstream reading and decoding in 2D case *-------------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t decode_azimuth2D( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ uint16_t *bitstream, /* i : bitstream to be read */ @@ -3133,7 +3134,7 @@ static int16_t read_truncGR_azimuth( * *-------------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t read_common_direction( uint16_t *bitstream, /* i : bitstream to be read */ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ @@ -3260,7 +3261,7 @@ static void decode_spread_coherence( const int16_t no_frames /* i : number of time subframes */ #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ #endif ) { @@ -3274,6 +3275,7 @@ static void decode_spread_coherence( #ifdef HR_METADATA int16_t min_index; #endif + coding_subbands_0 = hQMetaData->q_direction[0].cfg.nbands; coding_subbands = hQMetaData->q_direction[idx_d].cfg.nbands; if ( coding_subbands_0 <= 5 ) @@ -3328,8 +3330,9 @@ static void decode_spread_coherence( for ( i = 0; i < coding_subbands; i++ ) { var_azi = var( q_direction->band_data[i].azimuth, no_frames ); + #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { minimum_s( (int16_t *) ( q_direction->band_data[i].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); min_index = min_index >> 1; @@ -3357,7 +3360,9 @@ static void decode_spread_coherence( idx_sub_cb = MASA_NO_CV_COH * ( q_direction->band_data[i].energy_ratio_index[0] + DIRAC_DIFFUSE_LEVELS ); /* NO_CV_COH = 8 */ } #endif + dct_coh[i][0] = coherence_cb0_masa[idx_sub_cb + q_direction->coherence_band_data[i].spread_coherence_dct0_index]; + if ( coding_subbands < coding_subbands_0 ) { assert( idx_d == 1 ); @@ -3386,7 +3391,7 @@ static void decode_spread_coherence( * Read Hufman code *-------------------------------------------------------------------*/ -/* !r: number of bits read */ +/*! r: number of bits read */ static ivas_error read_huf( int16_t *num_bits_read, const uint16_t *bitstream, /* i : bitstream to be read */ @@ -3614,14 +3619,21 @@ static int16_t decode_fixed_rate_composed_index_coherence( return nbits; } + #ifdef HR_METADATA -/* !r: number of bits read */ +/*-------------------------------------------------------------------* + * read_coherence_data_hr_512() + * + * + *-------------------------------------------------------------------*/ + +/*! r: number of bits read */ static int16_t read_coherence_data_hr_512( uint16_t *bitstream, /* i : bitstream */ int16_t *p_bit_pos, /* i : position in the bitstream */ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ const int16_t idx_dir, /* i : direction index */ - int16_t nbits_coh ) + const int16_t nbits_coh ) { int16_t j, k, i; int16_t nbands, nblocks; @@ -3687,13 +3699,15 @@ static int16_t read_coherence_data_hr_512( return nbits; } #endif -/*------------------------------------------------------------------ - * + + +/*------------------------------------------------------------------- * * read_coherence_data() * * Read coherence data - *------------------------------------------------------------------ - */ + *------------------------------------------------------------------- */ -/* !r: number of bits read */ +/*! r: number of bits read */ static int16_t read_coherence_data( uint16_t *bitstream, /* i : bitstream */ int16_t *p_bit_pos, /* i : position in the bitstream */ @@ -3701,7 +3715,7 @@ static int16_t read_coherence_data( const int16_t idx_dir /* i : direction index */ #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ #endif ) { @@ -3723,6 +3737,7 @@ static int16_t read_coherence_data( #ifdef HR_METADATA int16_t min_index; #endif + coding_subbands = hQMetaData->q_direction[idx_dir].cfg.nbands; q_direction = &( hQMetaData->q_direction[idx_dir] ); @@ -3734,7 +3749,7 @@ static int16_t read_coherence_data( for ( j = 0; j < coding_subbands; j++ ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { idx_ER = 7 - ( q_direction->band_data[j].energy_ratio_index_mod[0] >> 1 ) + coding_subbands / MASA_FACTOR_CV_COH; } @@ -3770,7 +3785,7 @@ static int16_t read_coherence_data( if ( no_cv_vec[j] > 1 ) { #ifdef HR_METADATA - q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( decoded_idx[j] * ( 255.0f / (float) ( 7 - ( q_direction->band_data[j].energy_ratio_index_mod[0] >> ( is_hr ) ) + coding_subbands / MASA_FACTOR_CV_COH ) ) ); + q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( decoded_idx[j] * ( 255.0f / (float) ( 7 - ( q_direction->band_data[j].energy_ratio_index_mod[0] >> ( hrmasa_flag ) ) + coding_subbands / MASA_FACTOR_CV_COH ) ) ); #else q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( decoded_idx[j] * ( 255.0f / (float) ( 7 - q_direction->band_data[j].energy_ratio_index_mod[0] + coding_subbands / MASA_FACTOR_CV_COH ) ) ); #endif @@ -3791,7 +3806,7 @@ static int16_t read_coherence_data( if ( no_cv_vec[j] > 1 ) { #ifdef HR_METADATA - q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( decoded_index[j] * ( 255.0f / (float) ( 7 - ( q_direction->band_data[j].energy_ratio_index_mod[0] >> ( is_hr ) ) + coding_subbands / MASA_FACTOR_CV_COH ) ) ); + q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( decoded_index[j] * ( 255.0f / (float) ( 7 - ( q_direction->band_data[j].energy_ratio_index_mod[0] >> ( hrmasa_flag ) ) + coding_subbands / MASA_FACTOR_CV_COH ) ) ); #else q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( decoded_index[j] * ( 255.0f / (float) ( 7 - q_direction->band_data[j].energy_ratio_index_mod[0] + coding_subbands / MASA_FACTOR_CV_COH ) ) ); #endif @@ -3808,7 +3823,7 @@ static int16_t read_coherence_data( for ( j = 0; j < coding_subbands; j++ ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { minimum_s( (int16_t *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); no_cv_vec[j] = len_cb_dct0_masa[min_index >> 1]; /* spread coherence DCT0*/ @@ -4103,7 +4118,15 @@ static int16_t read_surround_coherence( return bits_sur_coherence; } + + #ifdef HR_METADATA +/*-------------------------------------------------------------------* + * read_surround_coherence_hr() + * + * + *-------------------------------------------------------------------*/ + static int16_t read_surround_coherence_hr( uint16_t *bitstream, /* i : bitstream */ int16_t *p_bit_pos, /* i : position in the bitstream */ @@ -4175,7 +4198,6 @@ static int16_t read_surround_coherence_hr( } else { - /* read how the surround coherence is encoded */ byteBuffer = bitstream[bit_pos--]; bits_sur_coherence += 1; diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index 2b034655f3427156e9b7a77c65379ff41099ed3c..16298dfe980c2f68e746765e91fce88411d0fd31 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -524,7 +524,7 @@ const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1] = 0.0f, 0.125f, 0.375f, 1.0f }; -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t sba_map_tc[11] = { 0, 1, 2, 3, 4, 8, 9, 15, 5, 6, 7 diff --git a/lib_dec/ivas_rom_dec.h b/lib_dec/ivas_rom_dec.h index 81aec535a2b901fcb5df063b8967694b713e1284..05211fa94e119e07a1d06a9917350065ed926065 100644 --- a/lib_dec/ivas_rom_dec.h +++ b/lib_dec/ivas_rom_dec.h @@ -115,7 +115,7 @@ extern const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM extern const float *const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; -#ifdef SPAR_TUNING +#ifdef HODIRAC extern const int16_t sba_map_tc[11]; extern const int16_t sba_map_tc_512[11]; #else diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 471916d12c556f38d07f274bdea2deaa7f6a02f5..0dcaec91da54020113ede586536eb13f1da1d064 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -125,7 +125,6 @@ ivas_error ivas_sba_dec_reconfigure( last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; #endif - /*-----------------------------------------------------------------* * Set SBA high-level parameters * Save old SBA high-level parameters @@ -301,6 +300,7 @@ ivas_error ivas_sba_dec_reconfigure( mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); #endif } + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, @@ -311,7 +311,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order, st_ivas->sba_mode, #ifdef HODIRAC - ( st_ivas->sba_analysis_order > 1 && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) + ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) #else IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND #endif @@ -320,12 +320,14 @@ ivas_error ivas_sba_dec_reconfigure( { return error; } + if ( st_ivas->renderer_type == RENDERER_DISABLE ) { ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); } + if ( st_ivas->hDirAC != NULL ) { mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); @@ -399,7 +401,7 @@ ivas_error ivas_sba_dec_reconfigure( else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { tc_nchan_to_allocate = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif @@ -496,7 +498,7 @@ void ivas_sba_dec_render( hSpar = st_ivas->hSpar; nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 426348c7fece6d4f02430ac5a330ca6b41b925b5..6d71f1f8b8e9d1ae738d5659cd9f9313edcc9130 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -439,7 +439,7 @@ void ivas_sba_upmixer_renderer( push_wmops( "ivas_sba_upmixer_renderer" ); nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif @@ -691,7 +691,7 @@ void ivas_sba_mix_matrix_determiner( /* Mixing matrix determiner */ num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , MAX_PARAM_SPATIAL_SUBFRAMES #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 22d38997ddeb09b82337e2ec4dbee906448efa46..d1104594a11a879df6fe1850505ffda2213c304f 100755 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -72,18 +72,18 @@ ivas_error ivas_spar_dec_open( IVAS_FB_CFG *fb_cfg; int16_t i, j, b, active_w_mixing; int32_t output_Fs; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t num_decor_chs; #endif error = IVAS_ERR_OK; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal -#ifdef SPAR_TUNING - , - st_ivas->hDecoderConfig->ivas_total_brate + +#ifndef HODIRAC + num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); +#else + num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); #endif - ); hSpar = st_ivas->hSpar; @@ -97,7 +97,7 @@ ivas_error ivas_spar_dec_open( } output_Fs = st_ivas->hDecoderConfig->output_Fs; -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( num_channels_internal > ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) { num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; @@ -108,7 +108,7 @@ ivas_error ivas_spar_dec_open( } #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC /* TD decorr. */ if ( ( error = ivas_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_decor_chs + 1, 1 ) ) != IVAS_ERR_OK ) { @@ -674,7 +674,7 @@ void ivas_spar_get_cldfb_gains( * determines if an FOA input channel is transmitted as residual channel. *---------------------------------------------------------------------*/ -/* !r: 1 if prediction residual channel */ +/*! r: 1 if prediction residual channel */ int16_t ivas_is_res_channel( const int16_t ch, /* i : ch index in WYZX ordering */ const int16_t nchan_transport /* i : number of transport channels (1-4) */ @@ -711,7 +711,7 @@ static void ivas_spar_dec_MD( { int16_t num_channels, table_idx, num_bands_out, bfi, sba_order; int32_t ivas_total_brate; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t num_md_sub_frames; #endif DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig; @@ -727,13 +727,13 @@ static void ivas_spar_dec_MD( bfi = st_ivas->bfi; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; num_channels = ivas_sba_get_nchan_metadata( sba_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , ivas_total_brate #endif ); -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); #endif @@ -797,7 +797,7 @@ static void ivas_spar_dec_MD( { ivas_spar_setup_md_smoothing( hSpar->hMdDec, num_bands_out -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -813,7 +813,7 @@ static void ivas_spar_dec_MD( if ( !bfi ) { ivas_spar_smooth_md_dtx( hSpar->hMdDec, num_bands_out -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -957,7 +957,7 @@ static void ivas_spar_get_skip_mat( const int16_t num_ch_in, const int16_t num_spar_bands, int16_t skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif @@ -972,7 +972,7 @@ static void ivas_spar_get_skip_mat( { skip_mat[out_ch][in_ch] = 1; skip_flag = 1; -#ifdef SPAR_TUNING +#ifdef HODIRAC for ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -1150,7 +1150,7 @@ void ivas_spar_dec_agc_pca( if ( hSpar->hMdDec->td_decorr_flag ) { num_in_ingest = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif @@ -1225,7 +1225,7 @@ void ivas_spar_dec_set_render_params( nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate ) #endif @@ -1257,7 +1257,7 @@ void ivas_spar_dec_digest_tc( default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); nSamplesLeftForTD = nSamplesForRendering; nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif @@ -1272,7 +1272,7 @@ void ivas_spar_dec_digest_tc( { int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame ); ivas_td_decorr_process( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr ); -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hSpar->hTdDecorr->num_apd_outputs >= ( nchan_internal - nchan_transport ) ) { for ( ch = 0; ch < nchan_internal - nchan_transport; ch++ ) @@ -1349,7 +1349,7 @@ void ivas_spar_dec_upmixer( if ( hSpar->hMdDec->td_decorr_flag ) { ivas_td_decorr_process( hSpar->hTdDecorr, st_ivas->hTcBuffer->tc, pPcm_tmp, output_frame ); -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hSpar->hTdDecorr->num_apd_outputs >= ( nchan_internal - nchan_transport ) ) { for ( i = 0; i < nchan_internal - nchan_transport; i++ ) @@ -1454,7 +1454,7 @@ void ivas_spar_dec_upmixer( int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; DECODER_CONFIG_HANDLE hDecoderConfig; SPAR_DEC_HANDLE hSpar; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t num_md_sub_frames; #ifndef JBM_TSM_ON_TCS int16_t md_sf_idx; @@ -1478,7 +1478,7 @@ void ivas_spar_dec_upmixer( numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate ); #endif @@ -1587,7 +1587,7 @@ void ivas_spar_dec_upmixer( { ivas_td_decorr_process( hSpar->hTdDecorr, output, pPcm_tmp, output_frame ); -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hSpar->hTdDecorr->num_apd_outputs >= ( nchan_internal - nchan_transport ) ) { for ( i = 0; i < nchan_internal - nchan_transport; i++ ) @@ -1652,7 +1652,7 @@ void ivas_spar_dec_upmixer( *---------------------------------------------------------------------*/ ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -1668,7 +1668,7 @@ 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 -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -1769,7 +1769,7 @@ void ivas_spar_dec_upmixer( for ( in_ch = 0; in_ch < numch_in; in_ch++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( b_skip_mat[out_ch][in_ch] == 0 ) { if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */ @@ -1831,7 +1831,7 @@ void ivas_spar_dec_upmixer( /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; split_band = SPAR_DIRAC_SPLIT_START_BAND; -#ifdef SPAR_TUNING +#ifdef HODIRAC md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0; #endif if ( split_band < IVAS_MAX_NUM_BANDS ) @@ -1951,7 +1951,7 @@ void ivas_spar_dec_upmixer( #ifndef JBM_TSM_ON_TCS -#ifdef SPAR_TUNING +#ifdef HODIRAC md_sf_idx = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? i_sf : 0; #endif split_band = SPAR_DIRAC_SPLIT_START_BAND; @@ -1970,7 +1970,7 @@ void ivas_spar_dec_upmixer( { for ( b = 0; b < num_spar_bands; b++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf_idx * IVAS_MAX_NUM_BANDS]; #else 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]; diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 6b9f1457d4a3cb3aeba1c9fd9ae99a8bfcd17472..bfca6c62802068d4d726e21653b4841f0f2ef8b0 100755 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -64,7 +64,7 @@ static const int16_t ivas_spar_dec_plc_spatial_target[IVAS_SPAR_MAX_CH] = { 1, 0 *------------------------------------------------------------------------------------------*/ static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t numch_out, #else const int16_t sba_order, @@ -82,19 +82,19 @@ static void ivas_get_band_idx_from_differential( ivas_spar_md_t *pSpar_md, const 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_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands, const int16_t bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif ); static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t numch_out #else const int16_t sba_order #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif @@ -118,19 +118,19 @@ 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 */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif ) { int16_t i, j; -#ifndef SPAR_TUNING +#ifndef HODIRAC int16_t num_md_sub_frames; num_md_sub_frames = MAX_PARAM_SPATIAL_SUBFRAMES; #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * num_md_sub_frames * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) #else if ( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) @@ -150,7 +150,7 @@ static ivas_error ivas_spar_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( ( hMdDec->mixer_mat[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) #else if ( ( hMdDec->mixer_mat[i][j] = (float *) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) @@ -173,7 +173,7 @@ static ivas_error ivas_spar_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( ( hMdDec->spar_coeffs.C_re[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) #else if ( ( hMdDec->spar_coeffs.C_re[i][j] = (float *) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) @@ -196,7 +196,7 @@ static ivas_error ivas_spar_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( ( hMdDec->spar_coeffs.P_re[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) #else if ( ( hMdDec->spar_coeffs.P_re[i][j] = (float *) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) @@ -286,7 +286,7 @@ static ivas_error ivas_spar_md_dec_matrix_open( return IVAS_ERR_OK; } -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t ivas_get_spar_dec_md_num_subframes( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate ) @@ -320,7 +320,7 @@ ivas_error ivas_spar_md_dec_open( { ivas_spar_md_dec_state_t *hMdDec; ivas_error error; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t num_md_sub_frames; #endif @@ -331,11 +331,11 @@ ivas_error ivas_spar_md_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate ); #endif if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, num_channels -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -516,13 +516,13 @@ ivas_error ivas_spar_md_dec_init( int16_t nchan_transport; float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; -#ifdef SPAR_TUNING +#ifdef HODIRAC ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); #else hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC ivas_sba_get_spar_hoa_ch_ind( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); #endif @@ -668,7 +668,7 @@ static ivas_error ivas_spar_set_dec_config( } nchan = ivas_sba_get_nchan_metadata( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate #endif @@ -732,7 +732,7 @@ void ivas_spar_md_dec_process( { int16_t j, k, b, bw, dtx_vad, nB, i_ts; ivas_spar_md_dec_state_t *hMdDec; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t num_md_chs; #endif int16_t num_md_sub_frames; @@ -742,10 +742,10 @@ void ivas_spar_md_dec_process( int16_t active_w_vlbr; active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_chs = ivas_sba_get_nchan_metadata( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); #else num_md_sub_frames = MAX_PARAM_SPATIAL_SUBFRAMES; @@ -761,7 +761,7 @@ void ivas_spar_md_dec_process( 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 = ivas_sba_get_nchan_metadata( sba_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , st_ivas->hDecoderConfig->ivas_total_brate #endif @@ -898,7 +898,7 @@ void ivas_spar_md_dec_process( }*/ #endif /* SPAR to DirAC conversion */ -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdDec->spar_hoa_dirac2spar_md_flag == 1 ) #endif { @@ -1035,7 +1035,7 @@ void ivas_spar_md_dec_process( }*/ #endif /* expand DirAC MD to all time slots */ -#ifdef SPAR_TUNING +#ifdef HODIRAC for ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) #else for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) @@ -1063,12 +1063,12 @@ void ivas_spar_md_dec_process( } } -#ifdef SPAR_TUNING +#ifdef HODIRAC ivas_get_spar_matrices( hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, #else ivas_get_spar_matrices( hMdDec, num_bands_out, MAX_PARAM_SPATIAL_SUBFRAMES, bw, dtx_vad, nB, #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_chs, #else sba_order, @@ -1098,12 +1098,12 @@ void ivas_spar_md_dec_process( } ivas_spar_md_fill_invalid_bands( &hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, -#ifdef SPAR_TUNING +#ifdef HODIRAC num_md_chs #else sba_order #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -1127,7 +1127,7 @@ void ivas_spar_md_dec_process( void ivas_spar_smooth_md_dtx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out /* i : number of output bands */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames /* i : number of metadata subframes */ #endif @@ -1166,7 +1166,7 @@ void ivas_spar_smooth_md_dtx( } /* expand MD to all time slots */ -#ifdef SPAR_TUNING +#ifdef HODIRAC for ( int16_t i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) #else for ( int16_t i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) @@ -1210,7 +1210,7 @@ void ivas_spar_smooth_md_dtx( void ivas_spar_setup_md_smoothing( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out /* i : number of output bands */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames /* i : number of metadata subframes */ #endif @@ -1266,7 +1266,7 @@ void ivas_spar_setup_md_smoothing( } ivas_spar_smooth_md_dtx( hMdDec, num_bands_out -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -1350,14 +1350,14 @@ static void ivas_get_spar_matrices( const int16_t bw, const int16_t dtx_vad, const int16_t nB, -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t numch_out, #else const int16_t sba_order, #endif const int16_t active_w_vlbr ) { -#ifndef SPAR_TUNING +#ifndef HODIRAC int16_t numch_out, num_bands, dmx_ch, split_band; #else int16_t num_bands, dmx_ch, split_band; @@ -1366,7 +1366,7 @@ static void ivas_get_spar_matrices( const int16_t *order; float active_w_dm_fac, re; -#ifndef SPAR_TUNING +#ifndef HODIRAC numch_out = ivas_sba_get_nchan_metadata( sba_order ); #endif @@ -1747,7 +1747,7 @@ void ivas_spar_dec_gen_umx_mat( const int16_t nchan_transport, /* i : number of transport channels */ const int16_t num_bands_out, /* i : number of output bands */ const int16_t bfi /* i : bad frame indicator */ -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif @@ -1757,7 +1757,7 @@ void ivas_spar_dec_gen_umx_mat( num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; -#ifdef SPAR_TUNING +#ifdef HODIRAC for ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) #else for ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) @@ -1823,7 +1823,7 @@ void ivas_spar_dec_gen_umx_mat( } ivas_spar_dec_compute_ramp_down_post_matrix( hMdDec, num_bands_out, bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , num_md_sub_frames #endif @@ -2206,7 +2206,7 @@ static void ivas_decode_arith_bs( { pred_cell_dims[i].dim1 = ndm + ndec - 1; if ( hMdDec->spar_hoa_md_flag -#ifdef SPAR_TUNING +#ifdef HODIRAC && hMdDec->spar_hoa_dirac2spar_md_flag #endif ) @@ -2238,7 +2238,7 @@ static void ivas_decode_arith_bs( if ( any_diff == 1 ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) #else if ( hMdDec->spar_hoa_md_flag ) @@ -2264,7 +2264,7 @@ static void ivas_decode_arith_bs( ivas_fill_band_coeffs_idx( hMdDec->spar_md.band_coeffs_idx, nB, symbol_arr_re, pred_cell_dims, PRED_COEFF, planarCP ); -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) #else if ( hMdDec->spar_hoa_md_flag ) @@ -2533,7 +2533,7 @@ static void ivas_decode_huffman_bs( drct_dim = ndec * ( ndm - 1 ); decd_dim = ndec; pred_offset = 0; -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) #else if ( hMdDec->spar_hoa_md_flag ) @@ -2551,7 +2551,7 @@ static void ivas_decode_huffman_bs( &hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j] ); } -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) #else if ( hMdDec->spar_hoa_md_flag ) @@ -2608,12 +2608,12 @@ static void ivas_spar_md_fill_invalid_bands( const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t num_channels #else const int16_t sba_order #endif -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif @@ -2623,7 +2623,7 @@ 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; -#ifndef SPAR_TUNING +#ifndef HODIRAC int16_t num_channels; num_channels = ivas_sba_get_nchan_metadata( sba_order ); @@ -2714,7 +2714,7 @@ static void ivas_spar_md_fill_invalid_bands( { for ( j = 0; j < num_channels; j++ ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC for ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) #else for ( i_ts = 1; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) @@ -2743,7 +2743,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t bfi -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t num_md_sub_frames #endif @@ -2786,7 +2786,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( } /* apply the post matrix */ -#ifdef SPAR_TUNING +#ifdef HODIRAC for ( int16_t i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) #else for ( int16_t i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) @@ -3067,7 +3067,7 @@ void ivas_spar_to_dirac( if ( hDirAC != NULL #ifdef HODIRAC - && ( st_ivas->sba_analysis_order <= 1 || st_ivas->hDecoderConfig->ivas_total_brate <= IVAS_256k ) + && ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ) == 0 #endif ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index cc7e31f9a6f0b989faa4024bcae16733674d0f6a..98df8c3dcade50d3a372f45734cf1fd60b0fe72f 100755 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -732,7 +732,7 @@ typedef struct ivas_dirac_dec_data_structure PARAM_ISM_RENDERING_HANDLE hParamIsmRendering; IVAS_FB_MIXER_HANDLE hFbMdft; int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t *sba_map_tc; #endif @@ -861,7 +861,7 @@ typedef struct ivas_spar_md_dec_state_t int16_t table_idx; int16_t dtx_vad; int16_t spar_hoa_md_flag; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t spar_hoa_dirac2spar_md_flag; int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]; #endif diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 72d55bc1710fcaa8a74777d2184f9b0e11329a72..e3a5db6f7f9de8cb37882afe5ebe40525c56fddb 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -578,7 +578,7 @@ void computeReferencePower_enc( const SBA_MODE sba_mode /* i : SBA mode */ #ifdef HODIRAC , - int16_t nchan_ana /* i : no of analysis channels */ + const int16_t nchan_ana /* i : number of analysis channels */ #endif ) { @@ -599,6 +599,7 @@ void computeReferencePower_enc( reference_power_W[i] += ( Cldfb_RealBuffer[0][j] * Cldfb_RealBuffer[0][j] ) + ( Cldfb_ImagBuffer[0][j] * Cldfb_ImagBuffer[0][j] ); } reference_power[i] += reference_power_W[i]; + #ifdef HODIRAC for ( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ ) #else @@ -643,7 +644,7 @@ void ivas_dirac_param_est_enc( const SBA_MODE sba_mode #ifdef HODIRAC , - const int16_t hodirac, + const int16_t hodirac_flag, const int16_t nchan_fb_in #endif ) @@ -674,23 +675,12 @@ void ivas_dirac_param_est_enc( float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS] = { 0 }; #endif -#ifdef HODIRAC_WRITE_PARAMS - static FILE *f_secparams = 0; -#endif - push_wmops( "dirac_enc_param_est" ); #ifdef HODIRAC num_freq_bands = hDirAC->hConfig->nbands; #endif -#ifdef HODIRAC_WRITE_PARAMS - if ( f_secparams == 0 ) - { - f_secparams = fopen( "sector_params.txt", "w" ); - } -#endif - /* Initialization */ l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; if ( useLowerRes ) @@ -797,7 +787,7 @@ void ivas_dirac_param_est_enc( hDirAC->hConfig->enc_param_start_band, num_freq_bands, #ifdef HODIRAC - hodirac ? SBA_MODE_DIRAC : sba_mode + hodirac_flag ? SBA_MODE_DIRAC : sba_mode #else sba_mode #endif @@ -816,7 +806,7 @@ void ivas_dirac_param_est_enc( intensity_real ); #ifdef HODIRAC - if ( !hodirac ) + if ( !hodirac_flag ) #endif { computeDirectionVectors( @@ -841,40 +831,17 @@ void ivas_dirac_param_est_enc( mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); + #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { - calculate_hodirac_sector_parameters( - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - l_ts, - 0.20f, - hDirAC->band_grouping, - hDirAC->hConfig->nbands, - hDirAC->hConfig->enc_param_start_band, - azi_secs, ele_secs, diff_secs, ene_secs ); - -#ifdef HODIRAC_WRITE_PARAMS - for ( i = 0; i < num_freq_bands; i++ ) - { - for ( uint16_t j = 0; j < 4; j++ ) - { - fprintf( f_secparams, "%d %d %f %f %f %f %f\n", i, j, - azi_secs[j * num_freq_bands + i], - ele_secs[j * num_freq_bands + i], - ene_secs[j * num_freq_bands + i], - diff_secs[j * num_freq_bands + i], - diffuseness_vector[i] ); - } - } - -#endif // HODIRAC_WRITE_PARAMS + calculate_hodirac_sector_parameters( Cldfb_RealBuffer, Cldfb_ImagBuffer, l_ts, 0.20f, hDirAC->band_grouping, hDirAC->hConfig->nbands, hDirAC->hConfig->enc_param_start_band, azi_secs, ele_secs, diff_secs, ene_secs ); } -#endif // HODIRAC +#endif #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { @@ -901,7 +868,7 @@ void ivas_dirac_param_est_enc( } #ifdef HODIRAC - if ( !hodirac ) + if ( !hodirac_flag ) #endif { @@ -940,9 +907,10 @@ void ivas_dirac_param_est_enc( &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); } } + /* Sectors */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { @@ -953,20 +921,6 @@ void ivas_dirac_param_est_enc( q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); -#ifdef HODIRAC_WRITE_PARAMS - { - static FILE *f_a = 0; - if ( f_a == 0 ) - f_a = fopen( "param_enc", "w" ); - fprintf( f_a, "%f %f %f %f %f %f\n", - q_direction->band_data[band_m_idx].azimuth[block_m_idx], - q_direction->band_data[band_m_idx].elevation[block_m_idx], - diffuseness_vector[band_m_idx], - q_direction[1].band_data[band_m_idx].azimuth[block_m_idx], - q_direction[1].band_data[band_m_idx].elevation[block_m_idx], - q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] ); - } -#endif } } #endif diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 50ea332a7a1e1eab725e275436253840897fa45e..6121bd588f83b350d7a127c33a79b355f61ea1c8 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -138,7 +138,7 @@ ivas_error ivas_enc( #endif ) { -#ifdef SPAR_TUNING +#ifdef HODIRAC hp20( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); #else hp20( data_f[HOA_keep_ind[i]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 7390ba8b38dd11f1b23a3901016d9ab816faf8ba..6575d751a9a366c0e32b5a389d65f2e6cc84841c 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -57,7 +57,7 @@ *------------------------------------------------------------------------------------------*/ static void ivas_band_cov( float **ppIn_FR_real, float **ppIn_FR_imag, const int16_t num_chans, const int16_t num_bins, int16_t stride, float **pFb_bin_to_band, const int16_t *pFb_start_bin_per_band, const int16_t *pFb_active_bins_per_band, const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] #endif @@ -170,7 +170,7 @@ void ivas_enc_cov_handler_process( const int16_t num_ch, const int16_t dtx_vad, const int16_t transient_det[2] -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] #endif @@ -188,7 +188,7 @@ void ivas_enc_cov_handler_process( pFb->fb_bin_to_band.p_short_stride_num_bins_per_band, start_band, end_band, cov_real -#ifdef SPAR_TUNING +#ifdef HODIRAC , HOA_md_ind #endif @@ -285,7 +285,7 @@ static void ivas_band_cov( const int16_t start_band, const int16_t end_band, float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] -#ifdef SPAR_TUNING +#ifdef HODIRAC , const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] #endif @@ -301,7 +301,7 @@ static void ivas_band_cov( { #ifdef HODIRAC -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t i1 = HOA_md_ind[i]; int16_t j1 = HOA_md_ind[j]; #else diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index c706d9bb64ca4dc11b3a8851bc3af220f66873ff..e858074445b286935945a97ae7f9c5f0168d8d03 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -198,7 +198,7 @@ int16_t getNumChanAnalysis( #ifdef HODIRAC n = ( st_ivas->sba_analysis_order + 1 ) * ( st_ivas->sba_analysis_order + 1 ); #else -#ifdef SPAR_TUNING +#ifdef HODIRAC n = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->ivas_total_brate ); #else n = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 8938a415ffc78f67051b53df1343d1373540b4a5..2527fa91aabc9fc6f29477f31246637889489b33 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -64,7 +64,7 @@ static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_H static void average_masa_metadata( MASA_METADATA_FRAME *masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] #ifdef HR_METADATA , - SPHERICAL_GRID_DATA *sphGrid + const SPHERICAL_GRID_DATA *sphGrid #endif ); @@ -256,12 +256,14 @@ ivas_error ivas_masa_encode( } } } + #ifdef HR_METADATA if ( ivas_format == MASA_FORMAT && ivas_total_brate >= IVAS_384k ) { hMasa->config.mergeRatiosOverSubframes = 0; } #endif + /* Combine frequency bands and sub-frames */ combine_freqbands_and_subframes( hMasa ); } @@ -350,7 +352,6 @@ ivas_error ivas_masa_encode( } #endif - *nb_bits_metadata = hMetaData->nb_bits_tot; if ( ivas_format == MASA_FORMAT && Opt_DTX_ON ) @@ -537,6 +538,7 @@ ivas_error ivas_masa_enc_config( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA spherical grid\n" ) ); } + if ( ivas_total_brate == IVAS_512k ) { generate_gridEq( sphGrid ); @@ -546,6 +548,7 @@ ivas_error ivas_masa_enc_config( sphGrid->no_theta = 0; } #endif + /* average over sub-frames */ average_masa_metadata( &( hMasa->masaMetadata ), hMasa->data.energy #ifdef HR_METADATA @@ -1775,7 +1778,7 @@ static void average_masa_metadata( float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] #ifdef HR_METADATA , - SPHERICAL_GRID_DATA *Sph_Grid16 + const SPHERICAL_GRID_DATA *Sph_Grid16 #endif ) { diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index a44121f9a77b6b35978b3873417a07224b2e3dfb..6363ee3b130f9d7599b940f5db81fc674bf25bf0 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -740,7 +740,7 @@ static void ivas_mc_paramupmix_param_est_enc( int16_t chan1s[4] = { 4, 5, 8, 9 }; int16_t chan2s[4] = { 6, 7, 10, 11 }; -#ifdef SPAR_TUNING +#ifdef HODIRAC const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; #endif @@ -817,7 +817,7 @@ static void ivas_mc_paramupmix_param_est_enc( cov_dtx_real[i][j] = hMCParamUpmix->cov_dtx_real[b][i][j]; } } -#ifdef SPAR_TUNING +#ifdef HODIRAC ivas_enc_cov_handler_process( hMCParamUpmix->hCovEnc[b], pp_in_fr_real, pp_in_fr_imag, cov_real, cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind ); #else ivas_enc_cov_handler_process( hMCParamUpmix->hCovEnc[b], pp_in_fr_real, pp_in_fr_imag, cov_real, cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b] ); diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 273703b3176a498af9b0eb7f6b51213f314f1cfd..64d5b8e6aa86c91574a962280fcfff859334f420 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -55,7 +55,7 @@ static float direction_distance( float elevation[DIRAC_MAX_NBANDS][MAX_PARAM_SPA static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *needed_bits, int16_t *nbits_diff, int16_t *dfRatioBits #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag #endif ); @@ -68,7 +68,7 @@ static int16_t ivas_qmetadata_entropy_encode_df_ratio( BSTR_ENC_HANDLE hMetaData static int16_t ivas_qmetadata_entropy_encode_dir( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, const uint16_t diffuseness_index_max_ec_frame, const int16_t nbands, const int16_t start_band, const int16_t direction_bits_raw, int16_t max_bits #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); @@ -101,7 +101,7 @@ static int16_t write_fixed_rate_direction( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRE static int16_t ivas_qmetadata_quantize_coherence( IVAS_QMETADATA *hQMetaData, const int16_t idx_d, const int16_t all_coherence_zero, BSTR_ENC_HANDLE hMetaData, const int16_t write_flag, int16_t *indice_coherence #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); @@ -110,11 +110,11 @@ static void dct4_transform( uint8_t *v, float *dct_v ); static float quantize_DCT_0_coh( const float x, const int16_t j, const float *coherence_cb, const float delta_var, const int16_t no_cb, IVAS_QDIRECTION *q_direction, uint16_t *idx_x, int16_t *p_no_cb #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ); -static int16_t encode_coherence_indexesDCT0( uint16_t *idx_dct, const int16_t len, int16_t *no_cb_vec, BSTR_ENC_HANDLE hMetaData, int16_t indice_coherence, const int16_t nbits, const int16_t nbits1 ); +static int16_t encode_coherence_indexesDCT0( uint16_t *idx_dct, const int16_t len, int16_t *no_cb_vec, BSTR_ENC_HANDLE hMetaData, const int16_t indice_coherence, const int16_t nbits, const int16_t nbits1 ); static int16_t encode_coherence_indexesDCT1( uint16_t *idx_dct, const int16_t len, BSTR_ENC_HANDLE hMetaData ); @@ -137,41 +137,22 @@ static int16_t write_2dir_info( BSTR_ENC_HANDLE hMetaData, uint8_t *twoDirBands, static void transform_azimuth_dir2( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *dir2_bands ); static int16_t calc_var_azi( const IVAS_QDIRECTION *q_direction, const int16_t diffuseness_index_max_ec_frame, const float avg_azimuth, float *avg_azimuth_out ); + #ifdef HR_METADATA -static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr( - IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - int16_t *nbits_diff, - int16_t *dfRatioBits, - int16_t bits_dir_hr ); -static int16_t ivas_qmetadata_entropy_encode_diffuseness_hr( - BSTR_ENC_HANDLE hMetaData, - IVAS_QDIRECTION *q_direction, - uint16_t *diffuseness_index_max_ec_frame ); +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *needed_bits, int16_t *nbits_diff, int16_t *dfRatioBits, const int16_t bits_dir_hr ); -static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( - IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - int16_t bits_dir_hr, - BSTR_ENC_HANDLE hMetaData ); +static int16_t ivas_qmetadata_entropy_encode_diffuseness_hr( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, uint16_t *diffuseness_index_max_ec_frame ); -static int16_t encode_surround_coherence_hr( - IVAS_QMETADATA *hQMetaData, /* i : quantized metadata */ - BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ -); +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *needed_bits, const int16_t bits_dir_hr, BSTR_ENC_HANDLE hMetaData ); -static void ivas_qmetadata_reorder_2dir_bands_hr( - IVAS_QMETADATA_HANDLE hQMetaData ); +static int16_t encode_surround_coherence_hr( IVAS_QMETADATA *hQMetaData, BSTR_ENC_HANDLE hMetaData ); -static int16_t ivas_qmetadata_quantize_coherence_hr_512( - IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata */ - const int16_t idx_d, /* i : current direction index */ - const int16_t all_coherence_zero, /* i : all coherence is zero - flag */ - BSTR_ENC_HANDLE hMetaData, /* i : metadata handle */ - int16_t bits_coh ); +static void ivas_qmetadata_reorder_2dir_bands_hr( IVAS_QMETADATA_HANDLE hQMetaData ); +static int16_t ivas_qmetadata_quantize_coherence_hr_512( IVAS_QMETADATA *hQMetaData, const int16_t idx_d, const int16_t all_coherence_zero, BSTR_ENC_HANDLE hMetaData, const int16_t bits_coh ); #endif + /*-----------------------------------------------------------------------* * ivas_qmetadata_enc_encode() * @@ -179,11 +160,11 @@ static int16_t ivas_qmetadata_quantize_coherence_hr_512( *-----------------------------------------------------------------------*/ ivas_error ivas_qmetadata_enc_encode( - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - IVAS_QMETADATA *hQMetaData /* i/o: metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData /* i/o: metadata handle */ #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode*/ #endif ) { @@ -270,7 +251,7 @@ ivas_error ivas_qmetadata_enc_encode( #endif /* Reorder 2dir bands for more efficient encoding. */ #ifdef HODIRAC - if ( !hodirac ) + if ( !hodirac_flag ) #endif { ivas_qmetadata_reorder_2dir_bands( hQMetaData ); @@ -311,7 +292,7 @@ ivas_error ivas_qmetadata_enc_encode( ivas_qmetadata_quantize_diffuseness_nrg_ratios( hQMetaData, bits_dir_raw_pre, bits_diff, dfRatio_bits #ifdef HODIRAC , - hodirac + hodirac_flag #endif ); @@ -748,16 +729,21 @@ ivas_error ivas_qmetadata_enc_encode( return error; } + #ifdef HR_METADATA +/*-----------------------------------------------------------------------* + * ivas_qmetadata_enc_encode_hr_384_512() + * + * Main function for quantizing and coding Spatial Metadata at HRs + *-----------------------------------------------------------------------*/ ivas_error ivas_qmetadata_enc_encode_hr_384_512( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ - int16_t bits_sph_idx, - int16_t bits_sp_coh ) + const int16_t bits_sph_idx, + const int16_t bits_sp_coh ) { int16_t i, j; - int16_t bits_diff[QMETADATA_MAX_NO_DIRECTIONS]; IVAS_QDIRECTION *q_direction; int16_t nbands, nblocks, start_band; @@ -766,7 +752,6 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( int16_t bits_no_dirs_coh; int16_t bits_ec; float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - ivas_error error; error = IVAS_ERR_OK; @@ -799,7 +784,6 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( ndirections = hQMetaData->no_directions; - /* Check if coherence should be encoded */ all_coherence_zero = 1; bits_no_dirs_coh = 0; @@ -810,6 +794,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( push_next_indice( hMetaData, all_coherence_zero, 1 ); /* signal coherence */ bits_no_dirs_coh += 1; } + /* encode 2 direction subbands position */ if ( ndirections == 2 && bits_sph_idx == 11 ) { @@ -822,8 +807,8 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; } - /*Quantization and encoding of the Diffuseness */ + /*Quantization and encoding of the Diffuseness */ ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( hQMetaData, bits_diff, bits_sph_idx, hMetaData ); /* Encode surround coherence */ @@ -833,7 +818,6 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( } else { - for ( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { if ( hQMetaData->surcoh_band_data != NULL ) @@ -843,7 +827,6 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( } } - /* Loop over number of directions*/ for ( d = 0; d < ndirections; d++ ) { @@ -853,7 +836,6 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( nblocks = q_direction->cfg.nblocks; start_band = q_direction->cfg.start_band; - #ifdef DEBUG_MODE_QMETADATA { int16_t k; @@ -875,7 +857,6 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( #endif /*Coherence */ - if ( all_coherence_zero == 0 ) { ivas_qmetadata_quantize_coherence_hr_512( hQMetaData, d, all_coherence_zero, hMetaData, bits_sp_coh ); @@ -1328,13 +1309,13 @@ void reset_metadata_spatial( * *------------------------------------------------------------------------*/ -/* !r: quantized spherical index */ +/*! r: quantized spherical index */ int16_t quantize_direction2D( - float phi, /* i : input azimuth value */ - const int16_t no_cw, /* i : number of bits */ - float *phi_q, /* o : quantized azimuth value */ - uint16_t *index_phi, /* o : quantized azimuth index */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ + float phi, /* i : input azimuth value */ + const int16_t no_cw, /* i : number of bits */ + float *phi_q, /* o : quantized azimuth value */ + uint16_t *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { int16_t idx_sph; @@ -1346,7 +1327,6 @@ int16_t quantize_direction2D( return 0; } - if ( mc_format != MC_LS_SETUP_INVALID ) { id_phi = quantize_phi_chan_compand( phi + 180, phi_q, no_cw, 0, mc_format ); @@ -1363,6 +1343,7 @@ int16_t quantize_direction2D( return idx_sph; } + #ifdef HR_METADATA /*------------------------------------------------------------------------- * ivas_qmetadata_quantize_diffuseness_nrg_ratios() @@ -1375,7 +1356,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr( int16_t *needed_bits, int16_t *nbits_diff, int16_t *dfRatioBits, - int16_t bits_dir_hr ) + const int16_t bits_dir_hr ) { int16_t j, k, dir2band; int16_t index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; @@ -1517,17 +1498,15 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr( static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *needed_bits, - int16_t bits_dir_hr, + const int16_t bits_dir_hr, BSTR_ENC_HANDLE hMetaData ) { int16_t j, k; int16_t index; - needed_bits[0] = 0; needed_bits[1] = 0; - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) @@ -1541,6 +1520,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_dir_hr; } } + if ( hQMetaData->no_directions == 2 ) { for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; ++j ) @@ -1619,7 +1599,6 @@ static int16_t ivas_qmetadata_entropy_encode_diffuseness_hr( } } - /* Use similarity coding approach or raw coding when there is a low number of bands. */ /* one bit is used to indicate whether diffuseness values are entropy coded or coded raw */ if ( min_diffuseness_m_index == max_diffuseness_m_index ) /* all values are equal */ @@ -1649,7 +1628,6 @@ static int16_t ivas_qmetadata_entropy_encode_diffuseness_hr( } } - *diffuseness_index_max_ec_frame = 10; /* adaptively select the diffuseness_index_max_ec threshold */ if ( min_diffuseness_m_index > 10 ) @@ -1660,7 +1638,6 @@ static int16_t ivas_qmetadata_entropy_encode_diffuseness_hr( #ifdef DEBUGGING assert( ( hMetaData->nb_bits_tot - start_bit_pos ) <= 1 + diffuseness_bits_raw ); #endif - return ( hMetaData->nb_bits_tot - start_bit_pos ); } @@ -1679,7 +1656,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( int16_t *dfRatioBits #ifdef HODIRAC , - int16_t hodirac /* i: flag to indicate sector processing */ + const int16_t hodirac_flag #endif ) { @@ -1706,9 +1683,9 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( * accurate than simple separate quantization of each direct-to-total ratio or their * separate inverses. */ #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { - /* already encoded as total and ratios in HODIRAC*/ + /* already encoded as total and ratios in HO-DirAC */ diffRatio = 1.f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; } @@ -1727,7 +1704,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( diffRatioQ = diffuseness_reconstructions[index_diff]; #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { dfRatio_bits = ivas_get_df_ratio_bits_hodirac( index_diff ); } @@ -1741,7 +1718,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( dfRatio_qsteps = ( 1 << dfRatio_bits ); #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.0f, 1.f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); dirRatio1Q = 1.f - diffRatioQ; @@ -1757,7 +1734,6 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( dirRatio2Q = ( 1.0f - diffRatioQ ) - dirRatio1Q; } - index_dirRatio1Inv = masa_sq( 1.0f - dirRatio1Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction @@ -1769,8 +1745,9 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = dirRatio1Q; } nbits_diff[0] += MASA_BITS_ER; + #ifdef HODIRAC - if ( hodirac ) + if ( hodirac_flag ) { float tmp; index_dirRatio2Inv = usquant( dirRatio2Q, &tmp, 0.0f, 1.f / ( DIRAC_DIFFUSE_LEVELS - 1 ), DIRAC_DIFFUSE_LEVELS ); @@ -1795,7 +1772,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( masa_compensate_two_dir_energy_ratio_index( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod #ifdef HODIRAC , - hodirac + hodirac_flag #endif ); @@ -2244,7 +2221,7 @@ static void ivas_qmetadata_encode_quasi_uniform( * *------------------------------------------------------------------------*/ -/* !r: number of bits using Golomb Rice code */ +/*! r: number of bits using Golomb Rice code */ static int16_t GR_bits_new( uint16_t *data, /* i : data to encode with GR */ int16_t *no_symb, /* i : number of symbols for each component*/ @@ -2298,7 +2275,7 @@ static int16_t GR_bits_new( * Encoding azimuth indexes with GR code using context *------------------------------------------------------------------------*/ -/* !r: numer of bits used for coding */ +/*! r: numer of bits used for coding */ static int16_t GR_bits_azimuth_context( uint16_t *data_in, /* i : data to be encoded */ int16_t *no_symb, /* i : number of symbols for each component */ @@ -2396,7 +2373,7 @@ static int16_t GR_bits_azimuth_context( * Golomb Rice encoding with mean removing *------------------------------------------------------------------------*/ -/* !r: number of bits used */ +/*! r: number of bits used */ static int16_t mean_removed_GR_new( const uint16_t *idx, /* i : data to encode */ const int16_t max_no_symb, @@ -2486,7 +2463,7 @@ static int16_t ivas_qmetadata_entropy_encode_dir( int16_t max_bits #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag #endif ) { @@ -2532,10 +2509,11 @@ static int16_t ivas_qmetadata_entropy_encode_dir( idx = 0; dist_count = 0; set_zero( avg_direction_vector, 3 ); + for ( i = start_band; i < nbands; i++ ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { diff_idx_min = 0; // min( q_direction->band_data[i].energy_ratio_index_mod[0]>>1, diff_idx_min ); } @@ -2595,7 +2573,6 @@ static int16_t ivas_qmetadata_entropy_encode_dir( no_th = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; - for ( i = 0; i < no_th; i++ ) { theta_cb[i] = i * delta_theta_masa[bits_direction_masa[diff_idx_min] - 3]; @@ -2747,6 +2724,7 @@ static int16_t ivas_qmetadata_entropy_encode_dir( } } } + direction_bits_ec += elevation_bits_ec_best; } @@ -2919,6 +2897,7 @@ static int16_t ivas_qmetadata_entropy_encode_dir( } } } + /* encode the ExtendedGR part for azimuth */ ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( avg_azimuth_index_best - ( avg_azimuth_alphabet >> 1 ) ), avg_azimuth_alphabet ); @@ -2952,6 +2931,7 @@ static int16_t ivas_qmetadata_entropy_encode_dir( ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } + if ( dist_count > nblocks ) { if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( nblocks > 1 ) ) @@ -2986,6 +2966,7 @@ static int16_t ivas_qmetadata_entropy_encode_dir( } } } + direction_bits_ec -= bits_gained; } else @@ -4139,7 +4120,7 @@ static ivas_error requantize_direction_EC_3( * writing of the spherical indexes *-------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static int16_t write_fixed_rate_direction( BSTR_ENC_HANDLE hMetaData, /* i : MASA metadata structure */ IVAS_QDIRECTION *qdirection, /* i/o: quantized directional parameters */ @@ -4401,7 +4382,7 @@ static void calculate_two_distances( * write metadata using entropy encoding *-------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static ivas_error write_ec_direction( int16_t *num_bits_written, /* o : Number of bits written */ BSTR_ENC_HANDLE hMetaData, /* i : MASA metadata structure */ @@ -4575,7 +4556,7 @@ static ivas_error write_ec_direction( * Local functions (coherence Q and coding) *-----------------------------------------------------------------------*/ -/* !r: index */ +/*! r: index */ static uint64_t create_combined_index( uint16_t *idx_dct, /* i : indexes to combine */ const int16_t len, /* i : number of indexes */ @@ -4601,13 +4582,13 @@ static uint64_t create_combined_index( * encoding DCT0 coeffs with joint index *-----------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static int16_t encode_coherence_indexesDCT0( uint16_t *idx_dct, /* i : indexes to be encoded */ const int16_t len, /* i : number of indexes */ int16_t *no_cb_vec, /* i : number of codewords for each position */ BSTR_ENC_HANDLE hMetaData, - int16_t indice_coherence, + const int16_t indice_coherence, const int16_t nbits, const int16_t nbits1 ) { @@ -4750,14 +4731,14 @@ static int16_t coherence_coding_length( * Encoding spread coherence for 1 subframe bands *-------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static int16_t encode_spread_coherence_1sf( - IVAS_QMETADATA *q_metadata, /* i : quantized metadata */ - const int16_t idx_d, /* i : current direction index */ - BSTR_ENC_HANDLE hMasaMetaData /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *q_metadata, /* i : quantized metadata */ + const int16_t idx_d, /* i : current direction index */ + BSTR_ENC_HANDLE hMasaMetaData /* i/o: metadata bitstream handle */ #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ #endif ) { @@ -4790,7 +4771,7 @@ static int16_t encode_spread_coherence_1sf( for ( j = 0; j < coding_subbands; j++ ) { #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { idx_ER = 7 - ( q_direction->band_data[j].energy_ratio_index_mod[0] >> 1 ) + extra_cv; } @@ -4801,6 +4782,7 @@ static int16_t encode_spread_coherence_1sf( #ifdef HR_METADATA } #endif + if ( idx_ER > 0 ) { idx_sp_coh[j] = (uint16_t) roundf( q_direction->coherence_band_data[j].spread_coherence[0] / ( 255.0f / (float) idx_ER ) ); @@ -4945,7 +4927,7 @@ static int16_t encode_spread_coherence_1sf( * encoding surround coherence *-------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static int16_t encode_surround_coherence( IVAS_QMETADATA *hQMetaData, /* i : quantized metadata */ BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ @@ -5360,7 +5342,7 @@ static int16_t encode_surround_coherence_hr( * quanization of DCT component of order zero for transformed coherence vector *-------------------------------------------------------------------*/ -/* !r: quantized value */ +/*! r: quantized value */ static float quantize_DCT_0_coh( const float x, /* i : input value */ const int16_t j, /* i : subband index */ @@ -5372,7 +5354,7 @@ static float quantize_DCT_0_coh( int16_t *p_no_cb /* o : actual number of codewords dependent on energy ratio value */ #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ #endif ) { @@ -5383,8 +5365,9 @@ static float quantize_DCT_0_coh( #endif /* quantize first DCT component */ var_azi = var( q_direction->band_data[j].azimuth, q_direction->cfg.nblocks ); + #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { minimum_s( (int16_t *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); min_index = min_index >> 1; @@ -5393,6 +5376,7 @@ static float quantize_DCT_0_coh( { min_index = q_direction->band_data[j].energy_ratio_index[0]; } + if ( var_azi < delta_var ) { idx_sub_cb = no_cb * min_index; @@ -5431,7 +5415,7 @@ static float quantize_DCT_0_coh( * Encoding DCT1 coeffs with joint index or EC *-------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static int16_t encode_coherence_indexesDCT1( uint16_t *idx_dct, /* i : data to be encoded */ const int16_t len, /* i : number of data */ @@ -5486,13 +5470,20 @@ static void dct4_transform( return; } + #ifdef HR_METADATA +/*-------------------------------------------------------------------* + * ivas_qmetadata_quantize_coherence_hr_512() + * + * + *-------------------------------------------------------------------*/ + static int16_t ivas_qmetadata_quantize_coherence_hr_512( IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata */ const int16_t idx_d, /* i : current direction index */ const int16_t all_coherence_zero, /* i : all coherence is zero - flag */ BSTR_ENC_HANDLE hMetaData, /* i : metadata handle */ - int16_t bits_coh ) + const int16_t bits_coh ) { int16_t j, k; int16_t nbands, nblocks; @@ -5588,23 +5579,24 @@ static int16_t ivas_qmetadata_quantize_coherence_hr_512( } #endif + /*-------------------------------------------------------------------* * ivas_qmetadata_quantize_coherence() * * *-------------------------------------------------------------------*/ -/* !r: number of bits written */ +/*! r: number of bits written */ static int16_t ivas_qmetadata_quantize_coherence( - IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata */ - const int16_t idx_d, /* i : current direction index */ - const int16_t all_coherence_zero, /* i : all coherence is zero - flag */ - BSTR_ENC_HANDLE hMetaData, /* i : metadata handle */ - const int16_t write_flag, /* i : flag to actually write the data or not */ + IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata */ + const int16_t idx_d, /* i : current direction index */ + const int16_t all_coherence_zero, /* i : all coherence is zero - flag */ + BSTR_ENC_HANDLE hMetaData, /* i : metadata handle */ + const int16_t write_flag, /* i : flag to actually write the data or not */ int16_t *indice_coherence #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ #endif ) { @@ -5638,7 +5630,7 @@ static int16_t ivas_qmetadata_quantize_coherence( nbits = encode_spread_coherence_1sf( hQMetaData, idx_d, hMetaData #ifdef HR_METADATA , - is_hr + hrmasa_flag #endif ); @@ -5695,8 +5687,9 @@ static int16_t ivas_qmetadata_quantize_coherence( { /* DCT transform */ dct4_transform( hQMetaData->q_direction[idx_d].coherence_band_data[j].spread_coherence, dct_coh[j] ); + #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { minimum_s( (int16_t *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); no_cb_vec[j] = len_cb_dct0_masa[min_index >> 1]; @@ -5715,7 +5708,7 @@ static int16_t ivas_qmetadata_quantize_coherence( dct_coh[j][0] = quantize_DCT_0_coh( dct_coh[j][0], j, coherence_cb0_masa, MASA_DELTA_AZI_DCT0, MASA_NO_CV_COH, q_direction, &idx_dct[k], &no_cb_vec[j] #ifdef HR_METADATA , - is_hr + hrmasa_flag #endif ); } @@ -5880,13 +5873,22 @@ static void ivas_qmetadata_reorder_2dir_bands( return; } + #ifdef HR_METADATA +/*-------------------------------------------------------------------* + * ivas_qmetadata_reorder_2dir_bands_hr() + * + * + *-------------------------------------------------------------------*/ + static void ivas_qmetadata_reorder_2dir_bands_hr( IVAS_QMETADATA_HANDLE hQMetaData ) { - int16_t nbands; - int16_t nsubframes; + int16_t nbands, nsubframes; int16_t band, sf; + uint16_t uint16_tmp; + float flt_tmp; + uint8_t uint8_tmp; nbands = hQMetaData->q_direction[0].cfg.nbands; nsubframes = hQMetaData->q_direction[0].cfg.nblocks; @@ -5895,14 +5897,10 @@ static void ivas_qmetadata_reorder_2dir_bands_hr( { if ( hQMetaData->twoDirBands[band] == 1 ) { - for ( sf = 0; sf < nsubframes; sf++ ) { if ( hQMetaData->q_direction[0].band_data[band].energy_ratio[sf] < hQMetaData->q_direction[1].band_data[band].energy_ratio[sf] ) { - uint16_t uint16_tmp = 0; - float flt_tmp = 0; - uint8_t uint8_tmp = 0; uint16_tmp = hQMetaData->q_direction[0].band_data[band].spherical_index[sf]; hQMetaData->q_direction[0].band_data[band].spherical_index[sf] = hQMetaData->q_direction[1].band_data[band].spherical_index[sf]; hQMetaData->q_direction[1].band_data[band].spherical_index[sf] = uint16_tmp; @@ -5936,6 +5934,7 @@ static void ivas_qmetadata_reorder_2dir_bands_hr( } #endif + /*-------------------------------------------------------------------* * write_2dir_info() * @@ -5952,6 +5951,7 @@ static int16_t write_2dir_info( int16_t p[MASA_MAXIMUM_CODING_SUBBANDS]; uint16_t dif_p[MASA_MAXIMUM_CODING_SUBBANDS]; int16_t i, j; + j = 0; p[0] = 0; for ( i = 0; i < n; i++ ) @@ -5962,6 +5962,7 @@ static int16_t write_2dir_info( j++; } } + dif_p[0] = p[0]; for ( i = 1; i < j; i++ ) { @@ -5982,6 +5983,12 @@ static int16_t write_2dir_info( } +/*-------------------------------------------------------------------* + * transform_azimuth_dir2() + * + * + *-------------------------------------------------------------------*/ + static void transform_azimuth_dir2( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *dir2_bands ) diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index 3d2df98217deca34987173f49e7226e4ebe21427..4c79b875b7b1dfbc53971c0aec0e400cbabea077 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -62,7 +62,7 @@ void quantize_direction_frame( float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] #ifdef HR_METADATA , - int16_t is_hr + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ #endif ) { @@ -98,7 +98,7 @@ void quantize_direction_frame( q_direction->not_in_2D += q_direction->band_data[i].elevation_index[j]; #ifdef HR_METADATA - if ( is_hr ) + if ( hrmasa_flag ) { if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) { @@ -127,6 +127,7 @@ void quantize_direction_frame( #ifdef HR_METADATA } #endif + if ( q_direction->band_data[i].azimuth_index[j] == MASA_NO_INDEX ) { q_direction->band_data[i].azimuth_index[j] = 0; @@ -162,6 +163,7 @@ void quantize_direction_frame( return; } + /*-------------------------------------------------------------------* * quantize_direction_frame2D() * @@ -270,6 +272,7 @@ void small_requantize_direction_frame( return; } + /*-------------------------------------------------------------------* * quantize_direction() * @@ -351,7 +354,6 @@ uint16_t quantize_direction( return idx_sph; } - no_th = no_theta_masa[no_bits - 3]; for ( i = 0; i < no_th; i++ ) @@ -497,20 +499,21 @@ uint16_t quantize_direction( return idx_sph; } + /*-------------------------------------------------------------------* * direction_distance_cp() * * quantization distortion calculated on the sphere *----------------------------------------------------------------------*/ -/* !r: distortion value */ +/*! r: distortion value */ static float direction_distance_cp( - float theta, /* i : elevation absolute value */ - float theta_hat, /* i : quantized elevation value in absolute value */ - float theta_hat1, /* i : quantized elevation value in absolute value */ - const float phi, /* i : azimuth value */ - const float phi_hat, /* i : quantized azimuth value */ - const float phi_hat1, /* i : quantized azimuth value */ + float theta, /* i : elevation absolute value */ + float theta_hat, /* i : quantized elevation value in absolute value */ + float theta_hat1, /* i : quantized elevation value in absolute value */ + const float phi, /* i : azimuth value */ + const float phi_hat, /* i : quantized azimuth value */ + const float phi_hat1, /* i : quantized azimuth value */ float *d1 ) { float d, ct, st, st1, st2; @@ -536,28 +539,27 @@ static float direction_distance_cp( * joint quantization of elevation and azimuth *----------------------------------------------------------------------*/ -/* !r: quantized elevation value */ +/*! r: quantized elevation value */ static float quantize_theta_phi( - float *theta_cb, /* i : elevation codebook */ - const int16_t no_th, /* i : elevation codebook size */ - const int16_t *no_phi_loc, /* i : number of azimuth values for each elevation codeword */ - const float abs_theta, /* i : absolute value of elevation to be quantized */ - int16_t *id_phi, /* o : azimuth index */ - int16_t *id_phi_remap, /* o : remapped azimuth index */ - float *phi_hat, /* o : quantized azimuth value */ - const float phi, /* i : input azimuth value; to be quantized */ - const int16_t no_bits, /* i : number of bits used for quantization */ - int16_t *id_theta, /* o : elevation index */ - float *phi_q, /* o : rotated quantized azimuth */ - const int16_t remap, /* i : flag for remapping */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ + float *theta_cb, /* i : elevation codebook */ + const int16_t no_th, /* i : elevation codebook size */ + const int16_t *no_phi_loc, /* i : number of azimuth values for each elevation codeword*/ + const float abs_theta, /* i : absolute value of elevation to be quantized */ + int16_t *id_phi, /* o : azimuth index */ + int16_t *id_phi_remap, /* o : remapped azimuth index */ + float *phi_hat, /* o : quantized azimuth value */ + const float phi, /* i : input azimuth value; to be quantized */ + const int16_t no_bits, /* i : number of bits used for quantization */ + int16_t *id_theta, /* o : elevation index */ + float *phi_q, /* o : rotated quantized azimuth */ + const int16_t remap, /* i : flag for remapping */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { float theta_hat, theta_hat1, phi_hat1; int16_t id_th, id_th1, id_th2, id_ph, id_ph1; float d, d1; - id_th = (int16_t) ( abs_theta / delta_theta_masa[no_bits - 3] ); if ( id_th >= no_th ) { @@ -573,7 +575,6 @@ static float quantize_theta_phi( { if ( ( no_th < 6 ) && mc_format == MC_LS_SETUP_INVALID ) { - if ( id_th == 0 ) { id_th1 = 1; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 098654416a362fa11befcd4771505c3b4e2a175e..a7c359b7c96b6eaade81cf7fe35b58d88d154781 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -89,7 +89,7 @@ ivas_error ivas_spar_enc_open( input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal -#ifdef SPAR_TUNING +#ifdef HODIRAC , hEncoderConfig->ivas_total_brate #endif @@ -116,6 +116,7 @@ ivas_error ivas_spar_enc_open( assert( 0 && "sba_order must be 1,2, or 3!" ); } #endif + nchan_transport = ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal ); // bw = ivas_get_bw_idx_from_sample_rate(pCfg->input_Fs); @@ -471,7 +472,7 @@ static ivas_error ivas_spar_enc_process( 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 -#ifdef SPAR_TUNING +#ifdef HODIRAC , hEncoderConfig->ivas_total_brate #endif @@ -484,9 +485,7 @@ static ivas_error ivas_spar_enc_process( #ifdef HODIRAC nchan_fb_in = hSpar->hFbMixer->fb_cfg->nchan_fb_in; nchan_transport = st_ivas->nchan_transport; -#endif -#ifdef HODIRAC for ( i = FOA_CHANNELS + 1; i < nchan_fb_in; i++ ) #else for ( i = FOA_CHANNELS + 1; i < nchan_inp; i++ ) @@ -495,7 +494,6 @@ static ivas_error ivas_spar_enc_process( mvr2r( data_f[HOA_keep_ind[i]], data_f[i], input_frame ); } - /*-----------------------------------------------------------------------------------------* * Transient detector *-----------------------------------------------------------------------------------------*/ @@ -542,7 +540,7 @@ static ivas_error ivas_spar_enc_process( /* run Filter Bank overlapping MDFT analysis first, then we can use the temporary buffer for Parameter MDFT analysis*/ ivas_fb_mixer_pcm_ingest( hSpar->hFbMixer, data_f, p_pcm_tmp, input_frame -#ifdef SPAR_TUNING +#ifdef HODIRAC , hSpar->hMdEnc->HOA_md_ind #endif @@ -570,6 +568,7 @@ static ivas_error ivas_spar_enc_process( nchan_fb_in #endif ); + ivas_fb_mixer_update_prior_input( hSpar->hFbMixer, p_pcm_tmp, l_ts #ifdef HODIRAC , @@ -627,17 +626,15 @@ static ivas_error ivas_spar_enc_process( ivas_qmetadata_enc_encode( hMetaData, hQMetaData #ifdef HODIRAC , - st_ivas->sba_analysis_order > 1 && ivas_total_brate > IVAS_256k + ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) #endif ); } else { - hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; /* compute directions */ - #ifdef HODIRAC for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) #else @@ -754,7 +751,7 @@ static ivas_error ivas_spar_enc_process( nchan_inp, dtx_vad, transient_det -#ifdef SPAR_TUNING +#ifdef HODIRAC , hSpar->hMdEnc->HOA_md_ind #endif @@ -770,7 +767,7 @@ static ivas_error ivas_spar_enc_process( ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer ); } -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) #endif { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index d27f149b6de2d35bb33e1ce65990ea845b16553e..4f9882cd245d9c9ed51aed8ffc0121292c0ba4d2 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -120,7 +120,7 @@ ivas_error ivas_spar_md_enc_open( } num_channels = ivas_sba_get_nchan_metadata( sba_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , hEncoderConfig->ivas_total_brate #endif @@ -319,18 +319,18 @@ ivas_error ivas_spar_md_enc_init( float PR_minmax[2]; int16_t num_channels, i, j, k; -#ifdef SPAR_TUNING +#ifdef HODIRAC ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); #else hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); #endif num_channels = ivas_sba_get_nchan_metadata( sba_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , hEncoderConfig->ivas_total_brate #endif ); -#ifdef SPAR_TUNING +#ifdef HODIRAC ivas_sba_get_spar_hoa_ch_ind( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); #endif table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); @@ -581,7 +581,7 @@ ivas_error ivas_spar_md_enc_process( num_quant_strats = hMdEnc->spar_md_cfg.num_quant_strats; num_ch = ivas_sba_get_nchan_metadata( sba_order -#ifdef SPAR_TUNING +#ifdef HODIRAC , hEncoderConfig->ivas_total_brate #endif @@ -657,7 +657,7 @@ ivas_error ivas_spar_md_enc_process( nB = num_bands; bands_bw = 1; } -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) #else if ( hMdEnc->spar_hoa_md_flag ) @@ -838,7 +838,7 @@ ivas_error ivas_spar_md_enc_process( } } -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) #else if ( hMdEnc->spar_hoa_md_flag ) @@ -1431,7 +1431,7 @@ static void ivas_get_huffman_coded_bs( pred_coeff_dim = ndm + ndec - 1; pred_offset = 0; -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) #else if ( hMdEnc->spar_hoa_md_flag ) @@ -1542,7 +1542,7 @@ static void ivas_get_arith_coded_bs( { pred_cell_dims[i].dim1 = ndm + ndec - 1; if ( hMdEnc->spar_hoa_md_flag -#ifdef SPAR_TUNING +#ifdef HODIRAC && hMdEnc->spar_hoa_dirac2spar_md_flag #endif ) @@ -1571,7 +1571,7 @@ static void ivas_get_arith_coded_bs( break; } } -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) #else if ( hMdEnc->spar_hoa_md_flag ) @@ -1605,7 +1605,7 @@ static void ivas_get_arith_coded_bs( ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff ); -#ifdef SPAR_TUNING +#ifdef HODIRAC if ( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) #else if ( hMdEnc->spar_hoa_md_flag ) diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 8ba9484661b41547eeebb376f94f08a4ce2dd46e..58b77976621fb97676c96b1d46a1951fe229e122 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -656,7 +656,7 @@ typedef struct ivas_spar_md_enc_state_t ivas_huff_coeffs_t huff_coeffs; int16_t table_idx; int16_t spar_hoa_md_flag; -#ifdef SPAR_TUNING +#ifdef HODIRAC int16_t spar_hoa_dirac2spar_md_flag; int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]; #endif diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 95da7818e703a19eb0c03ff85aba45d69c8d4b06..90756a39b1ec5dcb33c3c2034f832ba5f1d9042e 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -84,7 +84,7 @@ MasaFileReader *MasaFileReader_open( *------------------------------------------------------------------------*/ IVAS_MASA_METADATA_HANDLE MasaFileReader_getMetadataHandle( - MasaFileReader *self /* i/o: MasaFileReader handle */ + MasaFileReader *self /* i/o: MasaFileReader handle */ ) { if ( self == NULL ) @@ -95,21 +95,19 @@ IVAS_MASA_METADATA_HANDLE MasaFileReader_getMetadataHandle( return &self->metadataFrame; } + +#ifndef HR_METADATA /*------------------------------------------------------------------------- * deindex_sph_idx() * * deindex the MASA metadata from the input metadata file *------------------------------------------------------------------------*/ -#ifndef HR_METADATA -static -#endif - void - deindex_sph_idx( - const uint16_t sphIndex, /* i : Spherical index */ - const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ - float *theta, /* o : Elevation */ - float *phi /* o : Azimuth */ - ) +static void deindex_sph_idx( + const uint16_t sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + float *theta, /* o : Elevation */ + float *phi /* o : Azimuth */ +) { float ba_crt, del_crt, div_crt, a4_crt; float estim; @@ -252,6 +250,7 @@ static return; } +#endif /*------------------------------------------------------------------------- @@ -418,7 +417,7 @@ ivas_error MasaFileReader_readNextFrame( *------------------------------------------------------------------------*/ void MasaFileReader_close( - MasaFileReader **selfPtr /* i/o: pointer to MasaFileReader handle */ + MasaFileReader **selfPtr /* i/o: pointer to MasaFileReader handle */ ) { if ( selfPtr == NULL || *selfPtr == NULL )