diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index ae4cb9ef3cd75991a3982093df42bbe8c7d7f108..0bb399c1534927e071e7c0bb8f64d634ca0e624a 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -148,6 +148,7 @@ + @@ -168,6 +169,7 @@ + diff --git a/apps/encoder.c b/apps/encoder.c index 205457858c9031fac515bff639ebc74412c6fd39..607e377e3b66ad289b6c5ada514ebe54a7f96a0b 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -34,6 +34,7 @@ #include "cmdl_tools.h" #include "audio_file_reader.h" #include "bitstream_writer.h" +#include "jbm_file_reader.h" #include "masa_file_reader.h" #include "ism_file_reader.h" #include @@ -142,7 +143,6 @@ typedef struct static void initArgStruct( EncArguments *arg ); static bool parseCmdlIVAS_enc( int16_t argc, char *argv[], EncArguments *arg ); static void usage_enc( void ); -static ivas_error readChannelAwareConfig( FILE *file, IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig ); static bool readBandwidth( FILE *file, IVAS_ENC_BANDWIDTH *bandwidth, int32_t *bandwidthFrameCounter ); static bool readBitrate( FILE *file, int32_t *bitrate ); #ifdef DEBUGGING @@ -206,7 +206,7 @@ int main( AudioFileReader *audioReader = NULL; FILE *f_bitrateProfile = NULL; FILE *f_bwProfile = NULL; - FILE *f_caProfile = NULL; + JbmFileReader *jbmReader = NULL; MasaFileReader *masaReader = NULL; IsmFileReader *ismReaders[IVAS_MAX_NUM_OBJECTS]; for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) @@ -396,20 +396,18 @@ int main( if ( arg.ca_config_file ) { - if ( ( f_caProfile = fopen( arg.ca_config_file, "rb" ) ) == NULL ) + if ( ( jbmReader = JbmFileReader_open( arg.ca_config_file ) ) == NULL ) { fprintf( stderr, "\nError: Channel aware configuration file could not be opened: %s\n\n", arg.ca_config_file ); usage_enc(); goto cleanup; } - else - { - fprintf( stdout, "\nChannel-aware mode: ON, Channel-aware config file name: %s \n\n", arg.ca_config_file ); - } + + fprintf( stdout, "Channel-aware mode: ON, config file: %s \n", arg.ca_config_file ); } - else if ( arg.caConfig.channelAwareModeEnabled ) + else if ( caConfig.channelAwareModeEnabled ) { - fprintf( stdout, "\nChannel-aware mode: ON, FEC indicator : %s FEC offset: %d \n\n", ( caConfig.fec_indicator == IVAS_ENC_FEC_LO ) ? "LO" : "HI", caConfig.fec_offset ); + fprintf( stdout, "Channel-aware mode: ON, FEC indicator : %s FEC offset: %d \n\n", ( caConfig.fec_indicator == IVAS_ENC_FEC_LO ) ? "LO" : "HI", caConfig.fec_offset ); } /*------------------------------------------------------------------------------------------* @@ -470,7 +468,7 @@ int main( goto cleanup; } - IVAS_ENC_PrintConfig( hIvasEnc ); + IVAS_ENC_PrintConfig( hIvasEnc, caConfig.channelAwareModeEnabled ); /*------------------------------------------------------------------------------------------* * Open input metadata files @@ -517,23 +515,9 @@ int main( #endif /*------------------------------------------------------------------------------------------* - * Compensate for encoder delay (bitstream aligned with input signal) + * Allocate input data buffer *------------------------------------------------------------------------------------------*/ - int16_t encDelayInSamples; - if ( ( error = IVAS_ENC_GetDelay( hIvasEnc, &encDelayInSamples ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nGetDelay failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - goto cleanup; - } - - int16_t numInputChannels; - if ( ( error = IVAS_ENC_GetNumInputChannels( hIvasEnc, &numInputChannels ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nGetNumInputChannels failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); - goto cleanup; - } - int16_t pcmBufSize; if ( ( error = IVAS_ENC_GetInputBufferSize( hIvasEnc, &pcmBufSize ) ) != IVAS_ERR_OK ) { @@ -543,6 +527,17 @@ int main( pcmBuf = malloc( pcmBufSize * sizeof( int16_t ) ); + /*------------------------------------------------------------------------------------------* + * Compensate for encoder delay (bitstream aligned with input signal) + *------------------------------------------------------------------------------------------*/ + + int16_t encDelayInSamples; + if ( ( error = IVAS_ENC_GetDelay( hIvasEnc, &encDelayInSamples ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nGetDelay failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + goto cleanup; + } + if ( arg.delayCompensationEnabled && encDelayInSamples ) { /* read samples and throw them away */ @@ -637,17 +632,17 @@ int main( } } - if ( f_caProfile ) + if ( jbmReader ) { - if ( ( error = readChannelAwareConfig( f_caProfile, &caConfig ) ) != IVAS_ERR_OK ) + if ( ( error = JbmFileReader_readCAconfig( jbmReader, &caConfig ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "readChannelAwareConfig failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); + fprintf( stderr, "JbmFileReader_readCAconfig() failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } if ( ( error = IVAS_ENC_SetChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "IVAS_ENC_SetChannelAwareConfig failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); + fprintf( stderr, "IVAS_ENC_SetChannelAwareConfig failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } } @@ -768,6 +763,11 @@ cleanup: AudioFileReader_close( &audioReader ); + if ( jbmReader ) + { + JbmFileReader_close( &jbmReader ); + } + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) { if ( ismReaders[i] != NULL ) @@ -791,11 +791,6 @@ cleanup: fclose( f_bitrateProfile ); } - if ( f_caProfile ) - { - fclose( f_caProfile ); - } - #ifdef DEBUGGING if ( f_forcedModeProfile ) { @@ -1049,7 +1044,7 @@ static bool parseCmdlIVAS_enc( else if ( strcmp( argv_to_upper, "-RF" ) == 0 ) { - arg->caConfig.channelAwareModeEnabled = true; + arg->caConfig.channelAwareModeEnabled = 1; i++; if ( i < argc - 4 ) @@ -1069,12 +1064,11 @@ static bool parseCmdlIVAS_enc( } i++; - if ( ( sscanf( argv[i], "%d", &tmp ) == 1 ) && ( i < argc - 4 ) ) { if ( tmp == 0 ) { - arg->caConfig.channelAwareModeEnabled = false; + arg->caConfig.channelAwareModeEnabled = 0; arg->caConfig.fec_offset = 0; i++; } @@ -1646,66 +1640,6 @@ static void usage_enc( void ) } -/*---------------------------------------------------------------------* - * readChannelAwareConfig() - * - * - *---------------------------------------------------------------------*/ - -static ivas_error readChannelAwareConfig( - FILE *file, - IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig ) -{ - char rline[10], str[4]; - int16_t tmp; - - /* Initialize */ - caConfig->fec_offset = 0; - caConfig->fec_indicator = IVAS_ENC_FEC_HI; - - while ( fgets( rline, 10, file ) == NULL && feof( file ) ) - { - rewind( file ); - } - - if ( sscanf( rline, "%s %hd", str, &tmp ) != 2 ) - { - fprintf( stderr, "Error in the RF configuration file. There is no proper configuration line.\n" ); - return IVAS_ERR_INVALID_FEC_CONFIG; - } - - /* Read RF FEC indicator */ - to_upper( str ); - - if ( strcmp( str, "HI" ) == 0 ) - { - caConfig->fec_indicator = IVAS_ENC_FEC_HI; - } - else if ( strcmp( str, "LO" ) == 0 ) - { - caConfig->fec_indicator = IVAS_ENC_FEC_LO; - } - else - { - fprintf( stderr, "Error: Incorrect FEC indicator string. Exiting the encoder.\n" ); - return IVAS_ERR_INVALID_FEC_CONFIG; - } - - /* Read RF FEC offset */ - if ( tmp == 0 || tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 ) - { - caConfig->fec_offset = tmp; - } - else - { - fprintf( stderr, "Error: incorrect FEC offset specified in the RF configuration file; RF offset can be 2, 3, 5, or 7. \n" ); - return IVAS_ERR_INVALID_FEC_CONFIG; - } - - return IVAS_ERR_OK; -} - - /*---------------------------------------------------------------------* * readBandwidth() * diff --git a/lib_com/cnst.h b/lib_com/cnst.h index c5911101093f04546215db45f30fdd745649ff42..17a437bef7f9a0b468e0eced552d99462b8ac124 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -133,9 +133,6 @@ enum{ #define MAX_V_MULT_MAT 100 /* maximum array length for the function v_mult_mat() */ -#define G192_BIN0 (uint16_t) 0x007F -#define G192_BIN1 (uint16_t) 0x0081 - /*----------------------------------------------------------------------------------* * Layers @@ -1269,6 +1266,8 @@ enum #define MAX_LEN_MA_FILTER 20 /* maximum length of the MA filter for SHB TD envelope calculation */ #define TABLE_CUMSUM_MAX_N 320 /* maximum length of cumsum(i) and cumsum(i*i) tables */ +#define NUM_BITS_FB_FRAMEGAIN_TBE 4 /* Number of bits for framegain for FB TBE */ + /*----------------------------------------------------------------------------------* * SWB BWE constants *----------------------------------------------------------------------------------*/ @@ -1282,7 +1281,7 @@ enum #define FB_MAX_GAIN_VAR 0.5f -#define NUM_BITS_FB_FRAMEGAIN 4 /* Number of bits for framegain for FB */ +#define NUM_BITS_FB_FRAMEGAIN 4 /* Number of bits for framegain for FB BWE */ #define FB_BAND_BEGIN 620 /* == 15.5 kHz */ #define FB_BAND_BEGIN_12k8 560 /* == 14 kHz */ #define FB_BAND_END 800 /* == 20 kHz */ diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index b504d89731ff227a6c6c87728f0872ed52bbc099..c27b7bc62852ca914519749fc693f8bf5d3fb54a 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -47,10 +47,26 @@ #define IVAS_MAX_NUM_OBJECTS 4 #define IVAS_MAX_OUTPUT_CHANNELS 16 #define IVAS_CLDFB_NO_CHANNELS_MAX ( 60 ) + /*----------------------------------------------------------------------------------* * Common API structures *----------------------------------------------------------------------------------*/ +typedef enum _IVAS_ENC_FEC_INDICATOR +{ + IVAS_ENC_FEC_LO, + IVAS_ENC_FEC_HI, + IVAS_ENC_FEC_UNDEFINED = 0xffff +} IVAS_ENC_FEC_INDICATOR; + +typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG +{ + int16_t channelAwareModeEnabled; + IVAS_ENC_FEC_INDICATOR fec_indicator; + int16_t fec_offset; +} IVAS_ENC_CHANNEL_AWARE_CONFIG; + + typedef struct _IVAS_ISM_METADATA { float azimuth; diff --git a/lib_com/gs_bitallocation.c b/lib_com/gs_bitallocation.c index 8c98bf27d9212b4343afde96ae2a84d9d3eb1825..8458fb754fdf0044c80e2595977de7c9a34fdc9e 100644 --- a/lib_com/gs_bitallocation.c +++ b/lib_com/gs_bitallocation.c @@ -200,7 +200,7 @@ void bands_and_bit_alloc( /* 2- Decide the pourcentage of bits allocated to LF (between 50-75%) depending of the temporal contribution in GSC */ bit_fracf = ( -0.125f * Diff_len + 76.0f ) / 100; - check_bounds( &bit_fracf, 0.50f, 0.75f ); + bit_fracf = check_bounds( bit_fracf, 0.50f, 0.75f ); /* Adjusment of the bitrate between LF and HF base on the content type */ /* 1 = new GSC bit alloc @@ -236,7 +236,7 @@ void bands_and_bit_alloc( nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f; } nb_bands_max = (int16_t) ( nb_bands_max * nb_bands_adj + 0.5f ); - check_bounds_s( &nb_bands_max, 5, nb_tot_bands ); + nb_bands_max = check_bounds_s( nb_bands_max, 5, nb_tot_bands ); bit_fracf *= SWB_bit_budget; diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index d36bf05de0c594dcb88f2080d1fe23cbfbf4a9b5..cc600418c69488ffa18f20fb3e90a90e756cb12c 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -49,15 +49,13 @@ #define _180_OVER_PI ( 180.0f / EVS_PI ) #define SQRT2 1.414213562373095f +#define SQRT2_OVER_2 (SQRT2 / 2.0f) #define INV_SQRT2 7.071067811865475e-1f /* 1/sqrt(2) */ #define INV_SQRT3 0.577350269189626f /* 1/sqrt(3) */ #define LOG_10 2.30258509299f -#define SQRT2_OVER_2 (SQRT2 / 2.0f) - -#define ALIGN8(x) ((((x)+7) >> 3) << 3) /*----------------------------------------------------------------------------------* * IVAS formats @@ -839,7 +837,7 @@ typedef enum { SBA_MODE_NONE, SBA_MODE_DIRAC, - SBA_MODE_SPAR, + SBA_MODE_SPAR, // VE: this is actually SBA_MODE_SPAR_DIRAC } SBA_MODE; @@ -1312,7 +1310,11 @@ typedef enum #define IVAS_LFE_NUM_COEFFS_IN_SUBGRP 2 #define IVAS_LFE_MAX_NUM_DCT_PASS_BINS 8 #define IVAS_LFE_MAX_NUM_DCT_COEFFS (IVAS_LFE_MAX_NUM_DCT_PASS_BINS * IVAS_LFE_NUM_COEFFS_IN_SUBGRP) +#ifdef SBA_CLEANING +#define IVAS_LFE_FADE_NS 8000000L /* 8.0 ms */ +#else #define IVAS_LFE_FADE_LEN_SEC_FLOAT ((float)0.008) +#endif #define IVAS_MAX_NUM_QUANT_STRATS 2 #define IVAS_MAX_NUM_DCT_COEF_GROUPS 4 #define IVAS_LFE_SHIFT_BITS 5 @@ -1355,14 +1357,14 @@ typedef enum *----------------------------------------------------------------------------------*/ #define BINAURAL_MAXBANDS 60 /* Max number of bands */ -#define BINAURAL_CONVBANDS 50 /* Bands upto which convolution is performed */ +#define BINAURAL_CONVBANDS 50 /* Bands upto which convolution is performed */ #define BINAURAL_NTAPS_MAX 96 #define HRTF_SH_ORDER 3 #define HRTF_SH_CHANNELS 16 #define HRTF_NUM_BINS 60 #define REVERB_PREDELAY_MAX 20 /* Max input delay for reverb module */ -#define GAIN_LFE 1.88364911f /* Gain applied to LFE during renderering */ +#define GAIN_LFE 1.88364911f /* Gain applied to LFE during renderering */ #define LOW_BIT_RATE_BINAURAL_EQ_BINS 17 /* Number of bins in an EQ applied at low bit rates in binauralization */ #define LOW_BIT_RATE_BINAURAL_EQ_OFFSET 14 /* Offset of bins where the low-bit-rate EQ starts*/ diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 76d765095379e5aa3e6295e6d0e71c2cb4d41359..0489f76714dcf5cb908988fe305299828f401d9e 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -327,7 +327,7 @@ ivas_error ivas_dirac_sba_config( ivas_error error; error = IVAS_ERR_OK; - hQMetaData->is_masa_type_format = 0; + hQMetaData->is_masa_ivas_format = 0; if ( sba_mode == SBA_MODE_SPAR ) { diff --git a/lib_com/ivas_mdct_imdct.c b/lib_com/ivas_mdct_imdct.c index cc343410c2ea38a833bd2d1e8598d78f58544ac6..036f89201fb72f09a491a14b25aad764e6a4470a 100644 --- a/lib_com/ivas_mdct_imdct.c +++ b/lib_com/ivas_mdct_imdct.c @@ -134,11 +134,12 @@ void ivas_mdct( const int16_t length ) { const float *pTwid_re, *pTwid_im; - int16_t len_by_2 = length >> 1; - float re[IVAS_480_PT_LEN]; - float im[IVAS_480_PT_LEN]; - float ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain( len_by_2 ); - int16_t i; + int16_t i, len_by_2; + float re[IVAS_480_PT_LEN], im[IVAS_480_PT_LEN]; + float ivas_mdct_scaling_gain; + + len_by_2 = length >> 1; + ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain( len_by_2 ); ivas_get_twid_factors( length, &pTwid_re, &pTwid_im ); diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index ba6fdfea7c31aa505bd40e7f66225d19d91b9d5e..dbf8f07c200c7ba63b537196b7be04954b455c66 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -119,7 +119,7 @@ void cov_subfr( static void house_refl( - float *px, + const float *px, const int16_t sizex, float *pu, float *normu ) @@ -254,8 +254,9 @@ static void house_qr( * * Compute eigenvalue decomposition by QR method *---------------------------------------------------------------------*/ + void eig_qr( - float *A, + const float *A, const int16_t num_iter, float *EV, float *Vals, @@ -389,6 +390,7 @@ void exhst_4x4( * * Convert 4D matrix -> double quaternion *---------------------------------------------------------------------*/ + void mat2dquat( const float *a, float *ql, @@ -481,6 +483,7 @@ void mat2dquat( * * Convert double quaternion -> 4D matrix *---------------------------------------------------------------------*/ + void dquat2mat( const float *ql, const float *qr, @@ -543,6 +546,7 @@ void dquat2mat( * * Shortest path verification (prior to quaternion interpolation) *---------------------------------------------------------------------*/ + void quat_shortestpath( const float *q00, float *q01, @@ -600,7 +604,8 @@ void quat_shortestpath( * Compute determinant of 4D matrix - brute-force version *---------------------------------------------------------------------*/ -float mat_det4( float *m ) +float mat_det4( + const float *m ) { float d; @@ -635,17 +640,14 @@ float mat_det4( float *m ) static void norm_quat( float *q ) { - float norm_q = 0.0f; + float norm_q; int16_t i; - for ( i = 0; i < 4; i++ ) - { - norm_q += q[i] * q[i]; - } + norm_q = dotp( q, q, IVAS_PCA_INTERP ); - norm_q = 1 / sqrtf( norm_q ); + norm_q = 1 / sqrtf( norm_q ); // VE: TBV: possible division by 0 - for ( i = 0; i < 4; i++ ) + for ( i = 0; i < IVAS_PCA_INTERP; i++ ) { q[i] *= norm_q; } @@ -662,7 +664,7 @@ static void quat_nlerp_preproc( { int16_t i; - for ( i = 0; i < 4; i++ ) + for ( i = 0; i < IVAS_PCA_INTERP; i++ ) { q_slerp[i] = alpha * q0[i] + ( 1.0f - alpha ) * q1[i]; } @@ -703,14 +705,8 @@ static float acos_clip( { float ph; - if ( v > 1.0 ) - { - v = 1.0; - } - if ( v < -1.0 ) - { - v = -1.0; - } + v = check_bounds( v, -1.0f, 1.0f ); + ph = acosf( v ); return ph; @@ -835,7 +831,7 @@ static void q_ang_2surv( static void q_ang_circ( - float a, + const float a, const int16_t N, float *a_q, int16_t *index ) @@ -881,11 +877,12 @@ static void q_ang_circ( static int16_t sel_q( const float *q, - float *q_cand, + const float *q_cand, const int16_t n ) { int16_t i, i_min, j; - float d, d_min, *p, temp; + float d, d_min, temp; + const float *p; i_min = -1; d_min = 1e30f; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a1b26ac2e1a429d9bbc89c7c0a58f2a003120b0a..0b5fb14d510bc4d2123adb6486751c242f938d6e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2486,14 +2486,16 @@ float lin_interp( const int16_t flag_sat /* i : flag to indicate whether to apply saturation */ ); -void check_bounds( - float *value, /* i/o: Input value / Adjusted value */ +/*! r: Adjusted value */ +float check_bounds( + const float value, /* i : Input value */ const float low, /* i : Low limit */ const float high /* i : High limit */ ); -void check_bounds_s( - int16_t *value, /* i/o: Input value / Adjusted value */ +/*! r: Adjusted value */ +int16_t check_bounds_s( + const int16_t value, /* i : Input value */ const int16_t low, /* i : Low limit */ const int16_t high /* i : High limit */ ); @@ -3064,7 +3066,7 @@ ivas_error ivas_sba_linear_renderer( const int16_t nchan_in, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup, /* i : output format setup */ - const float hoa_dec_mtx[] /* i : hoa decoding mtx */ + const float hoa_dec_mtx[] /* i : HOA decoding mtx */ ); int16_t ivas_sba_remapTCs( @@ -3713,10 +3715,10 @@ void ivas_sba_mix_matrix_determiner( void ivas_sba_prototype_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: Input audio in CLDFB domain, real */ - float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i: Input audio in CLDFB domain, imag */ - const int16_t firstSubframe, /* i: First subframe to map */ - const int16_t nSubframes /* i: Number of subframes to map */ + float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + const int16_t firstSubframe, /* i : First subframe to map */ + const int16_t nSubframes /* i : Number of subframes to map */ ); /* AGC */ @@ -3857,6 +3859,9 @@ ivas_error ivas_spar_foa_enc_process( ivas_error ivas_spar_foa_dec_open( ivas_spar_foa_dec_state_t **hSparFoa, /* i/o: SPAR FOA decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ +#ifdef SBA_CLEANING + const int16_t sba_order, /* i : Ambisonic (SBA) order */ +#endif const int16_t nchan_internal /* i : number of internal channels */ ); @@ -4258,7 +4263,7 @@ void ivas_td_decorr_process( /* PCA */ -void init_pca_enc( +void ivas_pca_enc_init( PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ ); @@ -4276,7 +4281,7 @@ void ivas_pca_read_bits( PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ ); -void init_pca_dec( +void ivas_pca_dec_init( PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ ); @@ -4305,7 +4310,7 @@ void cov_subfr( ); void eig_qr( - float *A, + const float *A, const int16_t num_iter, float *EV, float *Vals, const int16_t n @@ -4318,7 +4323,7 @@ void exhst_4x4( ); float mat_det4( - float *m + const float *m ); /* quaternion utilities */ @@ -4746,7 +4751,7 @@ void ivas_sba2mc_cldfb( float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part */ const int16_t nb_channels_out, /* i : nb of output channels */ const int16_t nb_bands, /* i : nb of CLDFB bands to process */ - const float *hoa_dec_mtx /* i : hoa decoding mtx */ + const float *hoa_dec_mtx /* i : HOA decoding mtx */ ); void ivas_ism2sba( @@ -4993,7 +4998,7 @@ void ivas_lfe_enc( ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ const int32_t output_Fs, /* i : output sampling rate */ - const float add_delay_s /* i : additional delay in seconds to lfe to sync with binaural filter*/ + const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ ); void ivas_lfe_dec_close( @@ -5016,9 +5021,9 @@ void LFE_tdplc( ); void lfe_window_init( - LFE_WINDOW_HANDLE hLFEWindow, - const int32_t sampling_rate, - const int16_t frame_len + LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */ + const int32_t sampling_rate, /* i : sampling rate */ + const int16_t frame_len /* i : frame length in samples */ ); void ivas_lfe_lpf_select_filt_coeff( diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 7e1939aabc83021a06e90b52d14844a5d861de34..388f4e57f33dedab10d551d63170039fbc3b4570 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -53,7 +53,9 @@ #define IVAS_MDCT_SCALING_GAIN_48k 1.9699011974118126e-06f #define IVAS_MDCT_SCALING_GAIN_32k 2.9548517961177197e-06f #define IVAS_MDCT_SCALING_GAIN_16k 5.909703592235439e-06f -#define IVAS_MDCT_SCALING_GAIN_8k 0.000011819f +#ifndef SBA_CLEANING +#define IVAS_MDCT_SCALING_GAIN_8k 0.000011819f +#endif #define IVAS_FLT_EPS ( 1e-10F ) #define IVAS_DBL_EPS ( (double) 1e-20 ) @@ -157,11 +159,13 @@ float ivas_get_mdct_scaling_gain( result = IVAS_MDCT_SCALING_GAIN_16k; break; } +#ifndef SBA_CLEANING case L_FRAME8k >> 2: { result = IVAS_MDCT_SCALING_GAIN_8k; break; } +#endif default: { assert( !"Unsupported frame length!" ); @@ -266,9 +270,10 @@ int16_t ivas_get_bw_idx_from_sample_rate( *-----------------------------------------------------------------------------------------*/ void lfe_window_init( - LFE_WINDOW_HANDLE hLFEWindow, - const int32_t sampling_rate, - const int16_t frame_len ) + LFE_WINDOW_HANDLE hLFEWindow, /* i/o: LFE window handle */ + const int32_t sampling_rate, /* i : sampling rate */ + const int16_t frame_len /* i : frame length in samples */ +) { /* Set window coefficients */ if ( sampling_rate == 48000 ) @@ -292,8 +297,12 @@ void lfe_window_init( hLFEWindow->dct_len = frame_len >> 1; /* 8ms of latency */ - hLFEWindow->fade_len = (int16_t) ( sampling_rate * IVAS_LFE_FADE_LEN_SEC_FLOAT ); - hLFEWindow->zero_pad_len = (int16_t) ( IVAS_ZERO_PAD_LEN_MULT_FAC * ( hLFEWindow->dct_len - hLFEWindow->fade_len ) ); +#ifdef SBA_CLEANING + hLFEWindow->fade_len = NS2SA( sampling_rate, IVAS_LFE_FADE_NS ); +#else + hLFEWindow->fade_len = ( int16_t )( sampling_rate * IVAS_LFE_FADE_LEN_SEC_FLOAT ); +#endif + hLFEWindow->zero_pad_len = ( int16_t )( IVAS_ZERO_PAD_LEN_MULT_FAC * ( hLFEWindow->dct_len - hLFEWindow->fade_len ) ); hLFEWindow->full_len = hLFEWindow->zero_pad_len + hLFEWindow->fade_len + hLFEWindow->dct_len; return; @@ -1431,6 +1440,7 @@ static void ivas_calc_mat_inv( { double det_re; double re; + ivas_calc_mat_det( dbl_in_re, dim, &det_re ); det = ( det_re * det_re ); /* assert to catch cases when input is singular matrix*/ @@ -1457,6 +1467,7 @@ static void ivas_calc_mat_inv( ivas_calc_mat_det( dbl_in_re, dim, &det_re ); det = det_re > 0 ? 1 / max( IVAS_DBL_EPS, det_re ) : min( det_re, -IVAS_DBL_EPS ); + for ( i = 0; i < dim; i++ ) { for ( j = 0; j < dim; j++ ) diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 36a1d939d46e6b6090a952eef80aae6116074b3b..3a98931276d8e94d84f0df09258d614c940b4b07 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -575,7 +575,7 @@ typedef struct ivas_masa_qmetadata_frame_struct /* Status values on metadata quality */ int16_t ec_flag; float dir_comp_ratio; - uint8_t is_masa_type_format; // VE: use 'ivas_format' instead + uint8_t is_masa_ivas_format; } IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index f5b75dd5f61b0d07fd025e071c9d945a680690c8..079af159bc453e57fa0d0ba2621421c195c7dadd 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -510,32 +510,39 @@ float lin_interp( * Ensure the input value is within the given limits *-------------------------------------------------------------------*/ -void check_bounds( - float *value, /* i/o: Input value / Adjusted value */ - const float low, /* i : Low limit */ - const float high /* i : High limit */ +/*! r: Adjusted value */ +float check_bounds( + const float value, /* i : Input value */ + const float low, /* i : Low limit */ + const float high /* i : High limit */ ) { - *value = min( max( *value, low ), high ); + float value_adj; - return; + value_adj = min( max( value, low ), high ); + + return value_adj; } + /*-------------------------------------------------------------------* * check_bounds_s() * * Ensure the input value is within the given limits *-------------------------------------------------------------------*/ -void check_bounds_s( - int16_t *value, /* i/o: Input value / Adjusted value */ - const int16_t low, /* i : Low limit */ - const int16_t high /* i : High limit */ +/*! r: Adjusted value */ +int16_t check_bounds_s( + const int16_t value, /* i : Input value */ + const int16_t low, /* i : Low limit */ + const int16_t high /* i : High limit */ ) { - *value = min( max( *value, low ), high ); + int16_t value_adj; - return; + value_adj = min( max( value, low ), high ); + + return value_adj; } diff --git a/lib_com/options.h b/lib_com/options.h index f99ede07d234de5521941f7f7237e615e99f0b6f..17a42db2b4e483a0c5c961e07303593004f46450 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,10 @@ #define FIX_MDCT_KERNEL_RATE_SWITCHING_PLC /* force kernel that can handle ACELP -> TCX transition frame lengths for transition frames in decoder */ #define FIX_SBA_CLEAN_UP_OPT /* Fix for tickets #6, #10, #17 and #20 */ +#define SIMPLIFY_SBA_RENDERING_LOGIC /* SBA rendering maintenance related to ticket #45 */ +#define SBA_CLEANING /* SBA maintenance related to ticket #45 */ + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_com/prot.h b/lib_com/prot.h index 9ddf214eb049b1a934375e3b3f734ca89686f5cb..4357e98284a397a105acab78f16e095c440ff970 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -261,13 +261,6 @@ void AGC_dec( const int16_t n /* i : vector size */ ); -/*! r: thresholded value */ -float thr_f( - const float x, /* i : input value */ - const float x_min, /* i : lower thresholod */ - const float x_max /* o : upper threshold */ -); - /*! r: index of the maximum value in the input vector */ int16_t maximum( const float *vec, /* i : input vector */ diff --git a/lib_com/tools.c b/lib_com/tools.c index 3d08b428fd6d54631740c7f36c7304c3e6b1b72b..3e6e56d5a0aed488b98d1e843612187b7f137b69 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -499,38 +499,6 @@ void mvl2l( } -/*---------------------------------------------------------------------* - * thr_f() - * - * Thresholding of input value such that x_min < x < x_max - *---------------------------------------------------------------------*/ - -/*! r: thresholded value */ -float thr_f( - const float x, /* i : input value */ - const float x_min, /* i : lower thresholod */ - const float x_max /* o : upper threshold */ -) -{ - float y; - - if ( x < x_min ) - { - y = x_min; - } - else if ( x > x_max ) - { - y = x_max; - } - else - { - y = x; - } - - return y; -} - - /*---------------------------------------------------------------------* * maximum() * @@ -799,6 +767,7 @@ float inv_sqrt( return (float) ( 1.0 / sqrt( x ) ); } + /*-------------------------------------------------------------------* * conv() * @@ -1071,6 +1040,7 @@ int16_t usquant( return idx; } + /*-------------------------------------------------------------------* * usdequant() * diff --git a/lib_dec/ivas_crend.c b/lib_dec/ivas_crend.c index 772101ecff194ebb205ca9aca58fad6a23ca8d12..abf1269373240a43842ba2c14bcf91ddb09cbe30 100644 --- a/lib_dec/ivas_crend.c +++ b/lib_dec/ivas_crend.c @@ -79,6 +79,7 @@ static ivas_error ivas_hrtf_init( hHrtf->pOut_to_bin_im[i][j] = NULL; } } + for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { hHrtf->num_iterations_diffuse[j] = 0; @@ -90,6 +91,7 @@ static ivas_error ivas_hrtf_init( return IVAS_ERR_OK; } + /*------------------------------------------------------------------------- * ivas_hrtf_open() * @@ -106,7 +108,7 @@ static ivas_error ivas_hrtf_open( { if ( ( pState = (HRTFS_HANDLE) count_malloc( sizeof( HRTFS_DATA ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Can not allocate memory for SPAR decoder\n" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder\n" ); } ivas_hrtf_init( pState ); @@ -648,7 +650,7 @@ ivas_error ivas_crend_open( ) { int16_t i, subframe_length; - int32_t max_total_ir_len, k; + int16_t max_total_ir_len; HRTFS_HANDLE hHrtf; CREND_HANDLE hCrend; ivas_error error; @@ -704,19 +706,13 @@ ivas_error ivas_crend_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - for ( k = 0; k < max_total_ir_len; k++ ) - { - hCrend->freq_buffer_re[i][k] = 0; - } + set_f( hCrend->freq_buffer_re[i], 0, max_total_ir_len ); if ( ( hCrend->freq_buffer_im[i] = (float *) count_malloc( sizeof( float ) * max_total_ir_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - for ( k = 0; k < max_total_ir_len; k++ ) - { - hCrend->freq_buffer_im[i][k] = 0; - } + set_f( hCrend->freq_buffer_im[i], 0, max_total_ir_len ); } for ( i = 0; i < BINAURAL_CHANNELS; i++ ) @@ -725,10 +721,7 @@ ivas_error ivas_crend_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - for ( k = 0; k < subframe_length; k++ ) - { - hCrend->prev_out_buffer[i][k] = 0; - } + set_f( hCrend->prev_out_buffer[i], 0, subframe_length ); } max_total_ir_len = hHrtf->num_iterations_diffuse[0] * subframe_length; @@ -739,19 +732,13 @@ ivas_error ivas_crend_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - for ( k = 0; k < max_total_ir_len; k++ ) - { - hCrend->freq_buffer_re_diffuse[k] = 0; - } + set_f( hCrend->freq_buffer_re_diffuse, 0, max_total_ir_len ); if ( ( hCrend->freq_buffer_im_diffuse = (float *) count_malloc( sizeof( float ) * max_total_ir_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - for ( k = 0; k < max_total_ir_len; k++ ) - { - hCrend->freq_buffer_im_diffuse[k] = 0; - } + set_f( hCrend->freq_buffer_im_diffuse, 0, max_total_ir_len ); } else { @@ -766,10 +753,7 @@ ivas_error ivas_crend_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" ); } - for ( k = 0; k < max_total_ir_len; k++ ) - { - hCrend->lfe_delay_line[k] = 0; - } + set_f( hCrend->lfe_delay_line, 0, max_total_ir_len ); } else { @@ -813,7 +797,6 @@ ivas_error ivas_crend_open( st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtf->latency_s * 1000000000.f ); } - st_ivas->hCrend = hCrend; return error; @@ -915,16 +898,13 @@ static ivas_error ivas_crend_convolver( float *pFreq_buf_im; float *pFreq_filt_re; float *pFreq_filt_im; - int16_t i, j, m, nchan_out, subframe_length, nchan_intern, idx_in; + int16_t i, j, k, m, nchan_out, subframe_length, nchan_intern, idx_in; float pOut[L_FRAME48k * 2]; - float tmp_out_re[L_FRAME48k]; - float tmp_out_im[L_FRAME48k]; - int32_t offset, offset_in, offset_diffuse; - int32_t output_Fs, k; - AUDIO_CONFIG intern_config; + float tmp_out_re[L_FRAME48k], tmp_out_im[L_FRAME48k]; + int16_t offset, offset_in, offset_diffuse; + int32_t output_Fs; - intern_config = st_ivas->intern_config; - nchan_intern = audioCfg2channels( intern_config ); + nchan_intern = audioCfg2channels( st_ivas->intern_config ); nchan_out = st_ivas->hDecoderConfig->nchan_out; output_Fs = st_ivas->hDecoderConfig->output_Fs; subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 7527209028ab322f0747fdc5739c6d412cc216a8..5b6d95e5e8cc187aa112ec4ccb850d859283dd2e 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -221,8 +221,7 @@ ivas_error ivas_dec( set_s( nb_bits_metadata, 0, MAX_SCE ); /* read parameters from the bitstream */ - if ( ( st_ivas->hQMetaData != NULL ) && - ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + if ( st_ivas->hQMetaData != NULL && st_ivas->sba_mode != SBA_MODE_SPAR ) { st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; @@ -240,17 +239,16 @@ ivas_error ivas_dec( } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { - if ( ( st_ivas->hQMetaData != NULL ) && ( SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ) ) + if ( st_ivas->hQMetaData != NULL ) { st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; #ifndef FIX_SBA_CLEAN_UP_OPT - ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], - st_ivas->sba_mode, st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands ); + ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], st_ivas->sba_mode, st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands ); #else - ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], - st_ivas->sba_mode, st_ivas->hSpar->dirac_to_spar_md_bands ); + ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], st_ivas->sba_mode, st_ivas->hSpar->dirac_to_spar_md_bands ); #endif } + if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK ) { return error; @@ -330,11 +328,32 @@ ivas_error ivas_dec( } /* Loudspeakers, Ambisonics or Binaural rendering */ +#ifdef SIMPLIFY_SBA_RENDERING_LOGIC + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + ivas_dirac_dec_binaural( st_ivas, output, nchan_remapped ); + } + else if( st_ivas->sba_mode == SBA_MODE_DIRAC || st_ivas->ivas_format == MASA_FORMAT ) + { + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) + { + ivas_sba_linear_renderer( output, output_frame, nchan_remapped, output_config, st_ivas->hOutSetup, st_ivas->hoa_dec_mtx ); + } + else if ( st_ivas->renderer_type == RENDERER_DIRAC ) + { + ivas_dirac_dec( st_ivas, output, nchan_remapped, NULL, NULL, -1 ); + } + } + else /* SBA_MODE_SPAR */ + { + ivas_sba_upmixer_renderer( st_ivas, output, nchan_remapped, output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */ + } +#else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode == SBA_MODE_DIRAC ) { ivas_sba_linear_renderer( output, output_frame, nchan_remapped, output_config, st_ivas->hOutSetup, st_ivas->hoa_dec_mtx ); } - else if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) + else if ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->sba_mode != SBA_MODE_SPAR ) { ivas_dirac_dec( st_ivas, output, nchan_remapped, NULL, NULL, -1 ); } @@ -348,6 +367,7 @@ ivas_error ivas_dec( { ivas_sba_upmixer_renderer( st_ivas, output, nchan_remapped, output_frame ); } +#endif } else if ( st_ivas->ivas_format == MC_FORMAT ) { @@ -477,8 +497,7 @@ ivas_error ivas_dec( /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */ if ( output_config == AUDIO_CONFIG_5_1 || output_config == AUDIO_CONFIG_7_1 || output_config == AUDIO_CONFIG_5_1_4 || output_config == AUDIO_CONFIG_7_1_4 || - output_config == AUDIO_CONFIG_5_1_2 || - ( output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) + output_config == AUDIO_CONFIG_5_1_2 || ( output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) { ivas_lfe_synth_with_filters( st_ivas->hMasa->hMasaLfeSynth, output, output_frame, n, LFE_CHANNEL ); } @@ -572,7 +591,7 @@ ivas_error ivas_dec( { st_ivas->ini_frame++; } - if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_4k4 ) + if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_4k4 ) // VE: looks strange: ini_frame -> ini_frame_active ? { st_ivas->ini_active_frame++; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index d18a013df206dd8a7e46ddb1e0d0d25dfa5380a2..1a5094fadf577a966bb3bbbbd5f22c151dd7a684 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1342,7 +1342,6 @@ void ivas_dirac_dec_read_BS( *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT, sba_mode ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; @@ -1365,7 +1364,7 @@ void ivas_dirac_dec_read_BS( else { hQMetaData->sba_inactive_mode = 0; - hQMetaData->is_masa_type_format = 0; + hQMetaData->is_masa_ivas_format = 0; if ( hQMetaData->useLowerRes ) { hQMetaData->q_direction[0].cfg.nblocks = 1; @@ -1827,7 +1826,7 @@ void ivas_dirac_dec( set_zero( onset_filter_subframe, hDirAC->num_freq_bands ); } - if ( ( st_ivas->hHeadTrackData ) ) + if ( st_ivas->hHeadTrackData ) { QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[st_ivas->hHeadTrackData->num_quaternions++], st_ivas->hHeadTrackData->Rmat ); @@ -1896,6 +1895,7 @@ void ivas_dirac_dec( set_zero( surCohRatio, hDirAC->num_freq_bands ); } } + if ( st_ivas->hDecoderConfig->Opt_Headrotation && st_ivas->hHeadTrackData->shd_rot_max_order == 1 ) { ivas_dirac_dec_compute_directional_responses( hDirAC, @@ -1944,6 +1944,7 @@ void ivas_dirac_dec( st_ivas->cldfbAnaDec[ch] ); } } + /* CNG in DirAC, extra CLDFB ana for CNA*/ if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->sba_mode != SBA_MODE_SPAR ) { @@ -1956,7 +1957,7 @@ void ivas_dirac_dec( Cldfb_ImagBuffer[1][0], index_slot, st->cna_dirac_flag && st->flag_cna, - ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && ( st->cng_type == FD_CNG ) && st->cng_dirac_flag ); + ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == FD_CNG && st->cng_dirac_flag ); } /* LFE synthesis */ @@ -2054,6 +2055,7 @@ void ivas_dirac_dec( /*-----------------------------------------------------------------* * Compute DirAC parameters at decoder side *-----------------------------------------------------------------*/ + if ( hDirAC->hConfig->dec_param_estim == TRUE ) { hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ @@ -2233,11 +2235,13 @@ void ivas_dirac_dec( { v_add( reference_power, reference_power_smooth, reference_power_smooth, hDirAC->num_freq_bands ); } + if ( hDirAC->hConfig->dec_param_estim ) { hDirAC->dirac_read_idx = ( hDirAC->dirac_read_idx + 1 ) % hDirAC->dirac_md_buffer_length; } } + if ( hDirAC->hConfig->dec_param_estim == 0 ) { hDirAC->dirac_read_idx = ( hDirAC->dirac_read_idx + 1 ) % hDirAC->dirac_md_buffer_length; diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index a3dd0472acdc62a7efee52f58caa880004629b12..fd9233c4f9cf358744f9d64689eac7761a4572b1 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -315,7 +315,7 @@ void ivas_lfe_dec( ivas_filter_process( &hLFE->filter_state, output_lfe_ch, output_frame ); } - /* ADD delay to make overall max(block_offset, 11.5)*/ + /* add delay to make overall max(block_offset, 11.5) */ if ( hLFE->lfe_addl_delay > 0 ) { delay_signal( output_lfe_ch, output_frame, hLFE->lfe_delay_buf, hLFE->lfe_addl_delay ); @@ -332,9 +332,9 @@ void ivas_lfe_dec( *-------------------------------------------------------------------------*/ ivas_error ivas_create_lfe_dec( - LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ - const int32_t output_Fs, /* i : output sampling rate */ - const float add_delay_s /* additional delay in second to lfe to sync with binaural filter*/ + LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ + const int32_t output_Fs, /* i : output sampling rate */ + const float add_delay_s /* i : additional LFE delay to sync with binaural filter */ ) { float low_pass_delay_dec_out, block_offset_s; @@ -379,7 +379,11 @@ ivas_error ivas_create_lfe_dec( hLFE->cum_freq_models[1][3] = &ivas_str_lfe_freq_models.entropy_coder_model_coarse_sg4; /* delay calculation */ +#ifdef SBA_CLEANING + hLFE->lfe_block_delay_s = ( IVAS_LFE_FADE_NS / 1000000000.f ) + ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3]; +#else hLFE->lfe_block_delay_s = IVAS_LFE_FADE_LEN_SEC_FLOAT + ivas_lfe_lpf_delay[IVAS_FILTER_ORDER_4 - 3]; +#endif block_offset_s = BLOCK_OFFSET_MS * 0.001f; @@ -409,8 +413,13 @@ ivas_error ivas_create_lfe_dec( { hLFE->filter_state.order = filt_order; } + hLFE->lfe_block_delay_s = hLFE->lfe_block_delay_s + low_pass_delay_dec_out; +#ifdef SBA_CLEANING + hLFE->lfe_prior_buf_len = NS2SA( output_Fs, IVAS_LFE_FADE_NS ); +#else hLFE->lfe_prior_buf_len = (int16_t) ( IVAS_LFE_FADE_LEN_SEC_FLOAT * output_Fs ); +#endif hLFE->bfi_count = 0; @@ -432,7 +441,6 @@ ivas_error ivas_create_lfe_dec( hLFE->lfe_delay_buf = NULL; } - *hLFE_out = hLFE; return IVAS_ERR_OK; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 77756b1630c7047a73a006d9e7f1b2d4576a6b2a..4c1a39649d70223aa6763e35a7191af52b195cf2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -111,7 +111,7 @@ ivas_error ivas_masa_decode( ivas_format = st_ivas->ivas_format; hMasa->data.dir_decode_quality = 1.0f; /* Set to default of max quality */ - hQMetaData->is_masa_type_format = 1; + hQMetaData->is_masa_ivas_format = 1; *nb_bits_read = 0; next_bit_pos_orig = st->next_bit_pos; diff --git a/lib_dec/ivas_output_init.c b/lib_dec/ivas_output_init.c index 86dc17d1741114cc31cf37bf7a41a42c6859fd48..4398b3cb9378f3fbbf7370ed6edb379e20734f73 100644 --- a/lib_dec/ivas_output_init.c +++ b/lib_dec/ivas_output_init.c @@ -352,6 +352,7 @@ void ivas_renderer_select( { *renderer_type = RENDERER_BINAURAL_FASTCONV_ROOM; } + if ( st_ivas->hDecoderConfig->Opt_Headrotation ) { if ( st_ivas->nchan_transport == 2 ) @@ -437,7 +438,7 @@ void ivas_renderer_select( { *renderer_type = RENDERER_BINAURAL_FASTCONV_ROOM; } -#if defined( DEBUGGING ) +#ifdef DEBUGGING if ( st_ivas->hRenderConfig->renderer_type_override == RENDER_TYPE_OVERRIDE_CREND ) { *renderer_type = RENDERER_BINAURAL_MIXER_CONV_ROOM; @@ -542,6 +543,7 @@ void ivas_renderer_select( { nchan_max = ivas_sba_get_nchan( 3, st_ivas->sba_planar ); } + if ( st_ivas->nchan_transport >= nchan_max ) { *renderer_type = RENDERER_SBA_LINEAR_DEC; diff --git a/lib_dec/ivas_pca_dec.c b/lib_dec/ivas_pca_dec.c index 8ceb6ae0e57a96fb074dfad1a939be2144fd259f..ef5694d6561ca775bba2f7b1b7ef914f3e833087 100644 --- a/lib_dec/ivas_pca_dec.c +++ b/lib_dec/ivas_pca_dec.c @@ -62,25 +62,6 @@ static int32_t ivas_bitstream_read_int32( } -void ivas_pca_read_bits( - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - PCA_DEC_STATE *hPCA ) -{ - /*first bit in the PCA payload (first bit after 3 header bits) signals bypass/active*/ - hPCA->pca_bypass = get_next_indice( st0, 1 ); - - if ( hPCA->pca_bypass == PCA_MODE_INACTIVE ) - { - return; - } - - hPCA->index[0] = ivas_bitstream_read_int32( st0, IVAS_PCA_QBITS - 1 ); - hPCA->index[1] = ivas_bitstream_read_int32( st0, IVAS_PCA_QBITS ); - - return; -} - - static void pca_dec_reset_dquat( float *ql, float *qr ) @@ -126,6 +107,7 @@ static void pca_inv_transform_sub( { buffer_data[k] = transformed_data[k][j + start]; } + for ( k = 0; k < n_channels; k++ ) { temp = 0.0f; @@ -158,14 +140,16 @@ static void pca_dec_inv_transform( pca_interp_preproc( hPCA->prev_ql, hPCA->prev_qr, ql, qr, IVAS_PCA_N_SLOTS, ql_interp, qr_interp ); slot_len = (int16_t) ( n_samples / IVAS_PCA_N_SLOTS ); + for ( j = 0; j < IVAS_PCA_N_SLOTS; j++ ) { /* convert from double quaternion to 4D matrix */ dquat2mat( &ql_interp[4 * j], &qr_interp[4 * j], &hPCA->mem_eigVec_interp[16 * j + IVAS_PCA_DELAY_CMP * 16] ); - pca_inv_transform_sub( &hPCA->mem_eigVec_interp[16 * j], decoded_data, - slot_len * j, slot_len, n_channels ); + pca_inv_transform_sub( &hPCA->mem_eigVec_interp[16 * j], decoded_data, slot_len * j, slot_len, n_channels ); } + + return; } @@ -183,12 +167,12 @@ static void pca_dec_update_dquat( /*------------------------------------------------------------------------- - * init_pca_dec() + * ivas_pca_dec_init() * - * initialize PCA decoder + * Initialize PCA decoder *------------------------------------------------------------------------*/ -void init_pca_dec( +void ivas_pca_dec_init( PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ ) { @@ -202,6 +186,31 @@ void init_pca_dec( } +/*------------------------------------------------------------------------- + * ivas_pca_read_bits() + * + * Decode PCA indexes + *------------------------------------------------------------------------*/ + +void ivas_pca_read_bits( + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + PCA_DEC_STATE *hPCA ) +{ + /*first bit in the PCA payload (first bit after 3 header bits) signals bypass/active*/ + hPCA->pca_bypass = get_next_indice( st0, 1 ); + + if ( hPCA->pca_bypass == PCA_MODE_INACTIVE ) + { + return; + } + + hPCA->index[0] = ivas_bitstream_read_int32( st0, IVAS_PCA_QBITS - 1 ); + hPCA->index[1] = ivas_bitstream_read_int32( st0, IVAS_PCA_QBITS ); + + return; +} + + /*------------------------------------------------------------------------- * ivas_pca_dec() * @@ -218,8 +227,9 @@ void ivas_pca_dec( float pcm_out[][L_FRAME48k] /* o : output audio channels */ ) { - float ql[4], qr[4]; + float ql[IVAS_PCA_INTERP], qr[IVAS_PCA_INTERP]; int16_t pca_bypass; + mvr2r( &hPCA->mem_eigVec_interp[IVAS_PCA_N_SLOTS * 16], hPCA->mem_eigVec_interp, IVAS_PCA_DELAY_CMP * 16 ); /* @@@TODO: check how ivas_total_brate is set if bfi == 1 */ // VE: and what happens in DTX where "ivas_total_brate" can be close to zero? diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index e8b3ca4d7c4bbd36a629428a0d1784e37913f902..2d5a8b47032c814a6b56e019bc328ab9db0b6d06 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -513,7 +513,7 @@ int16_t ivas_qmetadata_dec_decode( int16_t dummy; ec_flag = 2; - if ( hQMetaData->is_masa_type_format == 0 ) + if ( hQMetaData->is_masa_ivas_format == 0 ) { reduce_bits = bits_dir_raw - ( total_bits_1dir - bits_diff - bits_coherence - signal_bits ); ind_order[0] = -1; diff --git a/lib_dec/ivas_reverb.c b/lib_dec/ivas_reverb.c index 12dec394dfe24a1715842de7833bae71e43082b4..e68cbc714fa672ff3494fc3ceb9cddd6254e2e84 100644 --- a/lib_dec/ivas_reverb.c +++ b/lib_dec/ivas_reverb.c @@ -369,7 +369,7 @@ static void calc_predelay( int16_t fbdelay; int16_t output_frame; - fbdelay = (int16_t) pParams->pLoop_delays[0]; + fbdelay = pParams->pLoop_delays[0]; predelay = (int16_t) round( acoustic_predelay_sec * output_Fs ); output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); @@ -423,7 +423,6 @@ static ivas_error compute_t60_coeffs( error = IVAS_ERR_OK; tf_T60_len = nr_fc_fft_filter; - if ( pParams->t60_is_iir == FALSE ) { return IVAS_ERR_INTERNAL; /* only IIR supported */ @@ -505,6 +504,7 @@ static void calc_low_shelf_first_order_filter( pDen[0] = 1 + w0 / g; pDen[1] = w0 / g - 1; } + pNum[0] = pNum[0] / pDen[0]; pNum[1] = pNum[1] / pDen[0]; pDen[1] = pDen[1] / pDen[0]; diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index e0e55002fe2f28048011ca960898add1230de072..a364a60d5212504f0bceefbe72490b091ba363ce 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -150,7 +150,7 @@ void ivas_sba2mc_cldfb( float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part */ const int16_t nb_channels_out, /* i : nb of output channels */ const int16_t nb_bands, /* i : nb of CLDFB bands to process */ - const float *hoa_dec_mtx /* i : hoa decoding mtx */ + const float *hoa_dec_mtx /* i : HOA decoding mtx */ ) { int16_t iBlock, iBand, n, m; diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 25bf71d906e67bc54563ee765f912a7610b5a061..e565145a0b3f3eff114325a22160950fc1c4b309 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -62,7 +62,7 @@ ivas_error ivas_sba_linear_renderer( const int16_t nchan_in, /* i : number of input ambisonics channels */ const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup, /* i : output format setup */ - const float hoa_dec_mtx[] /* i : hoa decoding mtx */ + const float hoa_dec_mtx[] /* i : HOA decoding mtx */ ) { int16_t i; @@ -147,7 +147,7 @@ static void ivas_sba_mtx_mult( const int16_t output_frame, /* i : output frame length per channel */ const int16_t nchan_in, /* i : Number of ambisonic channels */ IVAS_OUTPUT_SETUP output_setup, /* i : Output configuration */ - const float *mtx_hoa_decoder /* i : Hoa decoding mtx */ + const float *mtx_hoa_decoder /* i : HOA decoding mtx */ ) { int16_t i, k, ch_idx; @@ -199,7 +199,7 @@ static void ivas_sba_mtx_mult( /*-------------------------------------------------------------------* * ivas_sba_upmixer_renderer() * - * SBA upmix rendering + * SBA upmix & rendering *-------------------------------------------------------------------*/ void ivas_sba_upmixer_renderer( @@ -210,7 +210,11 @@ void ivas_sba_upmixer_renderer( ) { int16_t i, ch, nchan_out; +#ifdef SIMPLIFY_SBA_RENDERING_LOGIC + float temp; +#else float clip, temp; +#endif int16_t nchan_internal; wmops_sub_start( "ivas_sba_upmixer_renderer" ); @@ -249,39 +253,50 @@ void ivas_sba_upmixer_renderer( } } +#ifdef SIMPLIFY_SBA_RENDERING_LOGIC + /* Upmixer + Renderer */ +#else /* Upmixer */ +#endif #ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_upmixer( st_ivas, output, nchan_internal, output_frame ); #else ivas_spar_dec_upmixer( st_ivas, output, nchan_internal, output_frame ); #endif +#ifndef SIMPLIFY_SBA_RENDERING_LOGIC /* Renderer */ if ( st_ivas->hDirAC != NULL && st_ivas->renderer_type == RENDERER_DIRAC ) { nchan_out = st_ivas->hDirAC->hOutSetup.nchan_out_woLFE + st_ivas->hDirAC->hOutSetup.num_lfe; } - +#endif if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) { ivas_sba_linear_renderer( output, output_frame, st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup, st_ivas->hoa_dec_mtx ); } +#ifndef SIMPLIFY_SBA_RENDERING_LOGIC clip = 1.0f; +#endif for ( ch = 0; ch < nchan_out; ch++ ) { for ( i = 0; i < output_frame; i++ ) { +#ifndef SIMPLIFY_SBA_RENDERING_LOGIC clip = max( clip, fabsf( output[ch][i] ) ); +#endif output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; } } +#ifndef SIMPLIFY_SBA_RENDERING_LOGIC #ifdef DEBUGGING if ( clip > 1.0f ) { fprintf( stderr, "IVAS Crend Clipped: max gain = %f\n", clip ); } +#endif #endif wmops_sub_end(); diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 3316da9af03f4037da066d571d8675a6ee4545d4..c208fc6511c88b2586f466a1f87fc57647b4bb70 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -49,7 +49,7 @@ /*------------------------------------------------------------------------- * ivas_spar_dec_open() * - * Allocate and initialize SPAR handle + * Allocate and initialize SPAR decoder handle and sub-handles *------------------------------------------------------------------------*/ ivas_error ivas_spar_dec_open( @@ -66,15 +66,10 @@ ivas_error ivas_spar_dec_open( #endif error = IVAS_ERR_OK; - sba_order_internal = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); - num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); - /*-----------------------------------------------------------------* - * Allocate and initialize SPAR handle - *-----------------------------------------------------------------*/ - + /* SPAR decoder handle */ if ( ( hSpar = (SPAR_DEC_HANDLE) count_malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" ); @@ -124,19 +119,25 @@ ivas_error ivas_spar_dec_open( return error; } - /* AGC */ + /* AGC handle */ if ( ( error = ivas_spar_agc_dec_open( &hSpar->hAgcDec, output_Fs ) ) != IVAS_ERR_OK ) { return error; } - /* PCA */ - if ( ( hSpar->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + /* PCA handle */ +#ifdef SBA_CLEANING + hSpar->hPCA = NULL; + if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 ) +#endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); - } + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } - init_pca_dec( hSpar->hPCA ); + ivas_pca_dec_init( hSpar->hPCA ); + } /* mixer_mat intitialization */ for ( i = 0; i < num_channels_internal; i++ ) diff --git a/lib_dec/ivas_spar_foa_dec.c b/lib_dec/ivas_spar_foa_dec.c index 0106af6f4d9a9c4119d75ccf2c61fd112e8559bf..70426f276e576b6f2c578e988a096974157b3bb6 100644 --- a/lib_dec/ivas_spar_foa_dec.c +++ b/lib_dec/ivas_spar_foa_dec.c @@ -393,6 +393,9 @@ void ivas_spar_get_cldfb_gains( ivas_error ivas_spar_foa_dec_open( ivas_spar_foa_dec_state_t **hSparFoa, /* i/o: SPAR FOA decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ +#ifdef SBA_CLEANING + const int16_t sba_order, /* i : Ambisonic (SBA) order */ +#endif const int16_t nchan_internal /* i : number of internal channels */ ) { @@ -447,12 +450,18 @@ ivas_error ivas_spar_foa_dec_open( } /* PCA */ - if ( ( pState->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) +#ifdef SBA_CLEANING + pState->hPCA = NULL; + if ( hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order == 1 ) +#endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); - } + if ( ( pState->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } - init_pca_dec( pState->hPCA ); + ivas_pca_dec_init( pState->hPCA ); + } /* mixer_mat intitialization */ for ( i = 0; i < nchan_internal; i++ ) @@ -596,12 +605,10 @@ void ivas_spar_dec_MD( sba_order = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); bfi = st_ivas->bfi; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - num_channels = ivas_sba_get_nchan_metadata( sba_order ); - num_bands_out = pState->hFbMixer->pFb->filterbank_num_bands; - if ( ivas_total_brate > FRAME_NO_DATA && bfi != 1 ) + if ( ivas_total_brate > FRAME_NO_DATA && !bfi ) { if ( ivas_total_brate > IVAS_SID_5k ) { @@ -622,7 +629,6 @@ void ivas_spar_dec_MD( } } - /*---------------------------------------------------------------------* * Decode MD *---------------------------------------------------------------------*/ @@ -637,20 +643,26 @@ void ivas_spar_dec_MD( * read PCA bits *---------------------------------------------------------------------*/ +#ifdef SBA_CLEANING + if ( pState->hPCA != NULL ) +#else if ( hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order == 1 ) +#endif { ivas_pca_read_bits( st0, pState->hPCA ); } +#ifndef SBA_CLEANING else { pState->hPCA->pca_bypass = PCA_MODE_INACTIVE; } +#endif /*---------------------------------------------------------------------* * Read AGC bits *---------------------------------------------------------------------*/ - if ( ivas_total_brate > IVAS_SID_5k && !bfi && ( pState->hMdDec->dtx_vad == 1 ) ) + if ( ivas_total_brate > IVAS_SID_5k && !bfi && pState->hMdDec->dtx_vad ) { pState->AGC_flag = get_next_indice( st0, 1 ); @@ -741,7 +753,6 @@ static float ivas_spar_get_cldfb_slot_gain( output_Fs = (float) hDecoderConfig->output_Fs; encfb_delay = IVAS_FB_ENC_DELAY_NS; decfb_delay = IVAS_FB_DEC_DELAY_NS; - // VE: overcomplicated logic -> rewrite xfade_start_ns = pState->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f; xfade_delay_subframes = (int16_t) ( xfade_start_ns / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); @@ -951,7 +962,7 @@ void ivas_spar_foa_dec_upmixer( /*-------------------------------------------------------------------* * ivas_spar_foa_dec_upmixer() * - * IVAS SPAR FOA upmixer + * IVAS SPAR upmixer *-------------------------------------------------------------------*/ void ivas_spar_dec_upmixer( @@ -1085,7 +1096,12 @@ void ivas_spar_dec_upmixer( * PCA decoder *---------------------------------------------------------------------*/ - ivas_pca_dec( pState->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); +#ifdef SBA_CLEANING + if ( pState->hPCA != NULL ) +#endif + { + ivas_pca_dec( pState->hPCA, output_frame, num_in_ingest, hDecoderConfig->ivas_total_brate, hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output ); + } /*---------------------------------------------------------------------* * TD decorrelation @@ -1246,9 +1262,13 @@ void ivas_spar_dec_upmixer( if ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) { +#ifdef SBA_CLEANING + ivas_dirac_dec( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im, i_sf ); +#else nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_order ); // VE: == nchan_internal that is already set correctly ivas_dirac_dec( st_ivas, output, nchan_transport, cldfb_in_ts_re, cldfb_in_ts_im, i_sf ); +#endif } if ( st_ivas->hDirAC != NULL ) @@ -1330,7 +1350,6 @@ void ivas_spar_dec_upmixer( } } - wmops_sub_end(); return; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e7875d7c29c8590ef6b39679c538b366f4d46b70..e7bb2e12672b6ddb962f56df43b7914948a8c451 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1369,7 +1369,7 @@ typedef struct ivas_binaural_rendering_struct /* Common variables for all modules */ IVAS_OUTPUT_SETUP_HANDLE hInputSetup; /* pointer to input spatial format for binaural renderer*/ EFAP_HANDLE hEFAPdata; /* EFAP structure*/ - float *hoa_dec_mtx; /* pointer to hoa decoder mtx */ + float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ int16_t max_band; /* band upto which rendering is performed */ int16_t conv_band; /* band upto which convolution in cldfb domain is performed */ diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index fbdfab03720dd1571758943663ba2986ef0b1959..074efaa1a262340aa39753d0dfff02cea7b18abe 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -101,8 +101,8 @@ static void stereo_dft_dequantize_res_gains( for ( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - check_bounds_s( &ind1[i], 0, 30 ); - check_bounds_s( &ind2[i], 0, 7 ); + ind1[i] = check_bounds_s( ind1[i], 0, 30 ); + ind2[i] = check_bounds_s( ind2[i], 0, 7 ); index = ( ( ind1[i] < 15 ? 15 - ind1[i] : ind1[i] - 15 ) << 3 ) + ind2[i]; gout[i] = ind1[i] < 15 ? -dft_res_gains_q[index][0] : dft_res_gains_q[index][0]; rout[i] = dft_res_gains_q[index][1]; @@ -130,8 +130,8 @@ static void stereo_dft_dequantize_res_gains_f( for ( i = 0; i < N; i++ ) { /* Ensure the indices are within range -- may go out of range due to frame loss */ - check_bounds( &ind1[i], 0, 31 ); - check_bounds( &ind2[i], 0, 7 ); + ind1[i] = check_bounds( ind1[i], 0, 31 ); + ind2[i] = check_bounds( ind2[i], 0, 7 ); /* compensate for the offset and extract/remove sign of first index */ sign = ind1[i] < 15 ? -1 : 1; diff --git a/lib_dec/ivas_vbap.c b/lib_dec/ivas_vbap.c index a2f89e08091046e7f6d75c0950d35d63d271c8f1..a173e627ee5deb23e2716e78d7d13421f731726a 100644 --- a/lib_dec/ivas_vbap.c +++ b/lib_dec/ivas_vbap.c @@ -46,8 +46,6 @@ * Local constants *-----------------------------------------------------------------------*/ -#define VBAP_SUB_FUNCTION_MEMORY_INIT_FAIL ( -1 ) - /* 128 is maximum num_speaker_nodes number. This relates to memory optimization and maximum of triplets: - triplet indices are unsigned_char (see below structs) --> max triplets is 256 - num_speaker_nodes_internal = num_speaker_nodes + 2 (potential virtual node channels, bottom and top) @@ -1002,7 +1000,7 @@ static int16_t check_and_store_triplet( /* Get center azimuth for fast search use */ triplet_azidegs[*triplet_index] = atan2f( speaker_node_data[chA].unit_vec[1] + speaker_node_data[chB].unit_vec[1] + speaker_node_data[chC].unit_vec[1], speaker_node_data[chA].unit_vec[0] + speaker_node_data[chB].unit_vec[0] + speaker_node_data[chC].unit_vec[0] ) * - 180.0f / EVS_PI; + _180_OVER_PI; /* Store increasing order indices for the later sorting step. */ triplet_order[*triplet_index] = *triplet_index; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 79b83e5c68d6336a0cefb4e82b4d904b9ad24a8d..a0c863cc4b2568bcb2b88af7f415e701a82a4573 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -1995,7 +1995,7 @@ void fb_tbe_dec( } else { - i = get_next_indice( st, 4 ); + i = get_next_indice( st, NUM_BITS_FB_FRAMEGAIN_TBE ); } ratio = (float) ( 1 << i ); } diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index aeefb3116c3d194019639f52d24696defe7f4b09..fdfac29703c9887423f23aa36e6b6be9804bf0f6 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -442,7 +442,7 @@ void dtx( tmpBandwidthMin = WB; } - check_bounds_s( &( st->bwidth ), tmpBandwidthMin, FrameSizeConfig[n].bandwidth_max ); + st->bwidth = check_bounds_s( st->bwidth, tmpBandwidthMin, FrameSizeConfig[n].bandwidth_max ); } } @@ -493,7 +493,7 @@ static void update_SID_cnt( { hDtxEnc->interval_SID = INT_L + (int16_t) ( ( INT_H - INT_L ) * ( EstimatedSNR - SNR_L ) / ( SNR_H - SNR_L ) ); } - check_bounds_s( &( hDtxEnc->interval_SID ), INT_L, INT_H ); + hDtxEnc->interval_SID = check_bounds_s( hDtxEnc->interval_SID, INT_L, INT_H ); if ( !Opt_AMR_WB || hDtxEnc->max_SID != 3 ) { diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 9d355b83707b96b839a277393d294ff383517f83..cd321ef06c06d236ff5dfca20bc32cad2eda8426 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -646,13 +646,6 @@ ivas_error init_encoder( if ( !st->Opt_RF_ON || ( st->bwidth != WB && st->bwidth != SWB ) || st->total_brate != ACELP_13k20 ) { - if ( st->Opt_RF_ON ) - { // VE: this should be printed outside of library - printf( "\nWarning: Channel-aware mode only available for 13.2 kbps WB/SWB\n" ); - printf( " Switched to normal mode!\n" ); - st->Opt_RF_ON = 0; - st->rf_fec_offset = 0; - } st->rf_mode = 0; } else diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 6ad0e5bef255b6042032f3754660304ed6a4c976..feb164d201c2306a3a81f38abeadfca352324aaa 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -353,12 +353,20 @@ ivas_error ivas_create_lfe_enc( * Input memory buffer: allocate and initialize *-----------------------------------------------------------------*/ +#ifdef SBA_CLEANING + if ( ( hLFE->old_wtda_audio = (float *) count_malloc( sizeof( float ) * NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ) ) == NULL ) +#else if ( ( hLFE->old_wtda_audio = (float *) count_malloc( sizeof( float ) * (int16_t) ( input_Fs * IVAS_LFE_FADE_LEN_SEC_FLOAT ) ) ) == NULL ) +#endif { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n" ) ); } +#ifdef SBA_CLEANING + set_zero( hLFE->old_wtda_audio, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ); +#else set_zero( hLFE->old_wtda_audio, (int16_t) ( input_Fs * IVAS_LFE_FADE_LEN_SEC_FLOAT ) ); +#endif /*-----------------------------------------------------------------* * LFE Window: allocate and initialize diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index cda908a49b1365de8c52f7aedc60ae2fb8a358f1..2e233bbc6d6f89cad5c20b260907bf4d2e2e173e 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -478,7 +478,8 @@ ivas_error ivas_masa_enc_config( ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); - hQMetaData->is_masa_type_format = 1; + hQMetaData->is_masa_ivas_format = 1; + if ( ivas_format == MASA_FORMAT ) { /* Inspect metadata for parameter changes that affect coding. */ diff --git a/lib_enc/ivas_pca_enc.c b/lib_enc/ivas_pca_enc.c index 6694a36f25b9a2e8480b68440b58f5ae56bfa27b..c6b804088e6e4b6e62903122c31f9bb7ea8ba36a 100644 --- a/lib_enc/ivas_pca_enc.c +++ b/lib_enc/ivas_pca_enc.c @@ -95,29 +95,6 @@ static void pca_enc_reset( } -/*------------------------------------------------------------------------- - * ivas_pca_enc() - * - * Initialize PCA encoder - *------------------------------------------------------------------------*/ - -void init_pca_enc( - PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ -) -{ - hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; - pca_enc_reset( hPCA ); - - return; -} - - -/*------------------------------------------------------------------------- - * pca_transform_sub() - * - * - *------------------------------------------------------------------------*/ - static void pca_transform_sub( float *eigVec, float *transformed_data[8], /* i : input/transformed audio channels */ @@ -264,6 +241,23 @@ static void sort4_D_eigVec( } +/*------------------------------------------------------------------------- + * ivas_pca_enc_init() + * + * Initialize PCA encoder + *------------------------------------------------------------------------*/ + +void ivas_pca_enc_init( + PCA_ENC_STATE *hPCA /* i/o: PCA encoder structure */ +) +{ + hPCA->prev_bypass_decision = PCA_MODE_INACTIVE; + pca_enc_reset( hPCA ); + + return; +} + + /*------------------------------------------------------------------------- * ivas_pca_enc() * diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 8a10750e11651c423e5ec0d5dd4573a83ca96395..d73763ceefaf32adb9a53fdcd78d5bd402b363e7 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -418,7 +418,7 @@ ivas_error ivas_qmetadata_enc_encode( bits_dir_bands[0] = ivas_qmetadata_raw_encode_dir( NULL, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); - reduce_bits = hQMetaData->is_masa_type_format ? ( total_bits_1dir - ( bits_diff[d] + bits_coherence[d] + bits_signalling[d] ) - 1 ) : MASA_MAX_BITS; + reduce_bits = hQMetaData->is_masa_ivas_format ? ( total_bits_1dir - ( bits_diff[d] + bits_coherence[d] + bits_signalling[d] ) - 1 ) : MASA_MAX_BITS; bits_ec = ivas_qmetadata_entropy_encode_dir( hMetaData, q_direction, diffuseness_index_max_ec_frame, q_direction->cfg.nbands, q_direction->cfg.start_band, bits_dir_bands[0], reduce_bits ); @@ -534,7 +534,8 @@ ivas_error ivas_qmetadata_enc_encode( { bits_signalling[d] = 2; } - if ( hQMetaData->is_masa_type_format == 0 ) + + if ( hQMetaData->is_masa_ivas_format == 0 ) { reduce_bits = bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signalling[d] ); ind_order[0] = -1; @@ -549,6 +550,7 @@ ivas_error ivas_qmetadata_enc_encode( reduce_bits = bits_dir_raw - nbands * nblocks; } } + only_reduce_bits_direction( &extra_bits, q_direction, reduce_bits, nbands, nblocks, ind_order ); bits_dir[d] = hMetaData->nb_bits_tot; requantize_direction_EC_3( &extra_bits, q_direction, nbands, hMetaData, elevation_orig, azimuth_orig, ind_order ); @@ -639,6 +641,7 @@ ivas_error ivas_qmetadata_enc_encode( mvr2r( q_direction->band_data[i].azimuth, q_direction->band_data[i].q_azimuth, nblocks ); mvr2r( q_direction->band_data[i].elevation, q_direction->band_data[i].q_elevation, nblocks ); } + /* Copy original DOAs back to q_direction*/ for ( i = start_band; i < nbands; i++ ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 04bb15e2552d66bd079ed39c7b24c2e10ee122f5..448cd248c6d2dd383f279081b44b8b6c048be890 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -46,7 +46,7 @@ /*------------------------------------------------------------------------- * ivas_spar_enc_open() * - * Allocate and initialize SPAR encoder handle + * Allocate and initialize SPAR encoder handle and sub-handles *------------------------------------------------------------------------*/ ivas_error ivas_spar_enc_open( @@ -66,10 +66,7 @@ ivas_error ivas_spar_enc_open( hEncoderConfig = st_ivas->hEncoderConfig; error = IVAS_ERR_OK; - /*-----------------------------------------------------------------* - * Allocate and initialize SPAR handle - *-----------------------------------------------------------------*/ - + /* SPAR encoder handle */ if ( ( hSpar = (SPAR_ENC_HANDLE) count_malloc( sizeof( SPAR_ENC_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder" ); @@ -94,20 +91,13 @@ ivas_error ivas_spar_enc_open( // ivas_set_bitrate_config(&pState->hMdEnc->spar_md_cfg, table_idx); /* MD handle */ -#ifndef FIX_SBA_CLEAN_UP_OPT - if ( ( error = ivas_spar_foa_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig ) ) != IVAS_ERR_OK ) { return error; } -#endif /* set FB config. */ - active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; // VE: this parameter is different between enc and dec + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ); fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; @@ -129,13 +119,13 @@ ivas_error ivas_spar_enc_open( return error; } - /* AGC */ + /* AGC handle */ if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) { return error; } - /* PCA */ + /* PCA handle */ hSpar->hPCA = NULL; if ( hEncoderConfig->Opt_PCA_ON ) { @@ -143,10 +133,10 @@ ivas_error ivas_spar_enc_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder" ); } - init_pca_enc( hSpar->hPCA ); + ivas_pca_enc_init( hSpar->hPCA ); } - /* initializations */ + /* initialization */ hSpar->hMdEnc->table_idx = -1; #endif diff --git a/lib_enc/ivas_spar_foa_enc.c b/lib_enc/ivas_spar_foa_enc.c index 32c2b01a7b6718b3ba1dfd420e49dfa8c7883fb6..e6d1945d849d7113b818957b678e2221f3502755 100644 --- a/lib_enc/ivas_spar_foa_enc.c +++ b/lib_enc/ivas_spar_foa_enc.c @@ -130,7 +130,8 @@ ivas_error ivas_spar_foa_enc_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder" ); } - init_pca_enc( pState->hPCA ); + + ivas_pca_enc_init( pState->hPCA ); } /* initializations */ @@ -291,7 +292,7 @@ ivas_error ivas_spar_foa_enc_process( /*-----------------------------------------------------------------------------------------* * Function ivas_spar_enc_process() * - * Process call for SPAR FOA encoder + * Process call for SPAR encoder *-----------------------------------------------------------------------------------------*/ ivas_error ivas_spar_enc_process( @@ -333,7 +334,7 @@ ivas_error ivas_spar_enc_process( float dir[3], avg_dir[3]; float energySum, vecLen; - wmops_sub_start( "spar_foa_enc_process" ); + wmops_sub_start( "ivas_spar_enc_process" ); /*-----------------------------------------------------------------------------------------* * Initialization @@ -710,7 +711,7 @@ ivas_error ivas_spar_enc_process( } else { - if ( ( ivas_total_brate == PCA_BRATE ) && ( sba_order == 1 ) ) + if ( ivas_total_brate == PCA_BRATE && sba_order == 1 ) { /* write PCA bypass bit */ push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); @@ -720,9 +721,9 @@ ivas_error ivas_spar_enc_process( #ifdef SPAR_HOA_DBG /*FILE *fp = fopen("int_enc_dmx.raw", "ab"); - for (int t = 0; t < 960; t++) + for (int16_t t = 0; t < 960; t++) { - for (int c = 0; c < pState->hFbMixer->filterbank_num_out_chans; c++) + for (int16_t c = 0; c < pState->hFbMixer->filterbank_num_out_chans; c++) { for ( k = 0; k < 2; k++ ) { diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 6d41221dcf66942fdc74a0454ec55c840c32c8c1..48b21146fadf2ba50c3f6c3f929bf3b05604d52e 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -1092,7 +1092,7 @@ static void edge_detect( for ( j = 1; j <= i; j++ ) { y = inp_max - edge_slope * j; - err = y - thr_f( inp[j], inp_min, inp_max ); + err = y - check_bounds( inp[j], inp_min, inp_max ); edge[i] += err * err; } @@ -1130,7 +1130,7 @@ static void edge_detect( for ( j = 1; j < i; j++ ) { y = inp_min + edge_slope * j; - err = y - thr_f( inp[j], inp_min, inp_max ); + err = y - check_bounds( inp[j], inp_min, inp_max ); edge[i] += err * err; } diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 08b89ac9c30aecefc91dedc92a5b7bb710b408fb..b6a7e0685db044f1f2b5b92d87aeba2c62164807 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1707,7 +1707,7 @@ static void stereo_dft_enc_get_res_cod_mode_flag( g = fabsf( hStereoDft->side_gain[(k_offset) *STEREO_DFT_BAND_MAX + b] ); *res_dmx_ratio = max( hStereoDft->res_cod_NRG_S[b] / ( hStereoDft->res_cod_NRG_S[b] + ( 1 - g ) * ( 1 - g ) * hStereoDft->res_cod_NRG_M[b] + 1 ), *res_dmx_ratio ); } - check_bounds( res_dmx_ratio, 0, 1 ); /*should always be satisfied*/ + *res_dmx_ratio = check_bounds( *res_dmx_ratio, 0, 1 ); /*should always be satisfied*/ /*Calculate the total energy of RES and DMX*/ dmx_res_all = res_nrg_all_curr + dmx_nrg_all_curr; @@ -1898,7 +1898,7 @@ void stereo_dft_enc_res( panning_gain_min = 1.f - fabsf( panning_gain ); in_phase_ratio = ( panning_gain_min * panning_gain_min * hStereoDft->res_cod_NRG_M[b] ) / ( panning_gain_min * panning_gain_min * hStereoDft->res_cod_NRG_M[b] + hStereoDft->res_cod_NRG_S[b] + 1 ); - check_bounds( &in_phase_ratio, 0, 1 ); + in_phase_ratio = check_bounds( in_phase_ratio, 0, 1 ); res_cod_gain[b] = in_phase_ratio * STEREO_DFT_RES_COD_SNR_MIN + ( 1 - in_phase_ratio ) * STEREO_DFT_RES_COD_SNR_MAX; /*get the maximum through bands*/ diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index 4c1967c2ad630f573cae5d2d50d9bfeaf97b8423..5b47e9dc5240c2a25bb2dd17723d91304cc692cc 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -1557,7 +1557,7 @@ void stereo_dft_enc_compute_itd( /* Update memory */ hItd->prev_itd = itd; - check_bounds_s( &itd, -STEREO_DFT_ITD_MAX, STEREO_DFT_ITD_MAX ); + itd = check_bounds_s( itd, -STEREO_DFT_ITD_MAX, STEREO_DFT_ITD_MAX ); /*Inverse the time diff*/ hItd->itd[k_offset] = -1.f * itd; diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index 8f1f653b18ba3f4033ca8834df18f7c2a43173bd..84dfee698026db9cbf388b1901231692a49f5ff5 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -161,8 +161,8 @@ static void stereo_td_channel_extrapolate( g = dot_lead_lag / dot_lead_lead; nsr = 1 - ( ( dot_lead_lag * dot_lead_lag ) / ( dot_lead_lead * dot_lag_lag ) ); - check_bounds( &g, -1, 1.5f ); - check_bounds( &nsr, 0.0f, 1 ); + g = check_bounds( g, -1, 1.5f ); + nsr = check_bounds( nsr, 0.0f, 1 ); g_lpc = sqrtf( nsr ); /* rectangular window */ diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index cda6387f05f76616b83229d80aaf304d9583f038..41de84d71422668fd36ec663d569d256e9fa2087 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -338,7 +338,7 @@ int16_t stereo_tdm_ener_analysis( { if ( hCPE->element_brate >= IVAS_48k && sts[0]->hVAD->hangover_cnt != 0 && max( hStereoTD->tdm_lt_rms_L, hStereoTD->tdm_lt_rms_R ) < 512.0f ) { - check_bounds( &ratio_L, 0.3f, 0.7f ); + ratio_L = check_bounds( ratio_L, 0.3f, 0.7f ); } if ( ( hCPE->hStereoTCA->instTargetGain > 1.2f || hCPE->hStereoTCA->targetGain > 1.0f ) && ratio_L < 0.4f ) @@ -423,14 +423,13 @@ int16_t stereo_tdm_ener_analysis( idx_offet *= -1; } desired_idx += idx_offet; - check_bounds_s( &desired_idx, 0, 30 ); + desired_idx = check_bounds_s( desired_idx, 0, 30 ); } } if ( sts[1]->clas != UNVOICED_CLAS || sts[0]->clas != UNVOICED_CLAS ) { - desired_idx = min( desired_idx, 25 ); - desired_idx = max( desired_idx, 5 ); + desired_idx = check_bounds_s( desired_idx, 5, 25 ); } hStereoTD->tdm_inst_ratio_idx = desired_idx; @@ -848,7 +847,7 @@ static float Comp_diff_lt_corr( adaprate = M_ADAP * min( tdm_lt_rms_R, tdm_lt_rms_L ) + B_ADAP; } - check_bounds( &adaprate, MIN_ADAP_FAC, 1.0f ); + adaprate = check_bounds( adaprate, MIN_ADAP_FAC, 1.0f ); /*----------------------------------------------------------------* * In case of unvoiced content (expect when it is part of an onset), @@ -942,7 +941,7 @@ static int16_t limit_idx_Dwnmix( int16_t idx; idx = idx_in; - check_bounds_s( &idx, 1, 29 ); + idx = check_bounds_s( idx, 1, 29 ); if ( unclr_decision == 1 && tdm_last_LRTD_frame_cnt > 1 ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index cba218a3d059bc9535a0e65c1354a9d6a3444daf..164ad86875a6a960377e08730592d6552eefc10c 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -444,7 +444,7 @@ void tdm_configure_enc( { hStereoTD->tdm_inst_ratio_idx -= LRTD_STEREO_QUARTER_RANGE; } - check_bounds_s( &( hStereoTD->tdm_inst_ratio_idx ), 8, 22 ); + hStereoTD->tdm_inst_ratio_idx = check_bounds_s( hStereoTD->tdm_inst_ratio_idx, 8, 22 ); } /*----------------------------------------------------------------* diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 93b43ee63fb16355bc75c8bd68bddab472d547e5..28a8c3004e58d3b842b703230c06d824cb9fed18 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -762,7 +762,9 @@ static ivas_error configureEncoder( /* IVAS_fmToDo: needs more work in case of bitrate switching */ hEncoderConfig->sba_order = 1; } +#ifndef SBA_CLEANING st_ivas->sba_mode = ivas_sba_mode_select( hEncoderConfig->ivas_total_brate ); // VE: is it needed here? +#endif } else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) { @@ -938,33 +940,6 @@ ivas_error IVAS_ENC_GetDelay( } -/*---------------------------------------------------------------------* - * IVAS_ENC_GetNumInputChannels() - * - * - *---------------------------------------------------------------------*/ - -ivas_error IVAS_ENC_GetNumInputChannels( - const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ - int16_t *numInChannels /* o : number of input channels with current */ -) -{ - if ( !hIvasEnc->isConfigured ) - { - return IVAS_ERR_NOT_CONFIGURED; - } - - if ( numInChannels == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } - - *numInChannels = hIvasEnc->st_ivas->hEncoderConfig->nchan_inp; - - return IVAS_ERR_OK; -} - - /*---------------------------------------------------------------------* * getInputBufferSize() * @@ -1320,7 +1295,7 @@ IVAS_ENC_DTX_CONFIG IVAS_ENC_GetDefaultDtxConfig( void ) IVAS_ENC_CHANNEL_AWARE_CONFIG IVAS_ENC_GetDefaultChannelAwareConfig( void ) { IVAS_ENC_CHANNEL_AWARE_CONFIG defaultCaConfig; - defaultCaConfig.channelAwareModeEnabled = false; + defaultCaConfig.channelAwareModeEnabled = 0; defaultCaConfig.fec_indicator = IVAS_ENC_FEC_HI; defaultCaConfig.fec_offset = 0; @@ -1406,7 +1381,8 @@ const char *IVAS_ENC_GetErrorMessage( *---------------------------------------------------------------------*/ static ivas_error printConfigInfo_enc( - IVAS_ENC_HANDLE hIvasEnc ) + IVAS_ENC_HANDLE hIvasEnc, + const int16_t channelAwareModeEnabled ) { Encoder_Struct *st_ivas; ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -1616,6 +1592,18 @@ static ivas_error printConfigInfo_enc( } } + /*-----------------------------------------------------------------* + * Print Channel-aware limitation + *-----------------------------------------------------------------*/ + + if ( channelAwareModeEnabled ) + { + if ( hEncoderConfig->Opt_RF_ON == 0 ) + { + fprintf( stdout, "\nChannel-aware mode is supported at 13.2 kbps 32/48 kHz only. Switching to normal mode.\n" ); + } + } + return IVAS_ERR_OK; } @@ -1715,7 +1703,7 @@ static ivas_error setChannelAwareConfig( hEncoderConfig = st_ivas->hEncoderConfig; /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ - if ( ( hEncoderConfig->Opt_RF_ON && st_ivas->hEncoderConfig->ivas_total_brate != ACELP_13k20 ) || ( hEncoderConfig->Opt_RF_ON && hEncoderConfig->input_Fs == 8000 ) ) + if ( ( caConfig.channelAwareModeEnabled && st_ivas->hEncoderConfig->ivas_total_brate != ACELP_13k20 ) || ( hEncoderConfig->Opt_RF_ON && hEncoderConfig->input_Fs == 8000 ) ) { hEncoderConfig->Opt_RF_ON = 0; hEncoderConfig->rf_fec_offset = 0; @@ -2012,10 +2000,11 @@ static ivas_error forcedModeApiToInternal( *---------------------------------------------------------------------*/ void IVAS_ENC_PrintConfig( - const IVAS_ENC_HANDLE hIvasDec /* i : IVAS encoder handle */ + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + const int16_t channelAwareModeEnabled /* i : channel-aware mode enabled flag */ ) { - printConfigInfo_enc( hIvasDec ); + printConfigInfo_enc( hIvasEnc, channelAwareModeEnabled ); return; } diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index b8744a27318c574587238d505a71693b2a6a5cd6..0139e0f7abffa6bb0cd5f724a6469e869ae41768 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -123,25 +123,11 @@ typedef enum _IVAS_ENC_FORCED_MODE } IVAS_ENC_FORCED_MODE; #endif -typedef enum _IVAS_ENC_FEC_INDICATOR -{ - IVAS_ENC_FEC_LO, - IVAS_ENC_FEC_HI, - IVAS_ENC_FEC_UNDEFINED = 0xffff -} IVAS_ENC_FEC_INDICATOR; - /*---------------------------------------------------------------------* * Encoder structures *---------------------------------------------------------------------*/ -typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG -{ - bool channelAwareModeEnabled; - IVAS_ENC_FEC_INDICATOR fec_indicator; - int16_t fec_offset; -} IVAS_ENC_CHANNEL_AWARE_CONFIG; - typedef struct IVAS_ENC *IVAS_ENC_HANDLE; /* clang-format off */ @@ -302,12 +288,6 @@ ivas_error IVAS_ENC_GetDelay( int16_t *delay /* o : encoder delay */ ); -/*! r: encoder error code */ -ivas_error IVAS_ENC_GetNumInputChannels( - const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - int16_t *numInChannels /* o : number of input channels with current configuration */ -); - /*! r: encoder error code */ ivas_error IVAS_ENC_GetInputBufferSize( const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ @@ -337,7 +317,8 @@ const char *IVAS_ENC_GetErrorMessage( void IVAS_ENC_PrintConfig( - const IVAS_ENC_HANDLE hIvasDec /* i : IVAS encoder handle */ + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + const int16_t channelAwareModeEnabled /* i : channel-aware mode enabled flag */ ); void IVAS_ENC_PrintDisclaimer( diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 32b1118c15bc7d33c5711fe006e5a2d766d024ed..036611efb314f51a2361109701b45942b669c53b 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -2725,7 +2725,7 @@ void fb_tbe_enc( } else { - push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); + push_indice( st->hBstr, IND_FB_SLOPE, idxGain, NUM_BITS_FB_FRAMEGAIN_TBE ); } return; diff --git a/lib_util/g192.c b/lib_util/g192.c index 26b3aae578289a6f02ce3cc423fe841587b97272..6f708690a0420c85870875596abe0af93ee76590 100644 --- a/lib_util/g192.c +++ b/lib_util/g192.c @@ -34,11 +34,8 @@ EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ -/* WMC_TOOL_SKIP_FILE (basic ops file) */ - -#include "options.h" #include "g192.h" -#include "cnst.h" +#include "common_api_types.h" #include #include #include @@ -124,7 +121,7 @@ G192_ERROR G192_ReadFrame_compact( int16_t *const num_bits, int16_t *const bfi ) { - uint16_t short_serial[MAX_BITS_PER_FRAME]; + uint16_t short_serial[IVAS_MAX_BITS_PER_FRAME]; G192_ERROR err; int16_t i; @@ -153,7 +150,7 @@ G192_ERROR G192_ReadVoipFrame_compact( uint32_t *const rtpTimeStamp, uint32_t *const rcvTime_ms ) { - int16_t short_serial[MAX_BITS_PER_FRAME]; + int16_t short_serial[IVAS_MAX_BITS_PER_FRAME]; G192_ERROR err; int16_t i; @@ -223,7 +220,7 @@ G192_ERROR G192_ReadFrame_short( return G192_READ_ERROR; } - if ( *num_bits > MAX_BITS_PER_FRAME ) + if ( *num_bits > IVAS_MAX_BITS_PER_FRAME ) { fprintf( stderr, "\n Frame is too large " ); return G192_READ_ERROR; @@ -386,7 +383,7 @@ G192_ERROR G192_ReadVoipFrame_short( } *num_bits = rtpPayloadG192[1]; - if ( *num_bits == 0u || *num_bits + 2u != rtpPayloadSize || *num_bits > MAX_BITS_PER_FRAME ) + if ( *num_bits == 0u || *num_bits + 2u != rtpPayloadSize || *num_bits > IVAS_MAX_BITS_PER_FRAME ) { fprintf( stderr, "error in parsing RTP payload: rtpPayloadSize=%u nBits=%d", rtpPayloadSize, *num_bits ); return G192_INVALID_DATA; @@ -453,10 +450,10 @@ G192_ERROR G192_WriteFrame( const uint16_t *serial, const int16_t numBits ) { - uint16_t G192_HEADER[2], G192_DATA[MAX_BITS_PER_FRAME]; + uint16_t G192_HEADER[2], G192_DATA[IVAS_MAX_BITS_PER_FRAME]; uint16_t i, bit; - assert( numBits <= MAX_BITS_PER_FRAME ); + assert( numBits <= IVAS_MAX_BITS_PER_FRAME ); G192_HEADER[0] = G192_SYNC_GOOD_FRAME; G192_HEADER[1] = numBits; /* Frame Length */ @@ -492,7 +489,7 @@ G192_ERROR G192_WriteVoipFrame_short( uint16_t const rtpTimeStamp, uint32_t const rcvTime_ms ) { - int16_t G192_HEADER[2], G192_DATA[MAX_BITS_PER_FRAME]; + int16_t G192_HEADER[2], G192_DATA[IVAS_MAX_BITS_PER_FRAME]; int16_t i, bit; uint32_t rtpPacketSize = numBits + 12 + 2; @@ -502,7 +499,7 @@ G192_ERROR G192_WriteVoipFrame_short( uint32_t rtpTimeStamp_2 = htonl( rtpTimeStamp ); uint16_t ssrc_2 = (uint16_t) htonl( ssrc ); - assert( numBits <= MAX_BITS_PER_FRAME ); + assert( numBits <= IVAS_MAX_BITS_PER_FRAME ); fwrite( &rtpPacketSize, sizeof( rtpPacketSize ), 1, hG192->file ); fwrite( &rcvTime_ms, sizeof( rcvTime_ms ), 1, hG192->file ); diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index c3e45fa44661b938a7fb85437003395f262143f5..1f6f5c911a9fd6e273e53bdf21d36a77bcae1b0d 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -47,6 +47,13 @@ struct IsmFileReader char *file_path; }; + +/*---------------------------------------------------------------------* + * IsmFileReader_open() + * + * Allocates memory for an IsmFileReader and opens the file at given path for reading. + *---------------------------------------------------------------------*/ + IsmFileReader *IsmFileReader_open( const char *filePath /* i : path to ism metadata file */ ) @@ -75,6 +82,12 @@ IsmFileReader *IsmFileReader_open( return self; } + +/*---------------------------------------------------------------------* + * IsmFileReader_readNextFrame() + * + * Reads ISM metadata from a previously opened file into the provided struct. + *---------------------------------------------------------------------*/ /*! r: error code */ ivas_error IsmFileReader_readNextFrame( IsmFileReader *self, /* i/o: IsmFileReader handle */ @@ -131,6 +144,12 @@ ivas_error IsmFileReader_readNextFrame( return IVAS_ERR_OK; } + +/*---------------------------------------------------------------------* + * IsmFileReader_close() + * + * De-allocates all underlying memory of an IsmFileReader. + *---------------------------------------------------------------------*/ void IsmFileReader_close( IsmFileReader **selfPtr /* i/o: pointer to IsmFileReader handle */ ) @@ -148,6 +167,12 @@ void IsmFileReader_close( return; } + +/*---------------------------------------------------------------------* + * IsmFileReader_getFilePath() + * + *---------------------------------------------------------------------*/ + const char *IsmFileReader_getFilePath( IsmFileReader *self /* i/o: IsmFileReader handle */ ) diff --git a/lib_util/ism_file_reader.h b/lib_util/ism_file_reader.h index 294b26260e0cb5c2665e47554a2eb7cad65e9ab6..d618621d3210353c3860ef1453d105a05bcd3217 100644 --- a/lib_util/ism_file_reader.h +++ b/lib_util/ism_file_reader.h @@ -37,45 +37,26 @@ #include "common_api_types.h" #include "ivas_error.h" +/* clang-format off */ typedef struct IsmFileReader IsmFileReader; -/* clang-format off */ -/*---------------------------------------------------------------------* - * IsmFileReader_open() - * - * Allocates memory for an IsmFileReader and opens the file at given path for reading. - *---------------------------------------------------------------------*/ /*! r: IsmFileReader handle */ IsmFileReader *IsmFileReader_open( const char *filePath /* i : path to ISM metadata file */ ); -/*---------------------------------------------------------------------* - * IsmFileReader_readNextFrame() - * - * Reads ISM metadata from a previously opened file into the provided struct. - *---------------------------------------------------------------------*/ /*! r: error code */ ivas_error IsmFileReader_readNextFrame( IsmFileReader *self, /* i/o: IsmFileReader handle */ IVAS_ISM_METADATA *ismMetadata /* o : ISM metadata read from the opened file */ ); -/*---------------------------------------------------------------------* - * IsmFileReader_close() - * - * De-allocates all underlying memory of an IsmFileReader. - *---------------------------------------------------------------------*/ void IsmFileReader_close( IsmFileReader **selfPtr /* i/o: pointer to IsmFileReader handle */ ); -/*---------------------------------------------------------------------* - * IsmFileReader_getFilePath() - * - *---------------------------------------------------------------------*/ /*! r: path to the currently opened file or NULL if `self` is NULL */ const char *IsmFileReader_getFilePath( IsmFileReader* self /* i/o: IsmFileReader handle */ diff --git a/lib_util/jbm_file_reader.c b/lib_util/jbm_file_reader.c new file mode 100644 index 0000000000000000000000000000000000000000..cde35ac3e458e884fc7f0b74bbd820dd1a22280d --- /dev/null +++ b/lib_util/jbm_file_reader.c @@ -0,0 +1,181 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include "jbm_file_reader.h" +#include "cmdl_tools.h" +#include +#include +#include + +struct JbmFileReader +{ + FILE *file; + char *file_path; +}; + + +/*---------------------------------------------------------------------* + * JbmFileReader_open() + * + * Allocates memory for an JbmFileReader and opens the file at given path for reading. + *---------------------------------------------------------------------*/ + +/*! r: JbmFileReader handle */ +JbmFileReader *JbmFileReader_open( + const char *filePath /* i : path to CA config file */ +) +{ + JbmFileReader *self; + FILE *file; + + if ( !filePath ) + { + return NULL; + } + + file = fopen( filePath, "rb" ); + + if ( !file ) + { + return NULL; + } + + self = calloc( sizeof( JbmFileReader ), 1 ); + self->file = file; + self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + strcpy( self->file_path, filePath ); + + return self; +} + + +/*---------------------------------------------------------------------* + * JbmFileReader_readCAconfig() + * + * Read Chanel-aware config. entry + *---------------------------------------------------------------------*/ + +ivas_error JbmFileReader_readCAconfig( + JbmFileReader* self, /* i/o: JbmFileReader handle */ + IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig /* i/o: configuration of channel-aware mode */ +) +{ + char rline[10], str[4]; + int16_t tmp; + + /* Initialize */ + caConfig->fec_offset = 0; + caConfig->fec_indicator = IVAS_ENC_FEC_HI; + + while ( fgets( rline, 10, self->file ) == NULL && feof( self->file ) ) + { + rewind( self->file ); + } + + if ( sscanf( rline, "%s %hd", str, &tmp ) != 2 ) + { + fprintf( stderr, "Error in the RF configuration file. There is no proper configuration line.\n" ); + return IVAS_ERR_INVALID_FEC_CONFIG; + } + + /* Read RF FEC indicator */ + to_upper( str ); + + if ( strcmp( str, "HI" ) == 0 ) + { + caConfig->fec_indicator = IVAS_ENC_FEC_HI; + } + else if ( strcmp( str, "LO" ) == 0 ) + { + caConfig->fec_indicator = IVAS_ENC_FEC_LO; + } + else + { + fprintf( stderr, "Error: Incorrect FEC indicator string. Exiting the encoder.\n" ); + return IVAS_ERR_INVALID_FEC_CONFIG; + } + + /* Read RF FEC offset */ + if ( tmp == 0 || tmp == 2 || tmp == 3 || tmp == 5 || tmp == 7 ) + { + caConfig->fec_offset = tmp; + } + else + { + fprintf( stderr, "Error: incorrect FEC offset specified in the RF configuration file; RF offset can be 2, 3, 5, or 7. \n" ); + return IVAS_ERR_INVALID_FEC_CONFIG; + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * JbmFileReader_close() + * + * De-allocates all underlying memory of an JbmFileReader. + *---------------------------------------------------------------------*/ + +void JbmFileReader_close( + JbmFileReader **selfPtr /* i/o: pointer to JbmFileReader handle */ +) +{ + if ( selfPtr == NULL || *selfPtr == NULL ) + { + return; + } + + fclose( ( *selfPtr )->file ); + free( ( *selfPtr )->file_path ); + free( *selfPtr ); + *selfPtr = NULL; + + return; +} + + +/*---------------------------------------------------------------------* + * JbmFileReader_getFilePath() + * + *---------------------------------------------------------------------*/ + +const char *JbmFileReader_getFilePath( + JbmFileReader *self /* i/o: JbmFileReader handle */ +) +{ + if ( self == NULL ) + { + return NULL; + } + + return self->file_path; +} diff --git a/lib_util/jbm_file_reader.h b/lib_util/jbm_file_reader.h new file mode 100644 index 0000000000000000000000000000000000000000..dca0a6c13596b03b5a27012cd2083b9dfcee1348 --- /dev/null +++ b/lib_util/jbm_file_reader.h @@ -0,0 +1,67 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#ifndef IVAS_JBM_FILE_READER_H +#define IVAS_JBM_FILE_READER_H + +#include +#include "common_api_types.h" +#include "ivas_error.h" + +/* clang-format off */ + +typedef struct JbmFileReader JbmFileReader; + + +/*! r: JbmFileReader handle */ +JbmFileReader *JbmFileReader_open( + const char *filePath /* i : path to CA config file */ +); + +ivas_error JbmFileReader_readCAconfig( + JbmFileReader* self, /* i/o: JbmFileReader handle */ + IVAS_ENC_CHANNEL_AWARE_CONFIG *caConfig /* i/o: configuration of channel-aware mode */ +); + +void JbmFileReader_close( + JbmFileReader **selfPtr /* i/o: pointer to JbmFileReader handle */ +); + +/*! r: path to the currently opened file or NULL if `self` is NULL */ +const char *JbmFileReader_getFilePath( + JbmFileReader* self /* i/o: JbmFileReader handle */ +); + + +/* clang-format on */ + +#endif /* IVAS_JBM_FILE_READER_H */