diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 61539e2355ec5d9db3603452ca0f257c09c449ed..931fbc723bbc90e7ff6a5fed7fc31c2943b5e887 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -706,8 +706,7 @@ ivas_error openCldfb( HANDLE_CLDFB_FILTER_BANK hs; int16_t buf_len; - hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ); - if ( hs == NULL ) + if ( ( hs = (HANDLE_CLDFB_FILTER_BANK) malloc( sizeof( CLDFB_FILTER_BANK ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } @@ -728,8 +727,7 @@ ivas_error openCldfb( buf_len = hs->p_filter_length; } - hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ); - if ( hs->cldfb_state == NULL ) + if ( ( hs->cldfb_state = (float *) malloc( buf_len * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } @@ -1148,8 +1146,7 @@ ivas_error cldfb_save_memory( hs->memory_length = hs->p_filter_length; } - hs->memory = (float *) malloc( hs->memory_length * sizeof( float ) ); - if ( hs->memory == NULL ) + if ( ( hs->memory = (float *) malloc( hs->memory_length * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB\n" ); } diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 0203cd4fb75dd6eeb234c7fddcf30a3d692d34e3..f2dbf746b6f18d5e6b9fc07aaa570384733702be 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -68,9 +68,7 @@ ivas_error createFdCngCom( HANDLE_FD_CNG_COM hs; /* Allocate memory */ - hs = (HANDLE_FD_CNG_COM) malloc( sizeof( FD_CNG_COM ) ); - - if ( hs == NULL ) + if ( ( hs = (HANDLE_FD_CNG_COM) malloc( sizeof( FD_CNG_COM ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD CNG COM" ); } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 3ea6e6bbae22fe5713c892fac89dfd3d46cdc68d..6711b998c971fcfad9c904d14a305722ce3936f3 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -785,19 +785,19 @@ float ism_dequant_meta( const int16_t cbsize /* i : codebook size */ ); -ivas_error set_ism_metadata( - ISM_METADATA_HANDLE hIsmMeta, /* i/o: ISM metadata handle */ - float azimuth, /* i : azimuth */ - float elevation /* i : elevation */ +ivas_error ivas_set_ism_metadata( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const float azimuth, /* i : azimuth value */ + const float elevation /* i : elevation value */ ); -ivas_error create_ism_metadata_enc( +ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t n_ISms, /* i : number of objects */ int32_t element_brate_tmp[] /* o : element bitrate per object */ ); -ivas_error create_ism_metadata_dec( +ivas_error ivas_ism_metadata_dec_create( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t n_ISms, /* i : number of objects */ int32_t element_brate_tmp[] /* o : element bitrate per object */ @@ -1288,9 +1288,9 @@ int16_t adapt_GR_rpg1_ief( /*! r: number of bits written */ int16_t write_GR1( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const int16_t ind, /* i : bitstream index */ - const int16_t *in, /* i : input vector */ - const int16_t len /* i : vector length */ + const int16_t ind, /* i : bitstream index */ + const int16_t *in, /* i : input vector */ + const int16_t len /* i : vector length */ ); /*! r: number of bits written */ @@ -2837,7 +2837,7 @@ void ivas_mct_dec_mct( void apply_MCT_dec( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ Decoder_State **sts, /* i/o: decoder state structure */ - float *x[MCT_MAX_CHANNELS][NB_DIV] /* i/o: decoded and dequan. spect. input to MCT */ + float *x[MCT_MAX_CHANNELS][NB_DIV] /* i/o: decoded and dequan. spect. input to MCT */ ); void mctStereoIGF_dec( @@ -3114,6 +3114,7 @@ void ivas_dirac_param_est_enc( const SBA_MODE sba_mode ); + /*----------------------------------------------------------------------------------* * SBA format prototypes *----------------------------------------------------------------------------------*/ @@ -3150,6 +3151,7 @@ ivas_error ivas_cldfb_dec_reconfig( int16_t numCldfbAnalyses_old, /* i : number of CLDFB analysis instances in previous frame */ const int16_t numCldfbSyntheses_old /* i : number of CLDFB synthesis instances in previous frame */ ); + /*! r: Ambisonic (SBA) order */ int16_t ivas_sba_get_order( const int16_t nb_channels, /* i : Number of ambisonic channels */ @@ -3344,7 +3346,7 @@ void computeDiffuseness( float *diffuseness ); -void ivas_dirac_dec_onset_detection_open( +ivas_error ivas_dirac_dec_onset_detection_open( const int16_t num_channels, const int16_t num_freq_bands, const int16_t max_band_decorr, @@ -3360,7 +3362,7 @@ void ivas_dirac_dec_onset_detection_process( DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state ); -void ivas_dirac_dec_decorr_open( +ivas_error ivas_dirac_dec_decorr_open( DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state, const int16_t num_freq_bands, @@ -3393,7 +3395,7 @@ void ivas_dirac_dec_decorr_close( ); -void ivas_dirac_dec_output_synthesis_open( +ivas_error ivas_dirac_dec_output_synthesis_open( DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ const RENDERER_TYPE renderer_type, /* i : renderer type */ const int16_t nchan_transport, /* i : number of transport channels */ @@ -3670,7 +3672,7 @@ int16_t svd( const int16_t nChannelsC /* i : number of columns in the matrix to be decomposed */ ); -void ivas_dirac_dec_output_synthesis_cov_open( +ivas_error ivas_dirac_dec_output_synthesis_cov_open( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: handle for the covariance synthesis state */ const int16_t max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ @@ -3933,11 +3935,41 @@ void ivas_spar_bitrate_dist( const int16_t bwidth /* i : audio bandwidth */ ); -void ivas_mdct( const float *pIn, float *pOut, const int16_t length ); -void ivas_dct_windowing( const int16_t fade_len, const int16_t full_len, const int16_t dct_len, const int16_t zero_pad_len, const float *pWindow_coeffs, const int16_t frame_len, float *pOut_buf, float *pBuffer_prev, float *pTemp_lfe ); -void ivas_tda( const float *pIn, float *pOut, const int16_t length ); -void ivas_imdct( const float *pIn, float *pOut, const int16_t length ); -void ivas_itda( const float *re, float *pOut, const int16_t length ); +void ivas_mdct( + const float *pIn, + float *pOut, + const int16_t length +); + +void ivas_dct_windowing( + const int16_t fade_len, + const int16_t full_len, + const int16_t dct_len, + const int16_t zero_pad_len, + const float *pWindow_coeffs, + const int16_t frame_len, + float *pOut_buf, + float *pBuffer_prev, + float *pTemp_lfe +); + +void ivas_tda( + const float *pIn, + float *pOut, + const int16_t length +); + +void ivas_imdct( + const float *pIn, + float *pOut, + const int16_t length +); + +void ivas_itda( + const float *re, + float *pOut, + const int16_t length +); void ivas_spar_get_cldfb_gains( SPAR_DEC_HANDLE hSpar, @@ -4172,8 +4204,8 @@ void ivas_transient_det_close( void ivas_transient_det_process( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ float *pIn_pcm, /* i : input audio channels */ - const int16_t frame_len, /* i : frame length in samples */ - int16_t transient_det[2] /* o: transient det outputs */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t transient_det[2] /* o : transient det outputs */ ); #else int16_t ivas_transient_det_process( @@ -4452,7 +4484,7 @@ ivas_error ivas_masa_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void ivas_masa_encode( +ivas_error ivas_masa_encode( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -4915,7 +4947,7 @@ ivas_error ivas_td_binaural_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void ivas_td_binaural_renderer( +ivas_error ivas_td_binaural_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ const int16_t output_frame /* i : output frame length */ diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 4f1fe47a1ea9e78eb92fbe5ed017e2088652237f..0f2491bad3545e1dcfe9a785d208aa1f702f3eb1 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -98,9 +98,8 @@ ivas_error ivas_qmetadata_allocate_memory( const int16_t coherence_flag /* i : new coherence coding status */ ) { - int16_t dir; + int16_t j, dir; uint8_t do_realloc; - uint8_t reservationFailed = 0; #ifdef DEBUGGING assert( hQMetaData != NULL ); @@ -126,68 +125,63 @@ ivas_error ivas_qmetadata_allocate_memory( hQMetaData->no_directions = ndirs; hQMetaData->coherence_flag = coherence_flag; - hQMetaData->q_direction = (IVAS_QDIRECTION *) malloc( sizeof( IVAS_QDIRECTION ) * ndirs ); - reservationFailed = hQMetaData->q_direction == NULL; + if ( ( hQMetaData->q_direction = (IVAS_QDIRECTION *) malloc( sizeof( IVAS_QDIRECTION ) * ndirs ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); + } + - if ( !reservationFailed ) + for ( dir = 0; dir < hQMetaData->no_directions; dir++ ) { - for ( dir = 0; dir < hQMetaData->no_directions; dir++ ) + hQMetaData->q_direction[dir].cfg.nbands = nbands; + if ( nbands == 0 ) { - hQMetaData->q_direction[dir].cfg.nbands = nbands; - if ( nbands == 0 ) - { - hQMetaData->q_direction[dir].band_data = NULL; - } - else + hQMetaData->q_direction[dir].band_data = NULL; + } + else + { + if ( ( hQMetaData->q_direction[dir].band_data = (IVAS_QDIRECTION_BAND_DATA *) malloc( sizeof( IVAS_QDIRECTION_BAND_DATA ) * hQMetaData->q_direction[dir].cfg.nbands ) ) == NULL ) { - hQMetaData->q_direction[dir].band_data = (IVAS_QDIRECTION_BAND_DATA *) malloc( sizeof( IVAS_QDIRECTION_BAND_DATA ) * hQMetaData->q_direction[dir].cfg.nbands ); - { - int16_t j; - for ( j = 0; j < nbands; j++ ) - { - set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - - - reservationFailed |= hQMetaData->q_direction[dir].band_data == NULL; + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); } - if ( coherence_flag ) + for ( j = 0; j < nbands; j++ ) { - hQMetaData->q_direction[dir].coherence_band_data = (IVAS_QDIRECTION_BAND_COHERENCE_DATA *) malloc( sizeof( IVAS_QDIRECTION_BAND_COHERENCE_DATA ) * hQMetaData->q_direction[dir].cfg.nbands ); - reservationFailed |= hQMetaData->q_direction[dir].coherence_band_data == NULL; + set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); } - else - { - hQMetaData->q_direction[dir].coherence_band_data = NULL; - } - - /* These default values are set here to get them conveniently in one place */ - hQMetaData->q_direction[dir].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - hQMetaData->q_direction[dir].cfg.search_effort = 3; - hQMetaData->q_direction[dir].cfg.start_band = 0; - hQMetaData->q_direction[dir].cfg.mc_ls_setup = MC_LS_SETUP_INVALID; } if ( coherence_flag ) { - hQMetaData->surcoh_band_data = (IVAS_SURROUND_COHERENCE_BAND_DATA *) malloc( sizeof( IVAS_SURROUND_COHERENCE_BAND_DATA ) * hQMetaData->q_direction[0].cfg.nbands ); - reservationFailed |= hQMetaData->surcoh_band_data == NULL; + hQMetaData->q_direction[dir].coherence_band_data = (IVAS_QDIRECTION_BAND_COHERENCE_DATA *) malloc( sizeof( IVAS_QDIRECTION_BAND_COHERENCE_DATA ) * hQMetaData->q_direction[dir].cfg.nbands ); } else { - hQMetaData->surcoh_band_data = NULL; + hQMetaData->q_direction[dir].coherence_band_data = NULL; } + + /* These default values are set here to get them conveniently in one place */ + hQMetaData->q_direction[dir].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; + hQMetaData->q_direction[dir].cfg.search_effort = 3; + hQMetaData->q_direction[dir].cfg.start_band = 0; + hQMetaData->q_direction[dir].cfg.mc_ls_setup = MC_LS_SETUP_INVALID; } - } - if ( reservationFailed ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Q MetaData\n" ) ); + if ( coherence_flag ) + { + if ( ( hQMetaData->surcoh_band_data = (IVAS_SURROUND_COHERENCE_BAND_DATA *) malloc( sizeof( IVAS_SURROUND_COHERENCE_BAND_DATA ) * hQMetaData->q_direction[0].cfg.nbands ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); + } + } + else + { + hQMetaData->surcoh_band_data = NULL; + } } + return IVAS_ERR_OK; } diff --git a/lib_com/prot.h b/lib_com/prot.h index f9ec0e4b9f62a5f51cc1274429021a200ce5586f..16d069759febe82257afd5e0f3455ca18c7c071f 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -8663,17 +8663,13 @@ void ApplyFdCng( const int16_t concealWholeFrame, /* i : binary flag indicating frame loss */ const int16_t is_music ); -void perform_noise_estimation_dec( - const float *timeDomainInput, - float *power_spectrum, - HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */ - const int16_t element_mode, /* i : element mode type */ - const int16_t bwidth, /* i : audio bandwidth */ - const int16_t L_frame, /* i : frame length at internal Fs */ - const int16_t last_L_frame, /* i : frame length of the last frame at internal Fs */ - const int32_t last_core_brate, /* i : previous frame core bitrate */ - const int16_t VAD /* i : VAD flag in the decoder */ +void generate_comfort_noise_dec( + float **bufferReal, /* o : Real part of input bands */ + float **bufferImag, /* o : Imaginary part of input bands */ + Decoder_State *st, /* i/o: decoder state structure */ + const int16_t nchan_out /* i : number of output channels */ ); + /*! r: CNG energy */ float cng_energy( const int16_t element_mode, /* i : element mode */ @@ -8777,40 +8773,40 @@ void ReadFromBitstream( int16_t **pStream, int16_t *pnSize ); -void const *GetTnsFilterOrder( void const *p, int16_t index, int16_t *pValue ); -void *SetTnsFilterOrder( void *p, int16_t index, int16_t value ); -void const *GetNumOfTnsFilters( void const *p, int16_t index, int16_t *pValue ); -void *SetNumOfTnsFilters( void *p, int16_t index, int16_t value ); -void const *GetTnsEnabled( void const *p, int16_t index, int16_t *pValue ); -void *SetTnsEnabled( void *p, int16_t index, int16_t value ); -void const *GetTnsEnabledSingleFilter( void const *p, int16_t index, int16_t *pValue ); -void *SetTnsEnabledSingleFilter( void *p, int16_t index, int16_t value ); -void const *GetTnsFilterCoeff( void const *p, int16_t index, int16_t *pValue ); -void *SetTnsFilterCoeff( void *p, int16_t index, int16_t value ); - -void const *GetTnsOnWhite( void const *p, int16_t index, int16_t *pValue ); -void *SetTnsOnWhite( void *p, int16_t index, int16_t value ); - -int16_t GetSWBTCX10TnsFilterCoeffBits( int16_t value, int16_t index ); -int16_t EncodeSWBTCX10TnsFilterCoeff( int16_t value, int16_t index ); -int16_t DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t *pValue ); -int16_t GetSWBTCX20TnsFilterCoeffBits( int16_t value, int16_t index ); -int16_t EncodeSWBTCX20TnsFilterCoeff( int16_t value, int16_t index ); -int16_t DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t *pValue ); - -int16_t GetWBTCX20TnsFilterCoeffBits( int16_t value, int16_t index ); -int16_t EncodeWBTCX20TnsFilterCoeff( int16_t, int16_t index ); -int16_t DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t *pValue ); - -int16_t GetTnsFilterOrderBitsSWBTCX10( int16_t value, int16_t index ); -int16_t EncodeTnsFilterOrderSWBTCX10( int16_t value, int16_t index ); -int16_t DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, int16_t index, int16_t *pValue ); -int16_t GetTnsFilterOrderBitsSWBTCX20( int16_t value, int16_t index ); -int16_t EncodeTnsFilterOrderSWBTCX20( int16_t value, int16_t index ); -int16_t DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, int16_t index, int16_t *pValue ); -int16_t GetTnsFilterOrderBits( int16_t value, int16_t index ); -int16_t EncodeTnsFilterOrder( int16_t value, int16_t index ); -int16_t DecodeTnsFilterOrder( Decoder_State *st, int16_t index, int16_t *pValue ); +void const *GetTnsFilterOrder( void const *p, const int16_t index, int16_t *pValue ); +void *SetTnsFilterOrder( void *p, const int16_t index, const int16_t value ); +void const *GetNumOfTnsFilters( void const *p, const int16_t index, int16_t *pValue ); +void *SetNumOfTnsFilters( void *p, const int16_t index, const int16_t value ); +void const *GetTnsEnabled( void const *p, const int16_t index, int16_t *pValue ); +void *SetTnsEnabled( void *p, const int16_t index, const int16_t value ); +void const *GetTnsEnabledSingleFilter( void const *p, const int16_t index, int16_t *pValue ); +void *SetTnsEnabledSingleFilter( void *p, const int16_t index, const int16_t value ); +void const *GetTnsFilterCoeff( void const *p, const int16_t index, int16_t *pValue ); +void *SetTnsFilterCoeff( void *p, const int16_t index, const int16_t value ); + +void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ); +void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ); + +int16_t GetSWBTCX10TnsFilterCoeffBits( const int16_t value, const int16_t index ); +int16_t EncodeSWBTCX10TnsFilterCoeff( const int16_t value, const int16_t index ); +int16_t DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, const int16_t index, int16_t *pValue ); +int16_t GetSWBTCX20TnsFilterCoeffBits( const int16_t value, const int16_t index ); +int16_t EncodeSWBTCX20TnsFilterCoeff( const int16_t value, const int16_t index ); +int16_t DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, const int16_t index, int16_t *pValue ); + +int16_t GetWBTCX20TnsFilterCoeffBits( const int16_t value, const int16_t index ); +int16_t EncodeWBTCX20TnsFilterCoeff( const int16_t, const int16_t index ); +int16_t DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const int16_t index, int16_t *pValue ); + +int16_t GetTnsFilterOrderBitsSWBTCX10( const int16_t value, const int16_t index ); +int16_t EncodeTnsFilterOrderSWBTCX10( const int16_t value, const int16_t index ); +int16_t DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, const int16_t index, int16_t *pValue ); +int16_t GetTnsFilterOrderBitsSWBTCX20( const int16_t value, const int16_t index ); +int16_t EncodeTnsFilterOrderSWBTCX20( const int16_t value, const int16_t index ); +int16_t DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, const int16_t index, int16_t *pValue ); +int16_t GetTnsFilterOrderBits( const int16_t value, const int16_t index ); +int16_t EncodeTnsFilterOrder( const int16_t value, const int16_t index ); +int16_t DecodeTnsFilterOrder( Decoder_State *st, const int16_t index, int16_t *pValue ); void ResetTnsData( STnsData *pTnsData ); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 881d7845cacfc257f4aff3225a8c129a81f0f9ca..20e679c3167406981d5131f6f325e9defa87e545 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -287,67 +287,67 @@ static int16_t DecodeUsingTable( Decoder_State *st, int16_t *pValue, const Codin /* TNS filter coefficients */ -void const *GetTnsFilterCoeff( void const *p, int16_t index, int16_t *pValue ) +void const *GetTnsFilterCoeff( void const *p, const int16_t index, int16_t *pValue ) { *pValue = ( (int16_t const *) p )[index] + INDEX_SHIFT; return NULL; } -void *SetTnsFilterCoeff( void *p, int16_t index, int16_t value ) +void *SetTnsFilterCoeff( void *p, const int16_t index, const int16_t value ) { ( (int16_t *) p )[index] = value - INDEX_SHIFT; return NULL; } -int16_t GetSWBTCX20TnsFilterCoeffBits( int16_t value, int16_t index ) +int16_t GetSWBTCX20TnsFilterCoeffBits( const int16_t value, const int16_t index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return GetBitsFromTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -int16_t EncodeSWBTCX20TnsFilterCoeff( int16_t value, int16_t index ) +int16_t EncodeSWBTCX20TnsFilterCoeff( const int16_t value, const int16_t index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return EncodeUsingTable( value, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -int16_t DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t *pValue ) +int16_t DecodeSWBTCX20TnsFilterCoeff( Decoder_State *st, const int16_t index, int16_t *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -int16_t GetSWBTCX10TnsFilterCoeffBits( int16_t value, int16_t index ) +int16_t GetSWBTCX10TnsFilterCoeffBits( const int16_t value, const int16_t index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -int16_t EncodeSWBTCX10TnsFilterCoeff( int16_t value, int16_t index ) +int16_t EncodeSWBTCX10TnsFilterCoeff( const int16_t value, const int16_t index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -int16_t DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t *pValue ) +int16_t DecodeSWBTCX10TnsFilterCoeff( Decoder_State *st, const int16_t index, int16_t *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -int16_t GetWBTCX20TnsFilterCoeffBits( int16_t value, int16_t index ) +int16_t GetWBTCX20TnsFilterCoeffBits( const int16_t value, const int16_t index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); } -int16_t EncodeWBTCX20TnsFilterCoeff( int16_t value, int16_t index ) +int16_t EncodeWBTCX20TnsFilterCoeff( const int16_t value, const int16_t index ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); } -int16_t DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t *pValue ) +int16_t DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, const int16_t index, int16_t *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); @@ -356,67 +356,67 @@ int16_t DecodeWBTCX20TnsFilterCoeff( Decoder_State *st, int16_t index, int16_t * /* TNS filter order */ -void const *GetTnsFilterOrder( void const *p, int16_t index, int16_t *pValue ) +void const *GetTnsFilterOrder( void const *p, const int16_t index, int16_t *pValue ) { *pValue = ( (STnsFilter const *) p )[index].order; return ( (STnsFilter const *) p )[index].coefIndex; } -void *SetTnsFilterOrder( void *p, int16_t index, int16_t value ) +void *SetTnsFilterOrder( void *p, const int16_t index, const int16_t value ) { ( (STnsFilter *) p )[index].order = value; return ( (STnsFilter *) p )[index].coefIndex; } -int16_t GetTnsFilterOrderBitsSWBTCX20( int16_t value, int16_t index ) +int16_t GetTnsFilterOrderBitsSWBTCX20( const int16_t value, const int16_t index ) { (void) index; return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); } -int16_t EncodeTnsFilterOrderSWBTCX20( int16_t value, int16_t index ) +int16_t EncodeTnsFilterOrderSWBTCX20( const int16_t value, const int16_t index ) { (void) index; return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); } -int16_t DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, int16_t index, int16_t *pValue ) +int16_t DecodeTnsFilterOrderSWBTCX20( Decoder_State *st, const int16_t index, int16_t *pValue ) { (void) index; return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); } -int16_t GetTnsFilterOrderBitsSWBTCX10( int16_t value, int16_t index ) +int16_t GetTnsFilterOrderBitsSWBTCX10( const int16_t value, const int16_t index ) { (void) index; return GetBitsFromTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); } -int16_t EncodeTnsFilterOrderSWBTCX10( int16_t value, int16_t index ) +int16_t EncodeTnsFilterOrderSWBTCX10( const int16_t value, const int16_t index ) { (void) index; return EncodeUsingTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); } -int16_t DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, int16_t index, int16_t *pValue ) +int16_t DecodeTnsFilterOrderSWBTCX10( Decoder_State *st, const int16_t index, int16_t *pValue ) { (void) index; return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); } -int16_t GetTnsFilterOrderBits( int16_t value, int16_t index ) +int16_t GetTnsFilterOrderBits( const int16_t value, const int16_t index ) { (void) index; return GetBitsFromTable( value - 1, codesTnsOrder, nTnsOrderCodes ); } -int16_t EncodeTnsFilterOrder( int16_t value, int16_t index ) +int16_t EncodeTnsFilterOrder( const int16_t value, const int16_t index ) { (void) index; return EncodeUsingTable( value - 1, codesTnsOrder, nTnsOrderCodes ); } -int16_t DecodeTnsFilterOrder( Decoder_State *st, int16_t index, int16_t *pValue ) +int16_t DecodeTnsFilterOrder( Decoder_State *st, const int16_t index, int16_t *pValue ) { (void) index; return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); @@ -424,13 +424,13 @@ int16_t DecodeTnsFilterOrder( Decoder_State *st, int16_t index, int16_t *pValue /* Number of TNS filters */ -void const *GetNumOfTnsFilters( void const *p, int16_t index, int16_t *pValue ) +void const *GetNumOfTnsFilters( void const *p, const int16_t index, int16_t *pValue ) { *pValue = (int16_t) abs( ( (STnsData const *) p )[index].nFilters ); return ( (STnsData const *) p )[index].filter; } -void *SetNumOfTnsFilters( void *p, int16_t index, int16_t value ) +void *SetNumOfTnsFilters( void *p, const int16_t index, const int16_t value ) { ( (STnsData *) p )[index].nFilters = (int16_t) abs( value ); return ( (STnsData *) p )[index].filter; @@ -438,13 +438,13 @@ void *SetNumOfTnsFilters( void *p, int16_t index, int16_t value ) /* TNS enabled/disabled flag */ -void const *GetTnsEnabled( void const *p, int16_t index, int16_t *pValue ) +void const *GetTnsEnabled( void const *p, const int16_t index, int16_t *pValue ) { *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; return NULL; } -void *SetTnsEnabled( void *p, int16_t index, int16_t value ) +void *SetTnsEnabled( void *p, const int16_t index, const int16_t value ) { (void) p, (void) index, (void) value; return NULL; @@ -452,25 +452,25 @@ void *SetTnsEnabled( void *p, int16_t index, int16_t value ) /* TNS on whitened spectra flag */ -void const *GetTnsOnWhite( void const *p, int16_t index, int16_t *pValue ) +void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ) { *pValue = ( (STnsData const *) p )[index].tnsOnWhitenedSpectra > 0 ? 1 : 0; return NULL; } -void *SetTnsOnWhite( void *p, int16_t index, int16_t value ) +void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ) { ( (STnsData *) p )[index].tnsOnWhitenedSpectra = value; return NULL; } -void const *GetTnsEnabledSingleFilter( void const *p, int16_t index, int16_t *pValue ) +void const *GetTnsEnabledSingleFilter( void const *p, const int16_t index, int16_t *pValue ) { *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; return ( (STnsData const *) p )[index].filter; } -void *SetTnsEnabledSingleFilter( void *p, int16_t index, int16_t value ) +void *SetTnsEnabledSingleFilter( void *p, const int16_t index, const int16_t value ) { ( (STnsData *) p )[index].nFilters = value; return ( (STnsData *) p )[index].filter; diff --git a/lib_com/wi.c b/lib_com/wi.c index 7710f75789516faae113d2ffaa8b69cda4e42a83..7ec30010fe0365b2eb6a84cc8a295790afd98ca8 100644 --- a/lib_com/wi.c +++ b/lib_com/wi.c @@ -73,9 +73,7 @@ ivas_error DTFS_new( int16_t i; DTFS_STRUCTURE *dtfs = NULL; - dtfs = (DTFS_STRUCTURE *) malloc( sizeof( DTFS_STRUCTURE ) ); - - if ( dtfs == NULL ) + if ( ( dtfs = (DTFS_STRUCTURE *) malloc( sizeof( DTFS_STRUCTURE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTFS (SC-VBR) structure\n" ) ); } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 971841e26a2a04b057a9ef218432104100abb360..515188369cafb393093b0e59c546038841cfe018 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -58,6 +58,14 @@ #define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */ #define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ + +/*------------------------------------------------------------------- + * Local fucntions declarations + *-------------------------------------------------------------------*/ + +static void perform_noise_estimation_dec( const float *timeDomainInput, float *power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, const int16_t element_mode, const int16_t bwidth, const int16_t L_frame, const int16_t last_L_frame, const int32_t last_core_brate, const int16_t VAD ); + + /*------------------------------------------------------------------- * createFdCngDec() * @@ -75,8 +83,7 @@ ivas_error createFdCngDec( *hFdCngDec = NULL; /* Allocate memory */ - hs = (HANDLE_FD_CNG_DEC) malloc( sizeof( FD_CNG_DEC ) ); - if ( hs == NULL ) + if ( ( hs = (HANDLE_FD_CNG_DEC) malloc( sizeof( FD_CNG_DEC ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG DEC structure" ); } @@ -619,7 +626,7 @@ void ApplyFdCng( * Perform noise estimation at the decoder *-------------------------------------------------------------------*/ -void perform_noise_estimation_dec( +static void perform_noise_estimation_dec( const float *timeDomainInput, float *power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ diff --git a/lib_dec/hq_lr_dec.c b/lib_dec/hq_lr_dec.c index 81f4c1b284460f451ce60e2b6b367250089a34a4..774720844c56abf7a28ea7cd13c4c312153f9077 100644 --- a/lib_dec/hq_lr_dec.c +++ b/lib_dec/hq_lr_dec.c @@ -238,7 +238,7 @@ void hq_lr_dec( if ( flag_spt == 1 ) { - /* initalize the desired parameters for SPT */ + /* initialize the desired parameters for SPT */ spt_shorten_domain_band_save( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); spt_shorten_domain_pre( band_start, band_end, hHQ_core->prev_SWB_peak_pos, bands, bwe_br, new_band_start, new_band_end, new_band_width ); spt_shorten_domain_set_dec( st, p2a_flags, new_band_start, new_band_end, new_band_width, bands, band_start, band_end, band_width, &bit_budget ); diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index bb2b75318116177bc34c6ed300d93135de535430..492339d6d6d7b83e6316e4c5b6e00d7ccb633b3b 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -33,11 +33,7 @@ #include "options.h" #include "ivas_cnst.h" #include "ivas_prot.h" -#include "ivas_rom_com.h" -#include "ivas_stat_enc.h" #include "prot.h" -#include -#include #include #ifdef DEBUGGING #include "debug.h" @@ -74,9 +70,9 @@ ivas_error ivas_corecoder_dec_reconfig( hDecoderConfig = st_ivas->hDecoderConfig; ivas_total_brate = hDecoderConfig->ivas_total_brate; + output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); error = IVAS_ERR_OK; - output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); if ( st_ivas->ivas_format == MC_FORMAT ) { last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ @@ -85,8 +81,9 @@ ivas_error ivas_corecoder_dec_reconfig( { last_mc_mode = MC_MODE_NONE; } + /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SCE/CPE/MCT handles + * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ /* remove dummy CPE element for DFT stereo-like upmix */ @@ -119,6 +116,7 @@ ivas_error ivas_corecoder_dec_reconfig( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -139,7 +137,6 @@ ivas_error ivas_corecoder_dec_reconfig( nSCE_existing = min( nSCE_old, st_ivas->nSCE ); nCPE_existing = min( nCPE_old, st_ivas->nCPE ); - // VE: TBV - try to reuse the CoreCoder /* destroy superfluous core coder elements */ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) { @@ -192,6 +189,7 @@ ivas_error ivas_corecoder_dec_reconfig( for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -271,7 +269,6 @@ ivas_error ivas_corecoder_dec_reconfig( return error; } - // VE: TBV - just reset for now set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) ); st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ @@ -512,10 +509,12 @@ ivas_error ivas_cldfb_dec_reconfig( } } } + /* CLDFB Interpolation weights */ if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses || nchan_transport_old != st_ivas->nchan_transport ) ) { ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); } + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index de8dde9828fe1ff66492fc5b79585bb05212a0e1..ca4666ae769ce3fa3341a149cd01e74072589d6e 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -215,7 +215,10 @@ ivas_error ivas_dec( /* Binaural rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - ivas_td_binaural_renderer( st_ivas, output, output_frame ); + if ( ( ivas_td_binaural_renderer( st_ivas, output, output_frame ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) { @@ -451,7 +454,10 @@ ivas_error ivas_dec( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { - ivas_td_binaural_renderer( st_ivas, output, output_frame ); + if ( ( ivas_td_binaural_renderer( st_ivas, output, output_frame ) ) != IVAS_ERR_OK ) + { + return error; + } ivas_binaural_add_LFE( st_ivas, output_frame, output ); } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 14b8d91affd23b657996cce64e8b4155c1cceba2..649cd43b5c5a7973edad50947aa3c002fdecca1a 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -51,7 +51,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); +static ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); @@ -297,7 +297,10 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { hDirAC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); - hDirAC->frequency_axis = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + if ( ( hDirAC->frequency_axis = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->frequency_axis, 0.0f, hDirAC->num_freq_bands ); ivas_dirac_dec_get_frequency_axis( hDirAC->frequency_axis, output_Fs, hDirAC->num_freq_bands ); @@ -307,7 +310,10 @@ ivas_error ivas_dirac_dec_config( { if ( ( flag_config == DIRAC_RECONFIGURE && hDirAC->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN ) { - hDirAC->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ); + if ( ( hDirAC->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } ivas_masa_init_stereotype_detection( hDirAC->masa_stereo_type_detect ); } @@ -375,22 +381,34 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { num_outputs_dir_old = hDirAC->num_outputs_dir; - hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ); + if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } num_outputs_diff_old = hDirAC->num_outputs_diff; - hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ); + if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } if ( hDirAC->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) { free( hDirAC->proto_index_dir ); - hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ); + if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } set_s( hDirAC->proto_index_dir, 0, hDirAC->num_outputs_dir ); if ( hDirAC->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE ) { free( hDirAC->proto_index_diff ); - hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ); + if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } set_s( hDirAC->proto_index_diff, 0, hDirAC->num_outputs_diff ); @@ -510,14 +528,20 @@ ivas_error ivas_dirac_dec_config( /* direct/diffuse responses */ if ( flag_config == DIRAC_OPEN ) { - hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ); + if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } /* reallocate static memory */ else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->num_outputs_dir != num_outputs_dir_old ) { free( hDirAC->diffuse_response_function ); hDirAC->diffuse_response_function = NULL; - hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ); + if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } if ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) @@ -535,13 +559,19 @@ ivas_error ivas_dirac_dec_config( { if ( flag_config == DIRAC_OPEN ) { - hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ); + if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder && ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) { free( hDirAC->hoa_encoder ); hDirAC->hoa_encoder = NULL; - hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ); + if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } set_f( hDirAC->hoa_encoder, 0.0f, nchan_out_woLFE * hDirAC->num_outputs_diff ); compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirAC->hoa_encoder, hDirAC->num_outputs_diff, hDirAC->hOutSetup.ambisonics_order ); @@ -623,15 +653,18 @@ ivas_error ivas_dirac_dec_config( if ( ( flag_config == DIRAC_OPEN && hDirAC->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { - ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, - nchan_transport > 2 ? 4 : nchan_transport, - output_Fs ); + if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), + &( hDirAC->h_freq_domain_decorr_ap_state ), + hDirAC->num_freq_bands, + hDirAC->num_outputs_diff, + hDirAC->num_protos_diff, + hDirAC->synthesisConf, + hDirAC->frequency_axis, + nchan_transport > 2 ? 4 : nchan_transport, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { @@ -644,28 +677,38 @@ ivas_error ivas_dirac_dec_config( /* close and reopen the decorrelator */ ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); - ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, - nchan_transport > 2 ? 4 : nchan_transport, - output_Fs ); + if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), + &( hDirAC->h_freq_domain_decorr_ap_state ), + hDirAC->num_freq_bands, + hDirAC->num_outputs_diff, + hDirAC->num_protos_diff, + hDirAC->synthesisConf, + hDirAC->frequency_axis, + nchan_transport > 2 ? 4 : nchan_transport, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } } } /* output synthesis */ if ( flag_config == DIRAC_OPEN ) { - ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs ); + if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } hDirAC->h_output_synthesis_psd_params.use_onset_filters = hDirAC->proto_signal_decorr_on; } else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) ) { ivas_dirac_dec_output_synthesis_close( hDirAC ); - ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs ); + + if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } hDirAC->h_output_synthesis_psd_params.use_onset_filters = hDirAC->proto_signal_decorr_on; } @@ -690,13 +733,19 @@ ivas_error ivas_dirac_dec_config( { if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_frame_f == NULL ) ) { - hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ); + if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } else if ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->num_protos_diff != num_protos_diff_old ) ) { proto_frame_f_old = hDirAC->proto_frame_f; free( proto_frame_f_old ); - hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ); + if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } } @@ -713,13 +762,19 @@ ivas_error ivas_dirac_dec_config( { for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - hDirAC->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); } } if ( hDirAC->buffer_energy == NULL ) { - hDirAC->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); } @@ -751,7 +806,10 @@ ivas_error ivas_dirac_dec_config( { ivas_dirac_free_mem( &( hDirAC->stack_mem ) ); } - ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ) ); + if ( ( error = ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ) ) ) != IVAS_ERR_OK ) + { + return error; + } mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); @@ -801,45 +859,121 @@ ivas_error ivas_dirac_dec_config( } } - hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->diffuseness_vector = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); + if ( ( hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->diffuseness_vector = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { - hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + if ( ( hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_s( hDirAC->azimuth[i], 0, hDirAC->num_freq_bands ); - hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + + if ( ( hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_s( hDirAC->elevation[i], 0, hDirAC->num_freq_bands ); - hDirAC->diffuseness_vector[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->diffuseness_vector[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->diffuseness_vector[i], 1.0f, hDirAC->num_freq_bands ); - hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + if ( ( hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->spreadCoherence[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); } if ( st_ivas->ivas_format == MASA_FORMAT ) { - hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); + if ( ( hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { - hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + if ( ( hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_s( hDirAC->azimuth2[i], 0, hDirAC->num_freq_bands ); - hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + + if ( ( hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_s( hDirAC->elevation2[i], 0, hDirAC->num_freq_bands ); - hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + if ( ( hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->energy_ratio2[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands ); } } @@ -1103,7 +1237,7 @@ void ivas_dirac_dec_close( * Allocate stack memory for DirAC renderer *------------------------------------------------------------------------*/ -static void ivas_dirac_alloc_mem( +static ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) @@ -1130,17 +1264,35 @@ static void ivas_dirac_alloc_mem( hDirAC_mem->frame_dec_f = NULL; if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ); + if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->cy_auto_dir_smooth, size ); - hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ); + + if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->proto_power_smooth, size ); - hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ); + + if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->proto_power_diff_smooth, size ); - hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ); + + if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->direct_responses_square, size ); if ( hDirAC->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) { - hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ); + if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; @@ -1149,23 +1301,36 @@ static void ivas_dirac_alloc_mem( hDirAC->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; /* Target and smoothed nrg factors/gains */ - hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size ); + if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->cy_cross_dir_smooth, size ); + if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ); + if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->cy_auto_diff_smooth, size ); } else { - hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ); + if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff ); } hDirAC->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; hDirAC->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; /*Responses (gains/factors)*/ - hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size ); + if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } set_zero( hDirAC_mem->direct_responses, size ); hDirAC->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses; @@ -1174,16 +1339,26 @@ static void ivas_dirac_alloc_mem( hDirAC_mem->proto_diffuse_buffer_f = NULL; if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { - hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ); + if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + if ( hDirAC->proto_signal_decorr_on ) { if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ); + if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } else { - hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ); + if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } } @@ -1195,8 +1370,15 @@ static void ivas_dirac_alloc_mem( hDirAC_mem->diffuse_power_factor = NULL; if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { - hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ); - hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ); + if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + + if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } hDirAC->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; hDirAC->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; @@ -1207,10 +1389,16 @@ static void ivas_dirac_alloc_mem( { if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { - hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ); + if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } if ( hDirAC->proto_signal_decorr_on ) { - hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ); + if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } } @@ -1218,15 +1406,22 @@ static void ivas_dirac_alloc_mem( { if ( num_protos_dir > 2 ) { - hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ); + if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } + if ( hDirAC->proto_signal_decorr_on ) { - hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ); + if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } - return; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dirac_decorr_dec.c b/lib_dec/ivas_dirac_decorr_dec.c index 2d82bb0a3a6f334c13d22682272c7f653d138c1b..bcaa6cf2a13916ccb0b68bd275d0f243ba4df33d 100644 --- a/lib_dec/ivas_dirac_decorr_dec.c +++ b/lib_dec/ivas_dirac_decorr_dec.c @@ -70,10 +70,10 @@ static void lattice2allpass( const int16_t filter_length, const float *lattice_c /*------------------------------------------------------------------------- * ivas_dirac_dec_decorr_open() * - * + * Allocate and initialize TD decorrelator decoder handle *------------------------------------------------------------------------*/ -void ivas_dirac_dec_decorr_open( +ivas_error ivas_dirac_dec_decorr_open( DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state, const int16_t num_freq_bands, @@ -91,6 +91,7 @@ void ivas_dirac_dec_decorr_open( int16_t split_frequencies_bands[DIRAC_DECORR_NUM_SPLIT_BANDS + 1] = { 0, 0, 0, 23768 }; int16_t *split_freq_ptr; float cur_lattice_delta_phi, lattice_coeffs[2 * DIRAC_MAX_DECORR_FILTER_LEN]; + ivas_error error; /* pointers to structs for allocation */ DIRAC_DECORR_PARAMS *freq_domain_decorr_ap_params = NULL; @@ -101,8 +102,15 @@ void ivas_dirac_dec_decorr_open( *-----------------------------------------------------------------*/ /* allocate structs */ - freq_domain_decorr_ap_params = (DIRAC_DECORR_PARAMS *) malloc( sizeof( DIRAC_DECORR_PARAMS ) ); - freq_domain_decorr_ap_state = (DIRAC_DECORR_STATE *) malloc( sizeof( DIRAC_DECORR_STATE ) ); + if ( ( freq_domain_decorr_ap_params = (DIRAC_DECORR_PARAMS *) malloc( sizeof( DIRAC_DECORR_PARAMS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + + if ( ( freq_domain_decorr_ap_state = (DIRAC_DECORR_STATE *) malloc( sizeof( DIRAC_DECORR_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } /*-----------------------------------------------------------------* * check input parameters @@ -164,7 +172,6 @@ void ivas_dirac_dec_decorr_open( } } - /*-----------------------------------------------------------------* * open sub-modules *-----------------------------------------------------------------*/ @@ -173,21 +180,17 @@ void ivas_dirac_dec_decorr_open( if ( synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*Onset detector up to Nyquist and not only up to max_band_decorr*/ - ivas_dirac_dec_onset_detection_open( - num_protos_diff, - num_freq_bands, - num_freq_bands, - &freq_domain_decorr_ap_params->h_onset_detection_power_params, - &freq_domain_decorr_ap_state->h_onset_detection_power_state ); + if ( ( error = ivas_dirac_dec_onset_detection_open( num_protos_diff, num_freq_bands, num_freq_bands, &freq_domain_decorr_ap_params->h_onset_detection_power_params, &freq_domain_decorr_ap_state->h_onset_detection_power_state ) ) != IVAS_ERR_OK ) + { + return error; + } } else { - ivas_dirac_dec_onset_detection_open( - num_protos_diff, - num_freq_bands, - freq_domain_decorr_ap_params->max_band_decorr, - &freq_domain_decorr_ap_params->h_onset_detection_power_params, - &freq_domain_decorr_ap_state->h_onset_detection_power_state ); + if ( ( error = ivas_dirac_dec_onset_detection_open( num_protos_diff, num_freq_bands, freq_domain_decorr_ap_params->max_band_decorr, &freq_domain_decorr_ap_params->h_onset_detection_power_params, &freq_domain_decorr_ap_state->h_onset_detection_power_state ) ) != IVAS_ERR_OK ) + { + return error; + } } /*-----------------------------------------------------------------* @@ -215,7 +218,10 @@ void ivas_dirac_dec_decorr_open( } } - freq_domain_decorr_ap_params->split_frequency_bands = (int16_t *) malloc( sizeof( int16_t ) * ( freq_domain_decorr_ap_params->num_split_frequency_bands + 1 ) ); + if ( ( freq_domain_decorr_ap_params->split_frequency_bands = (int16_t *) malloc( sizeof( int16_t ) * ( freq_domain_decorr_ap_params->num_split_frequency_bands + 1 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } mvs2s( &split_frequencies_bands[0], freq_domain_decorr_ap_params->split_frequency_bands, freq_domain_decorr_ap_params->num_split_frequency_bands + 1 ); /* calc buffer size and allocate arrays */ @@ -232,18 +238,50 @@ void ivas_dirac_dec_decorr_open( if ( num_outputs_diff > 0 ) { buffer_size_decorr = ( ap_pre_delay[split_band_index_start] + ap_filter_length[split_band_index_start] ); - freq_domain_decorr_ap_state->decorr_buffer = (float *) malloc( sizeof( float ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ); + if ( ( freq_domain_decorr_ap_state->decorr_buffer = (float *) malloc( sizeof( float ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } set_f( freq_domain_decorr_ap_state->decorr_buffer, 0.0f, 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ); - freq_domain_decorr_ap_params->filter_coeff_num_real = (float *) malloc( sizeof( float ) * ( ap_filter_length[split_band_index_start] + 1 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - freq_domain_decorr_ap_params->filter_coeff_den_real = (float *) malloc( sizeof( float ) * ( ap_filter_length[split_band_index_start] + 1 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - freq_domain_decorr_ap_params->phase_coeff_real = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - freq_domain_decorr_ap_params->phase_coeff_imag = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - freq_domain_decorr_ap_state->direct_energy_smooth = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - freq_domain_decorr_ap_state->reverb_energy_smooth = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); + if ( ( freq_domain_decorr_ap_params->filter_coeff_num_real = (float *) malloc( sizeof( float ) * ( ap_filter_length[split_band_index_start] + 1 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } - freq_domain_decorr_ap_params->pre_delay = (int16_t *) malloc( sizeof( int16_t ) * freq_domain_decorr_ap_params->num_split_frequency_bands ); - freq_domain_decorr_ap_params->filter_length = (int16_t *) malloc( sizeof( int16_t ) * freq_domain_decorr_ap_params->num_split_frequency_bands ); + if ( ( freq_domain_decorr_ap_params->filter_coeff_den_real = (float *) malloc( sizeof( float ) * ( ap_filter_length[split_band_index_start] + 1 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + + if ( ( freq_domain_decorr_ap_params->phase_coeff_real = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + + if ( ( freq_domain_decorr_ap_params->phase_coeff_imag = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + + if ( ( freq_domain_decorr_ap_state->direct_energy_smooth = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + + if ( ( freq_domain_decorr_ap_state->reverb_energy_smooth = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + + if ( ( freq_domain_decorr_ap_params->pre_delay = (int16_t *) malloc( sizeof( int16_t ) * freq_domain_decorr_ap_params->num_split_frequency_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } + if ( ( freq_domain_decorr_ap_params->filter_length = (int16_t *) malloc( sizeof( int16_t ) * freq_domain_decorr_ap_params->num_split_frequency_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); + } set_f( freq_domain_decorr_ap_state->direct_energy_smooth, 0.0f, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); set_f( freq_domain_decorr_ap_state->reverb_energy_smooth, 0.0f, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); @@ -280,7 +318,7 @@ void ivas_dirac_dec_decorr_open( *ph_freq_domain_decorr_ap_params = freq_domain_decorr_ap_params; *ph_freq_domain_decorr_ap_state = freq_domain_decorr_ap_state; - return; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dirac_onsets_dec.c b/lib_dec/ivas_dirac_onsets_dec.c index 050ec5acddaf17a39a0492972f1b1b0d84106fb7..c094b45ff68aa32a7770f677b3c61e70b763f127 100644 --- a/lib_dec/ivas_dirac_onsets_dec.c +++ b/lib_dec/ivas_dirac_onsets_dec.c @@ -51,7 +51,7 @@ * onset detection *------------------------------------------------------------------------*/ -void ivas_dirac_dec_onset_detection_open( +ivas_error ivas_dirac_dec_onset_detection_open( const int16_t num_protos_diff, const int16_t num_freq_bands, const int16_t max_band_decorr, @@ -69,14 +69,20 @@ void ivas_dirac_dec_onset_detection_open( dirac_onset_detection_params->max_band_decorr = max_band_decorr; /* memory allocation */ - dirac_onset_detection_state->onset_detector_1 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ); - dirac_onset_detection_state->onset_detector_2 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ); + if ( ( dirac_onset_detection_state->onset_detector_1 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) ); + } + if ( ( dirac_onset_detection_state->onset_detector_2 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) ); + } /* init to zero */ set_zero( dirac_onset_detection_state->onset_detector_1, num_protos_diff * dirac_onset_detection_params->max_band_decorr ); set_zero( dirac_onset_detection_state->onset_detector_2, num_protos_diff * dirac_onset_detection_params->max_band_decorr ); - return; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 79560aae63f2ffd3ef2e0a7511ea0be63a025989..6a79d4563a4a13e141bc0e64f80819dd4ab7af59 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -58,7 +58,7 @@ * Sets up the state and parameters for the Covariance Synthesis *-------------------------------------------------------------------*/ -void ivas_dirac_dec_output_synthesis_cov_open( +ivas_error ivas_dirac_dec_output_synthesis_cov_open( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: hanlde for the covariance synthesis state */ const int16_t max_band_decorr, /* i : uppermost frequency band where decorrelation is applied */ @@ -80,15 +80,27 @@ void ivas_dirac_dec_output_synthesis_cov_open( /* buffer length and interpolator */ h_dirac_output_synthesis_params->alpha_synthesis = NULL; - h_dirac_output_synthesis_params->proto_matrix = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ); + if ( ( h_dirac_output_synthesis_params->proto_matrix = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } /* cov buffers */ for ( idx = 0; idx < num_param_bands; idx++ ) { - h_dirac_output_synthesis_state->cx_old[idx] = (float *) malloc( nchan_in * nchan_in * sizeof( float ) ); - h_dirac_output_synthesis_state->cy_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ); - h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ); + if ( ( h_dirac_output_synthesis_state->cx_old[idx] = (float *) malloc( nchan_in * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + if ( ( h_dirac_output_synthesis_state->cy_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + if ( ( h_dirac_output_synthesis_state->mixing_matrix_old[idx] = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } set_zero( h_dirac_output_synthesis_state->cx_old[idx], nchan_in * nchan_in ); set_zero( h_dirac_output_synthesis_state->cy_old[idx], nchan_out * nchan_out ); set_zero( h_dirac_output_synthesis_state->mixing_matrix_old[idx], nchan_out * nchan_in ); @@ -101,7 +113,10 @@ void ivas_dirac_dec_output_synthesis_cov_open( } for ( idx = 0; idx < num_param_bands_residual; idx++ ) { - h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ); + if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx] = (float *) malloc( nchan_out * nchan_out * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } set_zero( h_dirac_output_synthesis_state->mixing_matrix_res_old[idx], nchan_out * nchan_out ); } for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) @@ -114,7 +129,11 @@ void ivas_dirac_dec_output_synthesis_cov_open( *-----------------------------------------------------------------*/ /* compute interpolator */ - h_dirac_output_synthesis_params->interpolator = (float *) malloc( interp_length * sizeof( float ) ); + if ( ( h_dirac_output_synthesis_params->interpolator = (float *) malloc( interp_length * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); + } + for ( idx = 1; idx <= interp_length; ++idx ) { h_dirac_output_synthesis_params->interpolator[idx - 1] = (float) idx / (float) interp_length; @@ -122,7 +141,7 @@ void ivas_dirac_dec_output_synthesis_cov_open( mvr2r( proto_matrix, h_dirac_output_synthesis_params->proto_matrix, nchan_in * nchan_out ); - return; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 5cf1c8b2daa46594166905ef4d81e8a7a66cdfc7..3541bc5cfe44b7cd35728ae4bd86534e37ee5e7e 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -86,7 +86,7 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha * *------------------------------------------------------------------------*/ -void ivas_dirac_dec_output_synthesis_open( +ivas_error ivas_dirac_dec_output_synthesis_open( DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ RENDERER_TYPE renderer_type, /* i : renderer type */ const int16_t nchan_transport, /* i : number of transport channels*/ @@ -126,22 +126,34 @@ void ivas_dirac_dec_output_synthesis_open( dirac_output_synthesis_state->diffuse_responses_square = NULL; if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) { - dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( 2 * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( 2 * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } /* prototype power buffers */ dirac_output_synthesis_state->proto_power_smooth_prev = NULL; if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_protos_dir * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_protos_dir * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) { - dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } else { @@ -149,41 +161,74 @@ void ivas_dirac_dec_output_synthesis_open( } /* buffer length and interpolator */ - dirac_output_synthesis_params->interpolator = (float *) malloc( hDirAC->subframe_nbslots * sizeof( float ) ); + if ( ( dirac_output_synthesis_params->interpolator = (float *) malloc( hDirAC->subframe_nbslots * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } /* target PSD buffers */ - dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; - dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } else { - dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } else { - dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } } /* direct and diffuse gain buffers */ - dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirAC->synthesisConf != DIRAC_SYNTHESIS_MONO ) { - dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } else { - dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } } /*-----------------------------------------------------------------* @@ -194,15 +239,27 @@ void ivas_dirac_dec_output_synthesis_open( if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hDirAC->slot_size, hDirAC->num_freq_bands, hDirAC->frequency_axis, output_Fs ); - dirac_output_synthesis_params->alpha_synthesis = (float *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( float ) ); + if ( ( dirac_output_synthesis_params->alpha_synthesis = (float *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas ); computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hDirAC->slot_size, hDirAC->num_freq_bands, hDirAC->frequency_axis, output_Fs ); - dirac_output_synthesis_params->alpha_synthesis_fast = (float *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( float ) ); + if ( ( dirac_output_synthesis_params->alpha_synthesis_fast = (float *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast ); - dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); - dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } + if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); + } set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hDirAC->num_freq_bands ); set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hDirAC->num_freq_bands ); } @@ -276,7 +333,7 @@ void ivas_dirac_dec_output_synthesis_open( dirac_output_synthesis_params->diffuse_compensation_factor_decorr = 0.f; } - return; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 4ac8658822b73052497a72e4362d556699cfd7ad..25813f34b24c4b709ca15ddddc1e9a63ecbea38c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -822,7 +822,7 @@ ivas_error ivas_init_decoder( } } - if ( ( error = create_ism_metadata_dec( st_ivas, st_ivas->nSCE, element_brate_tmp ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nSCE, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -1381,7 +1381,10 @@ ivas_error ivas_init_decoder( * Allocate and initialize limiter struct *-----------------------------------------------------------------*/ - st_ivas->hLimiter = ivas_limiter_open( hDecoderConfig->nchan_out, output_Fs ); + if ( ( st_ivas->hLimiter = ivas_limiter_open( hDecoderConfig->nchan_out, output_Fs ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to open limiter handle" ); + } return error; } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 6f07130d1d2aa77f5c5b4b626b081ec8c64f63f7..0bda9f5ae033f20287d0068835d357d9e9b04d3f 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -62,14 +62,34 @@ static ivas_error ivas_ism_bitrate_switching( nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; - ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); + if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + st_ivas->nSCE = st_ivas->nchan_transport; - ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ - ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Initialize the needed renderer struct and destroy the unnecessary renderer struct */ + /*-----------------------------------------------------------------* + * Initialize the needed renderer struct and destroy the unnecessary renderer struct + *-----------------------------------------------------------------*/ /* select the renderer */ ivas_renderer_select( st_ivas ); @@ -85,10 +105,13 @@ static ivas_error ivas_ism_bitrate_switching( efap_free_data( &st_ivas->hEFAPdata ); } + /*-----------------------------------------------------------------* + * Switching between ParamISM and DiscISM + *-----------------------------------------------------------------*/ + + /* switching from ParamISM to DiscISM */ if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { - /* switching from ParamISM to DiscISM */ - /* Deallocate the ParamISM struct */ if ( st_ivas->hDirAC != NULL ) { @@ -102,7 +125,10 @@ static ivas_error ivas_ism_bitrate_switching( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open the TD Binaural renderer */ - ivas_td_binaural_open( st_ivas ); + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } else { @@ -112,7 +138,11 @@ static ivas_error ivas_ism_bitrate_switching( free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } - ivas_ism_renderer_open( st_ivas ); + + if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) @@ -132,6 +162,7 @@ static ivas_error ivas_ism_bitrate_switching( { return error; } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; #else ivas_crend_open( st_ivas ); @@ -139,18 +170,27 @@ static ivas_error ivas_ism_bitrate_switching( } } + /* switching from Discrete ISM to ParamISM */ if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { - /* switching from Discrete ISM to ParamISM */ - /* Allocate and initialize the ParamISM struct */ - ivas_param_ism_dec_open( st_ivas ); + if ( ( error = ivas_param_ism_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL ) { /* open the parametric binaural renderer */ - ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ); - ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ); + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } /* Close the TD Binaural renderer */ if ( st_ivas->hBinRendererTd != NULL ) @@ -176,8 +216,15 @@ static ivas_error ivas_ism_bitrate_switching( if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) { /* open the parametric binaural renderer */ - ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ); - ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ); + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } /* close the crend binaural renderer */ #ifdef FIX_197_CREND_INTERFACE diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 94784e435c263bf464ec9b469298b7c3b106b0e2..53c1e9d2e9d4d4e920fa304b9944f9b130940599 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -455,7 +455,10 @@ ivas_error ivas_ism_metadata_dec( if ( !bfi ) { - ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); + if ( ( error = ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ) ) != IVAS_ERR_OK ) + { + return error; + } for ( ch = 0; ch < *nchan_transport; ch++ ) { @@ -513,18 +516,19 @@ ivas_error ivas_ism_metadata_dec( /*------------------------------------------------------------------------- - * create_ism_metadata_dec() + * ivas_ism_metadata_dec_create() * - * Create, allocate, initialize and configure IVAS decoder ISM handles + * Create, allocate, initialize and configure IVAS decoder ISM metadata handles *-------------------------------------------------------------------------*/ -ivas_error create_ism_metadata_dec( +ivas_error ivas_ism_metadata_dec_create( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t n_ISms, /* i : number of objects */ int32_t element_brate_tmp[] /* o : element bitrate per object */ ) { int16_t ch; + ivas_error error; /* allocate ISm metadata handles */ for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ ) @@ -541,7 +545,10 @@ ivas_error create_ism_metadata_dec( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); + if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index dea3e6d6f86d3020472a03d26a96664f83d94954..81a4744726d7805f543e3d7d2b3feec0c2c9cad2 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -516,34 +516,105 @@ ivas_error ivas_param_ism_dec_open( if ( ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM ) ) { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); - hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); - hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ); + if ( ( hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + + if ( ( hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } + for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) { - hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + if ( ( hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_s( hDirAC->azimuth[i], 0, hDirAC->num_freq_bands ); - hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + + if ( ( hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_s( hDirAC->elevation[i], 0, hDirAC->num_freq_bands ); - hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + + if ( ( hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_s( hDirAC->azimuth2[i], 0, hDirAC->num_freq_bands ); - hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ); + + if ( ( hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_s( hDirAC->elevation2[i], 0, hDirAC->num_freq_bands ); - hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_f( hDirAC->spreadCoherence[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_f( hDirAC->energy_ratio2[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_f( hDirAC->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands ); - hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ); + + if ( ( hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM Rendering handle\n" ) ); + } set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 28c25de4a3e382716035e205bd691618da133b7c..b8b7b74ffc51647d6d466e68ea325f111014fd4b 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -68,7 +68,7 @@ static void replicate_subframes( IVAS_QMETADATA_HANDLE hQMetaData ); static void restore_lowbitrate_masa( IVAS_QMETADATA_HANDLE hQMetaData, const int16_t low_bitrate_mode, const int16_t numCodingBands ); -static void init_lfe_synth_data( Decoder_Struct *st_ivas, MASA_DECODER_HANDLE hMasa ); +static ivas_error init_lfe_synth_data( Decoder_Struct *st_ivas, MASA_DECODER_HANDLE hMasa ); static void compute_foa_cov_matrix( float foaCov[FOA_CHANNELS][FOA_CHANNELS], float inCov[FOA_CHANNELS][FOA_CHANNELS], float mixMtx[FOA_CHANNELS][FOA_CHANNELS] ); @@ -314,6 +314,7 @@ ivas_error ivas_masa_decode( create_masa_ext_out_meta( hMasa, hQMetaData, st_ivas->nchan_transport ); } #endif + return error /* *nb_bits_read*/; } @@ -329,6 +330,9 @@ ivas_error ivas_masa_dec_open( ) { MASA_DECODER_HANDLE hMasa; + ivas_error error; + + error = IVAS_ERR_OK; if ( ( hMasa = (MASA_DECODER_HANDLE) malloc( sizeof( MASA_DECODER ) ) ) == NULL ) { @@ -345,10 +349,17 @@ ivas_error ivas_masa_dec_open( /* Create spherical grid only for external output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) { - hMasa->data.sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ); + if ( ( hMasa->data.sph_grid16 = (SPHERICAL_GRID_DATA *) malloc( sizeof( SPHERICAL_GRID_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } + generate_gridEq( hMasa->data.sph_grid16 ); #ifdef FIX_350_MASA_DELAY_COMP - hMasa->data.extOutMeta = (MASA_DECODER_EXT_OUT_META *) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ); + if ( ( hMasa->data.extOutMeta = (MASA_DECODER_EXT_OUT_META *) malloc( sizeof( MASA_DECODER_EXT_OUT_META ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } #endif } else @@ -361,7 +372,7 @@ ivas_error ivas_masa_dec_open( if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { - init_lfe_synth_data( st_ivas, hMasa ); + error = init_lfe_synth_data( st_ivas, hMasa ); } else { @@ -370,7 +381,7 @@ ivas_error ivas_masa_dec_open( st_ivas->hMasa = hMasa; - return IVAS_ERR_OK; + return error; } @@ -398,6 +409,7 @@ void ivas_masa_dec_close( hMasa->data.extOutMeta = NULL; } #endif + if ( hMasa->hMasaLfeSynth != NULL ) { if ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer != NULL ) @@ -811,7 +823,7 @@ static void restore_lowbitrate_masa( } -static void init_lfe_synth_data( +static ivas_error init_lfe_synth_data( Decoder_Struct *st_ivas, /* i : IVAS decoder struct */ MASA_DECODER_HANDLE hMasa /* i/o: MASA decoder structure */ ) @@ -822,7 +834,10 @@ static void init_lfe_synth_data( output_Fs = st_ivas->hDecoderConfig->output_Fs; output_config = st_ivas->hDecoderConfig->output_config; - hMasa->hMasaLfeSynth = (MCMASA_LFE_SYNTH_DATA_HANDLE) malloc( sizeof( MCMASA_LFE_SYNTH_DATA ) ); + if ( ( hMasa->hMasaLfeSynth = (MCMASA_LFE_SYNTH_DATA_HANDLE) malloc( sizeof( MCMASA_LFE_SYNTH_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } hMasa->hMasaLfeSynth->transportEneSmooth = 0.0f; hMasa->hMasaLfeSynth->protoLfeEneSmooth = 0.0f; @@ -846,7 +861,10 @@ static void init_lfe_synth_data( /* Ring buffer for the filterbank of the LFE synthesis. * The filterbank is using moving average lowpass filter with the crossover of 120 Hz. */ bufferSize = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES ); - hMasa->hMasaLfeSynth->lfeSynthRingBuffer = (float *) malloc( bufferSize * sizeof( float ) ); + if ( ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } set_zero( hMasa->hMasaLfeSynth->lfeSynthRingBuffer, bufferSize ); hMasa->hMasaLfeSynth->ringBufferLoPointer = 0; hMasa->hMasaLfeSynth->ringBufferHiPointer = bufferSize / 2; @@ -856,7 +874,10 @@ static void init_lfe_synth_data( /* Ring buffer for additional lowpass filter for the LFE signal. * Moving average lowpass filter with the crossover of 240 Hz. */ bufferSize /= 2; - hMasa->hMasaLfeSynth->lfeSynthRingBuffer2 = (float *) malloc( bufferSize * sizeof( float ) ); + if ( ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2 = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } set_zero( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2, bufferSize ); hMasa->hMasaLfeSynth->ringBufferLoPointer2 = 0; hMasa->hMasaLfeSynth->lowpassSum2 = 0.0f; @@ -864,13 +885,19 @@ static void init_lfe_synth_data( /* Delay buffer for matching the delay of the lowpass filter */ bufferSize /= 2; /* The delay of the moving average lowpass filter is bufferSize / 2 */ - hMasa->hMasaLfeSynth->delayBuffer_syncLp = (float *) malloc( bufferSize * sizeof( float ) ); + if ( ( hMasa->hMasaLfeSynth->delayBuffer_syncLp = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } set_zero( hMasa->hMasaLfeSynth->delayBuffer_syncLp, bufferSize ); hMasa->hMasaLfeSynth->delayBuffer_syncLp_size = bufferSize; /* Delay buffer for syncing with DirAC rendering */ bufferSize = NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) - hMasa->hMasaLfeSynth->ringBufferSize / 2 - hMasa->hMasaLfeSynth->ringBufferSize2 / 2; - hMasa->hMasaLfeSynth->delayBuffer_syncDirAC = (float *) malloc( bufferSize * sizeof( float ) ); + if ( ( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } set_zero( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, bufferSize ); hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size = bufferSize; @@ -889,7 +916,10 @@ static void init_lfe_synth_data( /* Delay buffer for syncing with DirAC rendering */ bufferSize = NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ); - hMasa->hMasaLfeSynth->delayBuffer_syncDirAC = (float *) malloc( bufferSize * sizeof( float ) ); + if ( ( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); + } set_zero( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC, bufferSize ); hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size = bufferSize; @@ -905,7 +935,7 @@ static void init_lfe_synth_data( hMasa->hMasaLfeSynth->delayBuffer_syncDirAC = NULL; } - return; + return IVAS_ERR_OK; } @@ -1378,7 +1408,10 @@ static void compute_foa_cov_matrix( } #ifdef FIX_350_MASA_DELAY_COMP -static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, const int16_t nchan_transport ) +static void create_masa_ext_out_meta( + MASA_DECODER *hMasa, + IVAS_QMETADATA_HANDLE hQMetaData, + const int16_t nchan_transport ) { const uint8_t ivasmasaFormatDescriptor[8] = { 0x49, 0x56, 0x41, 0x53, 0x4D, 0x41, 0x53, 0x41 }; /* "IVASMASA" */ int16_t i, sf, b_old, b_new, dir; diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 803ccdf86c51b382113afbcaf19e3921c0ce361e..6bfddc78e64bc00e0462095141447baea2dc1637 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -96,7 +96,7 @@ static void param_mc_compute_interpolator( const uint16_t bAttackPresent, const static void param_mc_set_num_synth_bands( const int32_t output_Fs, PARAM_MC_DEC_HANDLE hParamMC ); -static void param_mc_get_diff_proto_info( const float *proto_mtx, const uint16_t nchan_transport, const uint16_t nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info ); +static ivas_error param_mc_get_diff_proto_info( const float *proto_mtx, const uint16_t nchan_transport, const uint16_t nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info ); static void ivas_param_mc_mc2sba_cldfb( IVAS_OUTPUT_SETUP hTransSetup, float *hoa_encoder, const int16_t slot_idx, float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], const int16_t nBands, const float gain_lfe ); @@ -231,8 +231,14 @@ ivas_error ivas_param_mc_dec_open( ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); /* init arrays for quantized parameters */ - hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ); - hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ); + if ( ( hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + if ( ( hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); @@ -280,11 +286,16 @@ ivas_error ivas_param_mc_dec_open( /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { - hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); + if ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + for ( k = 0; k < nchan_out_transport; k++ ) { mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); } + /* convert ParamMC parameter bands to SFB */ if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { @@ -302,7 +313,10 @@ ivas_error ivas_param_mc_dec_open( } } - hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ); + if ( ( hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } mvr2r( ivas_param_mc_conf[config_index].dmx_fac, hParamMC->proto_matrix_int, nchan_transport * nchan_out_transport ); if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) @@ -347,9 +361,15 @@ ivas_error ivas_param_mc_dec_open( else { hParamMC->num_outputs_diff = nchan_out_cov; - hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ); + if ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } - param_mc_get_diff_proto_info( proto_matrix, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ); + if ( ( error = param_mc_get_diff_proto_info( proto_matrix, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ) ) != IVAS_ERR_OK ) + { + return error; + } /* decorrelation */ hParamMC->h_freq_domain_decorr_ap_params = NULL; @@ -357,15 +377,18 @@ ivas_error ivas_param_mc_dec_open( ivas_dirac_dec_get_frequency_axis( frequency_axis, output_Fs, hParamMC->num_freq_bands ); - ivas_dirac_dec_decorr_open( &( hParamMC->h_freq_domain_decorr_ap_params ), - &( hParamMC->h_freq_domain_decorr_ap_state ), - hParamMC->num_freq_bands, - hParamMC->num_outputs_diff, - hParamMC->diff_proto_info->num_protos_diff, - DIRAC_SYNTHESIS_COV_MC_LS, - frequency_axis, - nchan_transport, - output_Fs ); + if ( ( error = ivas_dirac_dec_decorr_open( &( hParamMC->h_freq_domain_decorr_ap_params ), + &( hParamMC->h_freq_domain_decorr_ap_state ), + hParamMC->num_freq_bands, + hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, + DIRAC_SYNTHESIS_COV_MC_LS, + frequency_axis, + nchan_transport, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } hParamMC->h_output_synthesis_params.use_onset_filters = 0; hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; @@ -384,21 +407,27 @@ ivas_error ivas_param_mc_dec_open( } /* output synthesis */ - ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), - &( hParamMC->h_output_synthesis_cov_state ), - hParamMC->max_band_decorr, - PARAM_MC_MAX_NSLOTS, - hParamMC->hMetadataPMC->num_parameter_bands, - max_param_band_residual, - nchan_transport, - nchan_out_cov, - proto_matrix ); + if ( ( error = ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), + &( hParamMC->h_output_synthesis_cov_state ), + hParamMC->max_band_decorr, + PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, + max_param_band_residual, + nchan_transport, + nchan_out_cov, + proto_matrix ) ) != IVAS_ERR_OK ) + { + return error; + } /* Head rotation */ if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation ) { - hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ); + if ( ( hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hParamMC->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); } @@ -408,8 +437,15 @@ ivas_error ivas_param_mc_dec_open( if ( hParamMC->max_band_decorr > 0 ) { - hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ); - hParamMC->proto_frame_dec_f = (float *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( float ) ); + if ( ( hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + + if ( ( hParamMC->proto_frame_dec_f = (float *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } } else { @@ -616,8 +652,14 @@ ivas_error ivas_param_mc_dec_reconfig( /* init arrays for the quantized parameters */ - hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ); - hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ); + if ( ( hParamMC->icc_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + if ( ( hParamMC->icld_q = (float *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); @@ -696,7 +738,10 @@ ivas_error ivas_param_mc_dec_reconfig( /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ free( hParamMC->ls_conv_dmx_matrix ); - hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); + if ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } for ( k = 0; k < nchan_out_transport; k++ ) { mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); @@ -718,7 +763,10 @@ ivas_error ivas_param_mc_dec_reconfig( if ( nchan_transport_old != nchan_transport ) { free( hParamMC->proto_matrix_int ); - hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ); + if ( ( hParamMC->proto_matrix_int = (float *) malloc( nchan_out_transport * nchan_transport * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } mvr2r( ivas_param_mc_conf[config_index].dmx_fac, hParamMC->proto_matrix_int, nchan_transport * nchan_out_transport ); } @@ -789,9 +837,15 @@ ivas_error ivas_param_mc_dec_reconfig( } hParamMC->num_outputs_diff = nchan_out_cov; - hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ); + if ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } - param_mc_get_diff_proto_info( proto_matrix, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ); + if ( ( param_mc_get_diff_proto_info( proto_matrix, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ) ) != IVAS_ERR_OK ) + { + return error; + } /* decorrelation */ hParamMC->h_freq_domain_decorr_ap_params = NULL; @@ -799,15 +853,18 @@ ivas_error ivas_param_mc_dec_reconfig( ivas_dirac_dec_get_frequency_axis( frequency_axis, output_Fs, hParamMC->num_freq_bands ); - ivas_dirac_dec_decorr_open( &( hParamMC->h_freq_domain_decorr_ap_params ), - &( hParamMC->h_freq_domain_decorr_ap_state ), - hParamMC->num_freq_bands, - hParamMC->num_outputs_diff, - hParamMC->diff_proto_info->num_protos_diff, - DIRAC_SYNTHESIS_COV_MC_LS, - frequency_axis, - nchan_transport, - output_Fs ); + if ( ( error = ivas_dirac_dec_decorr_open( &( hParamMC->h_freq_domain_decorr_ap_params ), + &( hParamMC->h_freq_domain_decorr_ap_state ), + hParamMC->num_freq_bands, + hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, + DIRAC_SYNTHESIS_COV_MC_LS, + frequency_axis, + nchan_transport, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } hParamMC->h_output_synthesis_params.use_onset_filters = 0; hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; @@ -842,16 +899,20 @@ ivas_error ivas_param_mc_dec_reconfig( float tmp_buf[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; set_zero( tmp_buf, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + /* output synthesis */ - ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), - &( hParamMC->h_output_synthesis_cov_state ), - hParamMC->max_band_decorr, - PARAM_MC_MAX_NSLOTS, - hParamMC->hMetadataPMC->num_parameter_bands, - max_param_band_residual, - nchan_transport, - nchan_out_cov, - proto_matrix ); + if ( ( error = ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), + &( hParamMC->h_output_synthesis_cov_state ), + hParamMC->max_band_decorr, + PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, + max_param_band_residual, + nchan_transport, + nchan_out_cov, + proto_matrix ) ) != IVAS_ERR_OK ) + { + return error; + } ivas_dirac_dec_output_synthesis_cov_init( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); @@ -898,7 +959,10 @@ ivas_error ivas_param_mc_dec_reconfig( if ( hParamMC->max_band_decorr > 0 && nchan_transport_old != nchan_transport ) { free( hParamMC->proto_frame_f ); - hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ); + if ( ( hParamMC->proto_frame_f = (float *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); } @@ -2575,7 +2639,7 @@ static void param_mc_set_num_synth_bands( * calculated the diffuse prototype information *-------------------------------------------------------------------------*/ -static void param_mc_get_diff_proto_info( +static ivas_error param_mc_get_diff_proto_info( const float *proto_mtx, /* i : protoype matrix for the synthesis */ const uint16_t nchan_transport, /* i : number of transport channels */ const uint16_t nchan_out_cov, /* i : number if output channels of the covariance synthesis */ @@ -2591,9 +2655,16 @@ static void param_mc_get_diff_proto_info( /* Initializations */ max_num_src_chan = 0; set_zero( proto_fac, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); - p_diff_proto_info->proto_index_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ); + if ( ( p_diff_proto_info->proto_index_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } set_s( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov ); - p_diff_proto_info->num_source_chan_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ); + + if ( ( p_diff_proto_info->num_source_chan_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } set_s( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov ); /* we have at least one prototype, copy the first one */ @@ -2653,15 +2724,27 @@ static void param_mc_get_diff_proto_info( } /* set up the prototype info struct */ - p_diff_proto_info->source_chan_idx = (int16_t **) malloc( p_diff_proto_info->num_protos_diff * sizeof( int16_t * ) ); - p_diff_proto_info->proto_fac = (float **) malloc( p_diff_proto_info->num_protos_diff * sizeof( float * ) ); + if ( ( p_diff_proto_info->source_chan_idx = (int16_t **) malloc( p_diff_proto_info->num_protos_diff * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + if ( ( p_diff_proto_info->proto_fac = (float **) malloc( p_diff_proto_info->num_protos_diff * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } for ( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) { float *proto_fac_ptr; - p_diff_proto_info->source_chan_idx[cur_diff_proto] = (int16_t *) malloc( max_num_src_chan * sizeof( int16_t ) ); - p_diff_proto_info->proto_fac[cur_diff_proto] = (float *) malloc( max_num_src_chan * sizeof( float ) ); + if ( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (int16_t *) malloc( max_num_src_chan * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } + if ( ( p_diff_proto_info->proto_fac[cur_diff_proto] = (float *) malloc( max_num_src_chan * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); + } proto_fac_ptr = proto_fac + cur_diff_proto; for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) @@ -2676,7 +2759,7 @@ static void param_mc_get_diff_proto_info( } } - return; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 1623aad0239fffe7014c0b57b6d87ad0935c9bf1..332455974c4bce1eefac40d4e61d6fa1ca7f3e9c 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -671,13 +671,14 @@ ivas_error ivas_mc_dec_config( *-------------------------------------------------------------------------*/ static ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; int32_t new_brate_SCE, new_brate_CPE, ivas_total_brate; RENDERER_TYPE renderer_type_old; + Decoder_State *st; ivas_error error; MC_MODE mc_mode, last_mc_mode; @@ -730,6 +731,7 @@ static ivas_error ivas_mc_dec_reconfig( { ivas_param_mc_dec_close( &st_ivas->hParamMC ); st_ivas->hParamMC = NULL; + /* remove ls conversion if it was allocated by ParamMC */ ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); } @@ -774,7 +776,10 @@ static ivas_error ivas_mc_dec_reconfig( } else { - ivas_param_mc_dec_reconfig( st_ivas ); + if ( ( error = ivas_param_mc_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } /* De-allocate McMasa-related handles */ @@ -873,7 +878,7 @@ static ivas_error ivas_mc_dec_reconfig( set correct mct_chan_mode and init missing static mem (IGF, HQ) and some config (TNS) do it here since it is _very_ MC specific */ if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { - Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + st = st_ivas->hCPE[1]->hCoreCoder[1]; if ( st_ivas->nchan_transport == 3 ) { @@ -923,7 +928,7 @@ static ivas_error ivas_mc_dec_reconfig( #ifdef DEBUGGING assert( st_ivas->hCPE[1] != NULL ); #endif - Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + st = st_ivas->hCPE[1]->hCoreCoder[1]; st->mct_chan_mode = MCT_CHAN_MODE_LFE; st->hTcxCfg->fIsTNSAllowed = 0; } @@ -953,7 +958,7 @@ static ivas_error ivas_mc_dec_reconfig( if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { - Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + st = st_ivas->hCPE[1]->hCoreCoder[1]; /* TCX-LTP */ if ( st->hTcxLtpDec == NULL ) @@ -966,15 +971,24 @@ static ivas_error ivas_mc_dec_reconfig( } } - /* re-configure hp20 memories */ - ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); /*-----------------------------------------------------------------* - * CLDFB instances + * re-configure HP20 memories *-----------------------------------------------------------------*/ - ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } /*-----------------------------------------------------------------* * Allocate the LFE handle that is coded seperately after the allocation of the core coders diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 09db6fabfb23ba6ee45fc558cfa9ee1e10885aa6..8780b4ea98d6397edf69a7ec701bc73a07d6021b 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -65,26 +65,27 @@ ivas_error ivas_td_binaural_open( * and renders the current frame. *---------------------------------------------------------------------*/ -void ivas_td_binaural_renderer( +ivas_error ivas_td_binaural_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float output[][L_FRAME48k], /* i/o: SCE channels / Binaural synthesis */ const int16_t output_frame /* i : output frame length */ ) { + return ivas_td_binaural_renderer_unwrap( #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND - ivas_td_binaural_renderer_unwrap( st_ivas->hReverb, + st_ivas->hReverb, #else - ivas_td_binaural_renderer_unwrap( st_ivas->hRenderConfig, st_ivas->ini_frame, + st_ivas->hRenderConfig, st_ivas->ini_frame, #ifdef FIX_197_CREND_INTERFACE - st_ivas->hCrendWrapper, + st_ivas->hCrendWrapper, #else - st_ivas->hCrend, + st_ivas->hCrend, #endif #endif - st_ivas->transport_config, + st_ivas->transport_config, #ifndef FIX_330_ENABLE_TD_RENDERER_REVERB_REND - st_ivas->hDecoderConfig->output_Fs, + st_ivas->hDecoderConfig->output_Fs, #endif - st_ivas->hBinRendererTd, st_ivas->nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, - st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, output, output_frame ); + st_ivas->hBinRendererTd, st_ivas->nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, + st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, output, output_frame ); } diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index 787ceaaf44ac7fe6059d334b85d545214aaf240c..225a1c85b5f9ecdcf444ceebda5552857c6bb4a6 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -332,8 +332,14 @@ ivas_error ivas_ls_setup_conversion_open( hLsSetUpConversion->sfbCnt = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); for ( chIdx = 0; chIdx < outChannels; chIdx++ ) { - hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ); - hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ); + if ( ( hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + } + if ( ( hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + } set_f( hLsSetUpConversion->targetEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); set_f( hLsSetUpConversion->dmxEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); } @@ -348,8 +354,15 @@ ivas_error ivas_ls_setup_conversion_open( inChannels = st_ivas->nchan_transport; /*Initialization of MDCT bands with TCX20 resolution */ ivas_lssetupconversion_mdct_init_bands( output_frame, TCX_20_CORE, &hLsSetUpConversion->sfbOffset[0], &hLsSetUpConversion->sfbCnt ); - hLsSetUpConversion->targetEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ); - hLsSetUpConversion->dmxEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ); + if ( ( hLsSetUpConversion->targetEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + } + if ( ( hLsSetUpConversion->dmxEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); + } + for ( chIdx = 1; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 18a54132c7db719557141da4d587078f04bfdb83..525e775eb9f5361b886a14d07b3bd96f023295bb 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -107,7 +107,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA handles + * Allocate, initialize, and configure SBA handles *-----------------------------------------------------------------*/ if ( st_ivas->sba_mode != SBA_MODE_SPAR ) @@ -327,6 +327,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_binRenderer_close( &st_ivas->hBinRenderer ); } + if ( st_ivas->renderer_type != old_renderer_type ) { if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) @@ -435,23 +436,31 @@ ivas_error ivas_sba_dec_reconfigure( } /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SCE/CPE/MCT handles + * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ - ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ - ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); - + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } return error; } diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index eb7c2df9dbfce7543509646a6930facb2f7420ce..651f6402c6e6de45ecd1cd6f8090d9660983222e 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -649,4 +649,6 @@ static void run_min_stats( /* restore VAD (see above) */ st->VAD = save_VAD[ch]; } + + return; } diff --git a/lib_dec/ivas_vbap.c b/lib_dec/ivas_vbap.c index 9c595ea1fee5f33f38a2ab91b42696e1329438c5..cda52c1aec8e7c74c9b05d1016cc429e99fb6151 100644 --- a/lib_dec/ivas_vbap.c +++ b/lib_dec/ivas_vbap.c @@ -127,13 +127,13 @@ static int16_t determine_virtual_surface_triplets( const int16_t num_speaker_nod static void determine_initial_search_indices( const int16_t num_triplets, const float triplet_azidegs[VBAP_MAX_NUM_TRIPLETS], int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); -static void determine_connections( const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, int16_t connections[][2], const int16_t max_num_connections, int16_t *group1_count, int16_t *group2_start, int16_t *group2_count ); +static ivas_error determine_connections( const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, int16_t connections[][2], const int16_t max_num_connections, int16_t *group1_count, int16_t *group2_start, int16_t *group2_count ); static void formulate_horizontal_connections( const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, int16_t connections[][2], int16_t *connection_write_index ); -static void get_half_sphere_connection_options( const VBAP_SPEAKER_NODE *speaker_node_data, const enum SpeakerNodeGroup group, const int16_t num_speaker_nodes, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg, ConnectionOption **connection_options_pr, int16_t *num_connection_options ); +static ivas_error get_half_sphere_connection_options( const VBAP_SPEAKER_NODE *speaker_node_data, const enum SpeakerNodeGroup group, const int16_t num_speaker_nodes, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg, ConnectionOption **connection_options_pr, int16_t *num_connection_options ); -static void formulate_half_sphere_connections( const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, const enum SpeakerNodeGroup group, int16_t connections[][2], int16_t *connection_write_index, const int16_t max_num_connections, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg ); +static ivas_error formulate_half_sphere_connections( const VBAP_SPEAKER_NODE *speaker_node_data, const int16_t num_speaker_nodes, const enum SpeakerNodeGroup group, int16_t connections[][2], int16_t *connection_write_index, const int16_t max_num_connections, const int16_t num_non_crossing_planes, const float *non_crossing_plane_elevation_deg ); static int16_t determine_non_crossing_planes( const int16_t num_speaker_nodes, const VBAP_SPEAKER_NODE *node_data, float *non_crossing_plane_elevation_deg ); @@ -173,6 +173,7 @@ ivas_error vbap_init_data( float speaker_node_ele_deg_internal[VBAP_MAX_NUM_SPEAKER_NODES]; VBAP_SPEAKER_NODE speaker_node_data[VBAP_MAX_NUM_SPEAKER_NODES]; VBAP_DATA *vbap; + ivas_error error; push_wmops( "vbap_init" ); @@ -184,6 +185,7 @@ ivas_error vbap_init_data( /* TODO: are these two paths correct behaviour or should and error be returned ? */ return IVAS_ERR_OK; } + if ( !speaker_node_azi_deg || !speaker_node_ele_deg ) { hVBAPdata = NULL; @@ -206,7 +208,6 @@ ivas_error vbap_init_data( vbap->num_speaker_nodes = num_speaker_nodes; vbap->num_speaker_nodes_internal = num_speaker_nodes; - /* Check if the speaker node setup needs a virtual top or bottom node (function also increments vbap->num_speaker_nodes_internal when necessary) */ virtual_bottom_type = check_need_of_virtual_speaker_node( vbap, speaker_node_azi_deg, speaker_node_ele_deg, SPEAKER_NODE_BOTTOM_HALF ); @@ -220,7 +221,10 @@ ivas_error vbap_init_data( if ( is_success && virtual_bottom_type != NO_VIRTUAL_SPEAKER_NODE ) { - vbap->bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); + if ( ( vbap->bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } set_zero( vbap->bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->bottom_virtual_speaker_node_division_gains != NULL; speaker_node_azi_deg_internal[vbap->bottom_virtual_speaker_node_index] = 0.0f; @@ -229,7 +233,10 @@ ivas_error vbap_init_data( if ( is_success && virtual_top_type != NO_VIRTUAL_SPEAKER_NODE ) { - vbap->top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); + if ( ( vbap->top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } set_zero( vbap->top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->top_virtual_speaker_node_division_gains != NULL; speaker_node_azi_deg_internal[vbap->top_virtual_speaker_node_index] = 0.0f; @@ -238,7 +245,10 @@ ivas_error vbap_init_data( if ( is_success && virtual_back_type != NO_VIRTUAL_SPEAKER_NODE ) { - vbap->back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); + if ( ( vbap->back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } set_zero( vbap->back_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->back_virtual_speaker_node_division_gains != NULL; speaker_node_azi_deg_internal[vbap->back_virtual_speaker_node_index] = 180.0f; @@ -250,7 +260,10 @@ ivas_error vbap_init_data( /* Allocate and determine node-node connections */ max_num_connections = ( vbap->num_speaker_nodes_internal - 2 ) * 3; /* Theoretical maximum */ - determine_connections( vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, &connection_group1_count, &connection_group2_start, &connection_group2_count ); + if ( ( error = determine_connections( vbap->num_speaker_nodes_internal, speaker_node_data, connections, max_num_connections, &connection_group1_count, &connection_group2_start, &connection_group2_count ) ) != IVAS_ERR_OK ) + { + return error; + } /* Allocate and determine virtual surface speaker node triplets */ if ( is_success ) @@ -286,12 +299,20 @@ ivas_error vbap_init_data( break; } } - vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ); + + if ( ( vbap->search_struct[0].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group1_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } is_success &= vbap->search_struct[0].triplets != NULL; + if ( speaker_nodes_group2_internal > 0 ) { vbap->num_search_structs = 2; - vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ); + if ( ( vbap->search_struct[1].triplets = (VBAP_VS_TRIPLET *) malloc( ( ( speaker_nodes_group2_internal - 2 ) * 2 - ( max( 0, ( speaker_nodes_horiz_internal - 2 ) ) ) ) * sizeof( VBAP_VS_TRIPLET ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } is_success &= vbap->search_struct[1].triplets != NULL; } else @@ -1201,7 +1222,7 @@ static void determine_initial_search_indices( * Determine all valid connections between all speaker nodes *-------------------------------------------------------------------------*/ -static void determine_connections( +static ivas_error determine_connections( const int16_t num_speaker_nodes, /* i : number of speaker nodes */ const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ int16_t connections[][2], /* o : vector of connections */ @@ -1215,6 +1236,7 @@ static void determine_connections( int16_t c; int16_t connection_write_index = 0; float non_crossing_plane_elevation_deg[VBAP_MAX_PLANES]; + ivas_error error; set_f( non_crossing_plane_elevation_deg, 0.0f, VBAP_MAX_PLANES ); @@ -1230,20 +1252,31 @@ static void determine_connections( /* Process in different mode based on the grouping. It is enough to check for first node. */ if ( speaker_node_data[0].group == SPEAKER_NODE_ALL ) { - formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_ALL, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ); + if ( ( error = formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_ALL, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) != IVAS_ERR_OK ) + { + return error; + } } else { /* The node-node connections are determined in three stages: bottom, horizontal, and top. */ - formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_BOTTOM_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ); + if ( ( error = formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_BOTTOM_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) != IVAS_ERR_OK ) + { + return error; + } *group2_start = connection_write_index; + formulate_horizontal_connections( speaker_node_data, num_speaker_nodes, connections, &connection_write_index ); *group1_count = connection_write_index; - formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_TOP_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ); + + if ( ( error = formulate_half_sphere_connections( speaker_node_data, num_speaker_nodes, SPEAKER_NODE_TOP_HALF, connections, &connection_write_index, max_num_connections, num_non_crossing_planes, non_crossing_plane_elevation_deg ) ) != IVAS_ERR_OK ) + { + return error; + } *group2_count = connection_write_index - *group2_start; } - return; + return IVAS_ERR_OK; } @@ -1446,7 +1479,7 @@ static int16_t check_plane_crossing( * Get list of all potential connections at the half-sphere *-------------------------------------------------------------------------*/ -static void get_half_sphere_connection_options( +static ivas_error get_half_sphere_connection_options( const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ const enum SpeakerNodeGroup group, /* i : speaker node group */ const int16_t num_speaker_nodes, /* i : number of speaker nodes */ @@ -1472,7 +1505,11 @@ static void get_half_sphere_connection_options( } /* Init memory for connection options */ - c_options = (ConnectionOption *) malloc( sizeof( ConnectionOption ) * max_num_connection_options ); + if ( ( c_options = (ConnectionOption *) malloc( sizeof( ConnectionOption ) * max_num_connection_options ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } + for ( c = 0; c < max_num_connection_options; c++ ) { c_options[c].chA = -1; @@ -1527,7 +1564,11 @@ static void get_half_sphere_connection_options( /* Init memory for reordered connection options and order by arc_weighted, * which informs of the preference order of the connections in case they cross */ - c_options_reorder = (ConnectionOption *) malloc( sizeof( ConnectionOption ) * ( *num_connection_options ) ); + if ( ( c_options_reorder = (ConnectionOption *) malloc( sizeof( ConnectionOption ) * ( *num_connection_options ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VBAP data\n" ) ); + } + for ( c = 0; c < *num_connection_options; c++ ) { float min_arc_weighted; @@ -1554,16 +1595,17 @@ static void get_half_sphere_connection_options( *connection_options_pr = c_options_reorder; free( c_options ); - return; + return IVAS_ERR_OK; } + /*-------------------------------------------------------------------------* * formulate_half_sphere_connections() * * Formulate half-sphere connections *-------------------------------------------------------------------------*/ -static void formulate_half_sphere_connections( +static ivas_error formulate_half_sphere_connections( const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ const int16_t num_speaker_nodes, /* i : number of speaker nodes */ const enum SpeakerNodeGroup group, /* i : speaker node group */ @@ -1590,19 +1632,23 @@ static void formulate_half_sphere_connections( ConnectionOption *connection_options; int16_t num_connection_options; int16_t half_sphere_first_connection; + ivas_error error; half_sphere_first_connection = *connection_write_index; /* Obtain all connection options (i.e., channel pairs) at the half sphere. The function orders them * in terms of which connection to keep if two connections would cross each other. */ - get_half_sphere_connection_options( - speaker_node_data, - group, - num_speaker_nodes, - num_non_crossing_planes, - non_crossing_plane_elevation_deg, - &connection_options, - &num_connection_options ); + if ( ( error = get_half_sphere_connection_options( + speaker_node_data, + group, + num_speaker_nodes, + num_non_crossing_planes, + non_crossing_plane_elevation_deg, + &connection_options, + &num_connection_options ) ) != IVAS_ERR_OK ) + { + return error; + } set_f( connection_arc, 0.0f, max_num_connections ); for ( c = 0; c < max_num_connections; c++ ) @@ -1698,8 +1744,10 @@ static void formulate_half_sphere_connections( } c_opt++; } + free( connection_options ); - return; + + return IVAS_ERR_OK; } diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c index e272e21aa1cf0f265afea91511a2d324a8421d83..e68b3e170e2e71260d37eb05aeebec5e37984789 100644 --- a/lib_dec/jbm_jb4_circularbuffer.c +++ b/lib_dec/jbm_jb4_circularbuffer.c @@ -70,9 +70,14 @@ struct JB4_CIRCULARBUFFER /* Creates a circular buffer (FIFO) */ -int16_t JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ) +ivas_error JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ) { - JB4_CIRCULARBUFFER_HANDLE h = malloc( sizeof( struct JB4_CIRCULARBUFFER ) ); + JB4_CIRCULARBUFFER_HANDLE h; + + if ( ( h = malloc( sizeof( struct JB4_CIRCULARBUFFER ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } h->data = NULL; h->capacity = 0; @@ -81,7 +86,7 @@ int16_t JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ) *ph = h; - return 0; + return IVAS_ERR_OK; } @@ -119,13 +124,17 @@ int16_t JB4_CIRCULARBUFFER_Init( { /* keep one element free to be able to decide between full/empty buffer */ ++capacity; - h->data = malloc( capacity * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ); + + if ( ( h->data = malloc( capacity * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } h->capacity = capacity; h->writePos = 0; h->readPos = 0; - return 0; + return IVAS_ERR_OK; } diff --git a/lib_dec/jbm_jb4_circularbuffer.h b/lib_dec/jbm_jb4_circularbuffer.h index 0891cdfd116126e4d5a54ec2dce378806e2964f3..e14144b329e0984730809384e565db6c9b42b6ae 100644 --- a/lib_dec/jbm_jb4_circularbuffer.h +++ b/lib_dec/jbm_jb4_circularbuffer.h @@ -47,7 +47,7 @@ typedef struct JB4_CIRCULARBUFFER *JB4_CIRCULARBUFFER_HANDLE; typedef int32_t JB4_CIRCULARBUFFER_ELEMENT; -int16_t JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ); +ivas_error JB4_CIRCULARBUFFER_Create( JB4_CIRCULARBUFFER_HANDLE *ph ); void JB4_CIRCULARBUFFER_Destroy( JB4_CIRCULARBUFFER_HANDLE *ph ); diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index 8cec3bdf6120bcc58d027da44f89c4a1c8e84be2..925e35dfff2c23e7b28ad59f400d836f6cda0939 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -67,10 +67,15 @@ struct JB4_INPUTBUFFER /* Creates a input buffer */ -int16_t JB4_INPUTBUFFER_Create( +ivas_error JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ) { - JB4_INPUTBUFFER_HANDLE h = malloc( sizeof( struct JB4_INPUTBUFFER ) ); + JB4_INPUTBUFFER_HANDLE h; + + if ( ( h = malloc( sizeof( struct JB4_INPUTBUFFER ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } h->data = NULL; h->capacity = 0; @@ -80,7 +85,7 @@ int16_t JB4_INPUTBUFFER_Create( *ph = h; - return 0; + return IVAS_ERR_OK; } @@ -99,8 +104,12 @@ void JB4_INPUTBUFFER_Destroy( { return; } + if ( h->data ) + { free( h->data ); + } + free( h ); *ph = NULL; @@ -109,7 +118,7 @@ void JB4_INPUTBUFFER_Destroy( /* Initializes a input buffer with a fixed maximum allowed number of elements */ -int16_t JB4_INPUTBUFFER_Init( +ivas_error JB4_INPUTBUFFER_Init( JB4_INPUTBUFFER_HANDLE h, uint16_t capacity, int16_t ( *compareFunction )( const JB4_INPUTBUFFER_ELEMENT first, const JB4_INPUTBUFFER_ELEMENT second, bool *replaceWithNewElementIfEqual ) ) @@ -117,13 +126,17 @@ int16_t JB4_INPUTBUFFER_Init( /* keep one element free to be able to decide between full/empty buffer */ ++capacity; - h->data = malloc( capacity * sizeof( JB4_INPUTBUFFER_ELEMENT ) ); + if ( ( h->data = malloc( capacity * sizeof( JB4_INPUTBUFFER_ELEMENT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } + h->capacity = capacity; h->writePos = 0; h->readPos = 0; h->compareFunction = compareFunction; - return 0; + return IVAS_ERR_OK; } diff --git a/lib_dec/jbm_jb4_inputbuffer.h b/lib_dec/jbm_jb4_inputbuffer.h index 7af58a31d309f6dc09644bb3021861730386f17d..6087ecb20717b76c316e2349ca79a0e95131629e 100644 --- a/lib_dec/jbm_jb4_inputbuffer.h +++ b/lib_dec/jbm_jb4_inputbuffer.h @@ -48,14 +48,11 @@ typedef struct JB4_INPUTBUFFER *JB4_INPUTBUFFER_HANDLE; typedef void *JB4_INPUTBUFFER_ELEMENT; -int16_t JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ); +ivas_error JB4_INPUTBUFFER_Create( JB4_INPUTBUFFER_HANDLE *ph ); void JB4_INPUTBUFFER_Destroy( JB4_INPUTBUFFER_HANDLE *ph ); -int16_t JB4_INPUTBUFFER_Init( - JB4_INPUTBUFFER_HANDLE h, - uint16_t capacity, - int16_t ( *compareFunction )( const JB4_INPUTBUFFER_ELEMENT newElement, const JB4_INPUTBUFFER_ELEMENT arrayElement, bool *replaceWithNewElementIfEqual ) ); +ivas_error JB4_INPUTBUFFER_Init( JB4_INPUTBUFFER_HANDLE h, uint16_t capacity, int16_t ( *compareFunction )( const JB4_INPUTBUFFER_ELEMENT newElement, const JB4_INPUTBUFFER_ELEMENT arrayElement, bool *replaceWithNewElementIfEqual ) ); int16_t JB4_INPUTBUFFER_Enque( JB4_INPUTBUFFER_HANDLE h, JB4_INPUTBUFFER_ELEMENT element, JB4_INPUTBUFFER_ELEMENT *replacedElement ); diff --git a/lib_dec/jbm_jb4_jmf.c b/lib_dec/jbm_jb4_jmf.c index 8ec24046f03c8b3e9d3254f23d9e13014bc22a74..85e9980e6ef8b11a2306f70f228227185034cfd0 100644 --- a/lib_dec/jbm_jb4_jmf.c +++ b/lib_dec/jbm_jb4_jmf.c @@ -84,19 +84,35 @@ struct JB4_JMF /** helper function to add an entry at back of the buffer */ -static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, int32_t delay, int32_t offset, uint32_t time ); +static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, const int32_t delay, const int32_t offset, const uint32_t time ); + /** helper function to remove an entry from the front of the buffer */ static void JB4_JMF_popFront( JB4_JMF_HANDLE h ); -int16_t JB4_JMF_Create( +ivas_error JB4_JMF_Create( JB4_JMF_HANDLE *ph ) { - JB4_JMF_HANDLE h = malloc( sizeof( struct JB4_JMF ) ); + JB4_JMF_HANDLE h; + ivas_error error; + + if ( ( h = malloc( sizeof( struct JB4_JMF ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } - JB4_CIRCULARBUFFER_Create( &h->fifo ); - JB4_CIRCULARBUFFER_Create( &h->offsetFifo ); - JB4_CIRCULARBUFFER_Create( &h->timeStampFifo ); + if ( ( error = JB4_CIRCULARBUFFER_Create( &h->fifo ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( JB4_CIRCULARBUFFER_Create( &h->offsetFifo ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( JB4_CIRCULARBUFFER_Create( &h->timeStampFifo ) ) != IVAS_ERR_OK ) + { + return error; + } h->timeScale = 1000; h->consideredFraction = 1000; @@ -108,7 +124,7 @@ int16_t JB4_JMF_Create( *ph = h; - return 0; + return IVAS_ERR_OK; } @@ -141,10 +157,10 @@ void JB4_JMF_Destroy( /* function to set the window size of the fifo and the fraction which will be considered */ int16_t JB4_JMF_Init( JB4_JMF_HANDLE h, - int16_t timeScale, - uint16_t windowSize, - uint16_t windowDuration, - uint16_t consideredFraction ) + const int16_t timeScale, + const uint16_t windowSize, + const uint16_t windowDuration, + const uint16_t consideredFraction ) { /* check parameters */ @@ -175,8 +191,8 @@ int16_t JB4_JMF_Init( /* function to calculate delay for the current packet */ int16_t JB4_JMF_PushPacket( JB4_JMF_HANDLE h, - uint32_t sysTime, - uint32_t rtpTimeStamp ) + const uint32_t sysTime, + const uint32_t rtpTimeStamp ) { int32_t rtpTimeDiff, sysTimeDiff; int32_t offset, delay; @@ -267,9 +283,9 @@ int16_t JB4_JMF_MinOffset( /* helper function to add entry at back of the buffer */ static void JB4_JMF_pushBack( JB4_JMF_HANDLE h, - int32_t delay, - int32_t offset, - uint32_t time ) + const int32_t delay, + const int32_t offset, + const uint32_t time ) { int32_t minTime, maxTime; uint32_t duration; diff --git a/lib_dec/jbm_jb4_jmf.h b/lib_dec/jbm_jb4_jmf.h index 745d61ce92f3d2916ec7d6022a7c162efc5a0e8b..5efff7cd5ee36c4a91bf2f4cf0dc3b400161f590 100644 --- a/lib_dec/jbm_jb4_jmf.h +++ b/lib_dec/jbm_jb4_jmf.h @@ -45,13 +45,13 @@ /** handle for jitter measure fifo - a fifo used for windowed measure of network status */ typedef struct JB4_JMF *JB4_JMF_HANDLE; -int16_t JB4_JMF_Create( JB4_JMF_HANDLE *ph ); +ivas_error JB4_JMF_Create( JB4_JMF_HANDLE *ph ); void JB4_JMF_Destroy( JB4_JMF_HANDLE *ph ); -int16_t JB4_JMF_Init( JB4_JMF_HANDLE h, int16_t timeScale, uint16_t windowSize, uint16_t windowDuration, uint16_t consideredFraction ); +int16_t JB4_JMF_Init( JB4_JMF_HANDLE h, const int16_t timeScale, const uint16_t windowSize, const uint16_t windowDuration, const uint16_t consideredFraction ); -int16_t JB4_JMF_PushPacket( JB4_JMF_HANDLE h, uint32_t sysTime, uint32_t rtpTimeStamp ); +int16_t JB4_JMF_PushPacket( JB4_JMF_HANDLE h, const uint32_t sysTime, const uint32_t rtpTimeStamp ); int16_t JB4_JMF_Jitter( const JB4_JMF_HANDLE h, uint32_t *jitter ); diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 07d6acce9371459da0ef00ec09423bbfe72f4f5a..755187b640347bd9d61a94b0fdb75342e636c13b 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -61,7 +61,7 @@ #define MAXOFFSET 10 /*! Calculates the difference between two RTP timestamps - the diff is positive, if B 'later', negative otherwise */ -static int32_t JB4_rtpTimeStampDiff( uint32_t tsA, uint32_t tsB ); +static int32_t JB4_rtpTimeStampDiff( const uint32_t tsA, const uint32_t tsB ); /* function to calculate different options for the target playout delay */ static void JB4_targetPlayoutDelay( const JB4_HANDLE h, uint32_t *targetMin, uint32_t *targetMax, uint32_t *targetDtx, uint32_t *targetStartUp ); /*! function to do playout adaptation before playing the next data unit */ @@ -88,18 +88,18 @@ static int16_t JB4_inspectBufferForDropping( const JB4_HANDLE h, bool *dropEarly /* function to look into the buffer and check if it makes sense to drop a data unit during DTX */ static int16_t JB4_checkDtxDropping( const JB4_HANDLE h ); /*! function to estimate the short term jitter */ -static void JB4_estimateShortTermJitter( JB4_HANDLE h, uint32_t rcvTime, uint32_t rtpTimeStamp ); +static void JB4_estimateShortTermJitter( JB4_HANDLE h, const uint32_t rcvTime, const uint32_t rtpTimeStamp ); /*! function to pop a data unit from the buffer */ -static void JB4_popFromBuffer( JB4_HANDLE h, uint32_t sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ); +static void JB4_popFromBuffer( JB4_HANDLE h, const uint32_t sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ); /*! function to drop a data unit from the buffer - updates nShrinked */ static void JB4_dropFromBuffer( JB4_HANDLE h ); /*! function to calculate the playout delay based on the current jitter */ /*! @param[in] playTime the system time when the data unit will be played * @param[in] timeStamp the time stamp of the data unit to played * @param[out] delay the calculated playout delay */ -static int16_t JB4_playoutDelay( const JB4_HANDLE h, uint32_t playTime, uint32_t rtpTimeStamp, uint32_t *delay ); +static int16_t JB4_playoutDelay( const JB4_HANDLE h, const uint32_t playTime, const uint32_t rtpTimeStamp, uint32_t *delay ); /*! function to update lastPlayoutDelay and lastTargetTime after popFromBuffer() */ -static void JB4_updateLastTimingMembers( JB4_HANDLE h, uint32_t playTime, uint32_t rtpTimeStamp ); +static void JB4_updateLastTimingMembers( JB4_HANDLE h, const uint32_t playTime, const uint32_t rtpTimeStamp ); /*! function to compare the RTP time stamps of two data units: newElement==arrayElement ? 0 : (newElement>arrayElement ? +1 : -1) */ static int16_t JB4_inputBufferCompareFunction( const JB4_INPUTBUFFER_ELEMENT newElement, const JB4_INPUTBUFFER_ELEMENT arrayElement, bool *replaceWithNewElementIfEqual ); @@ -207,6 +207,7 @@ ivas_error JB4_Create( { int16_t iter; JB4_HANDLE h; + ivas_error error; if ( ( h = malloc( sizeof( struct JB4 ) ) ) == NULL ) { @@ -228,12 +229,23 @@ ivas_error JB4_Create( /* internal configuration values - do not change!!! */ h->timeScale = 0; h->frameDuration = 0; + /* jitter buffer configuration values: done in JB4_Init() */ /* short term jitter evaluation */ - JB4_JMF_Create( &h->stJmf ); - JB4_CIRCULARBUFFER_Create( &h->stJitterFifo ); - JB4_CIRCULARBUFFER_Create( &h->stTimeStampFifo ); + if ( ( error = JB4_JMF_Create( &h->stJmf ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( error = JB4_CIRCULARBUFFER_Create( &h->stJitterFifo ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( error = JB4_CIRCULARBUFFER_Create( &h->stTimeStampFifo ) ) != IVAS_ERR_OK ) + { + return error; + } h->stJitter = 0; + /* jitter buffer data */ h->firstDataUnitPopped = false; h->prevPopSysTime = 0; @@ -266,11 +278,18 @@ ivas_error JB4_Create( move32(); /* members to store the data units */ - JB4_INPUTBUFFER_Create( &h->inputBuffer ); + if ( ( error = JB4_INPUTBUFFER_Create( &h->inputBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + /* allocate memory for data units */ for ( iter = 0; iter < MAX_JBM_SLOTS; ++iter ) { - h->memorySlots[iter].data = malloc( MAX_AU_SIZE ); + if ( ( h->memorySlots[iter].data = malloc( MAX_AU_SIZE ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JB4 structure\n" ) ); + } h->freeMemorySlots[iter] = &h->memorySlots[iter]; } h->nFreeMemorySlots = MAX_JBM_SLOTS; @@ -314,12 +333,13 @@ void JB4_Destroy( } -int16_t JB4_Init( +ivas_error JB4_Init( JB4_HANDLE h, - int16_t safetyMargin ) + const int16_t safetyMargin ) { uint16_t ltJmfSize, stFifoSize, stJmfSize, stJmfAllowedLateLoss; uint16_t inputBufferCapacity; + ivas_error error; /* internal timescale is 1000, frame duration is 20ms */ h->timeScale = 1000; /* ms */ @@ -340,9 +360,13 @@ int16_t JB4_Init( JB4_JMF_Init( h->stJmf, h->timeScale, stJmfSize, h->timeScale /* 1s */, (uint16_t) ( 1000 - stJmfAllowedLateLoss ) ); inputBufferCapacity = MAX_JBM_SLOTS - 2; - JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ); - return 0; + if ( ( error = JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ) ) != IVAS_ERR_OK ) + { + return error; + } + + return IVAS_ERR_OK; } @@ -383,7 +407,7 @@ void JB4_FreeDataUnit( int16_t JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, - uint32_t rcvTime ) + const uint32_t rcvTime ) { JB4_DATAUNIT_HANDLE droppedDataUnit = NULL; @@ -551,8 +575,8 @@ int16_t JB4_FECoffset( int16_t JB4_PopDataUnit( JB4_HANDLE h, - uint32_t sysTime, - uint32_t extBufferedTime, + const uint32_t sysTime, + const uint32_t extBufferedTime, JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ) @@ -574,8 +598,8 @@ int16_t JB4_PopDataUnit( /* Calculates the difference between two RTP timestamps - the diff is positive, if B 'later', negative otherwise */ static int32_t JB4_rtpTimeStampDiff( - uint32_t tsA, - uint32_t tsB ) + const uint32_t tsA, + const uint32_t tsB ) { int32_t ret; /* do not dare to inline this function, casting to int32_t is important here! */ @@ -1058,8 +1082,8 @@ static int16_t JB4_checkDtxDropping( /* function to estimate the short term jitter */ static void JB4_estimateShortTermJitter( JB4_HANDLE h, - uint32_t rcvTime, - uint32_t rtpTimeStamp ) + const uint32_t rcvTime, + const uint32_t rtpTimeStamp ) { uint32_t jitter, duration, maxDuration; int32_t minTime, maxTime; @@ -1121,7 +1145,7 @@ static void JB4_estimateShortTermJitter( /* function to pop a data unit from the buffer */ static void JB4_popFromBuffer( JB4_HANDLE h, - uint32_t sysTime, + const uint32_t sysTime, JB4_DATAUNIT_HANDLE *pDataUnit ) { JB4_DATAUNIT_HANDLE nextDataUnit; @@ -1430,8 +1454,8 @@ static void JB4_dropFromBuffer( /* function to calculate the playout delay based on the current jitter */ static int16_t JB4_playoutDelay( const JB4_HANDLE h, - uint32_t playTime, - uint32_t rtpTimeStamp, + const uint32_t playTime, + const uint32_t rtpTimeStamp, uint32_t *delay ) { int32_t minOffTicks; @@ -1450,8 +1474,8 @@ static int16_t JB4_playoutDelay( /* function to update lastPlayoutDelay and lastTargetTime after popFromBuffer() */ static void JB4_updateLastTimingMembers( JB4_HANDLE h, - uint32_t playTime, - uint32_t rtpTimeStamp ) + const uint32_t playTime, + const uint32_t rtpTimeStamp ) { int32_t minOffTicks; diff --git a/lib_dec/jbm_jb4sb.h b/lib_dec/jbm_jb4sb.h index 6b31111670cc7c7a185d8284a710263e54131d98..54b873b006b1c9532794cae661a7f3c2aea031ad 100644 --- a/lib_dec/jbm_jb4sb.h +++ b/lib_dec/jbm_jb4sb.h @@ -85,15 +85,15 @@ ivas_error JB4_Create( JB4_HANDLE *ph ); void JB4_Destroy( JB4_HANDLE *ph ); -int16_t JB4_Init( JB4_HANDLE h, int16_t safetyMargin ); +ivas_error JB4_Init( JB4_HANDLE h, const int16_t safetyMargin ); JB4_DATAUNIT_HANDLE JB4_AllocDataUnit( JB4_HANDLE h ); void JB4_FreeDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit ); -int16_t JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, uint32_t rcvTime ); +int16_t JB4_PushDataUnit( JB4_HANDLE h, JB4_DATAUNIT_HANDLE dataUnit, const uint32_t rcvTime ); -int16_t JB4_PopDataUnit( JB4_HANDLE h, uint32_t sysTime, uint32_t extBufferedTime, JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ); +int16_t JB4_PopDataUnit( JB4_HANDLE h, const uint32_t sysTime, const uint32_t extBufferedTime, JB4_DATAUNIT_HANDLE *pDataUnit, uint32_t *scale, uint32_t *maxScaling ); int16_t JB4_getFECoffset( JB4_HANDLE h ); diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index c09a21e790ea624e198d1fb0d1a756e13f92b728..c816a9d9c8b4fadbea3da7e1ccb7061dbc4cd677 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -139,9 +139,9 @@ static bool extend_frm( apa_state_t *ps, const int16_t frm_in[], int16_t frm_out *---------------------------------------------------------------------*/ /* Allocates memory for state struct and initializes elements. */ -uint8_t apa_init( +ivas_error apa_init( apa_state_t **pps, - int32_t num_channels ) + const int32_t num_channels ) { apa_state_t *ps = NULL; @@ -152,22 +152,22 @@ uint8_t apa_init( } /* allocate state struct */ - ps = (apa_state_t *) malloc( sizeof( apa_state_t ) ); - if ( !ps ) + if ( ( ps = (apa_state_t *) malloc( sizeof( apa_state_t ) ) ) == NULL ) { - return 2; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } + ps->num_channels = (uint16_t) num_channels; ps->buf_out_capacity = (uint16_t) ( APA_BUF_PER_CHANNEL * num_channels ); - ps->buf_out = malloc( sizeof( float ) * ps->buf_out_capacity ); - if ( !ps->buf_out ) + if ( ( ps->buf_out = malloc( sizeof( float ) * ps->buf_out_capacity ) ) == NULL ) { - return 2; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); } + apa_reset( ps ); *pps = ps; - return 0; + return IVAS_ERR_OK; } diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index 2f0da13e9941abd012b4ac35db520d8e9d3c5eb4..543042f53b4301789af0eabe9fddee082254c8fa 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -91,8 +91,8 @@ typedef struct apa_state_t *PCMDSP_APA_HANDLE; /*! Allocates memory for state struct and initializes elements. * @return 0 on success, 1 on failure */ -uint8_t apa_init( apa_state_t **s, - int32_t num_channels ); +ivas_error apa_init( apa_state_t **s, + const int32_t num_channels ); /*! Sets state variables to initial value. */ void apa_reset( apa_state_t *s ); diff --git a/lib_dec/jbm_pcmdsp_fifo.c b/lib_dec/jbm_pcmdsp_fifo.c index 522da30dde0ef79caeb137be4003b1a831bb6711..81e833e5e56fc3860b7045c6b97405e52b71ae15 100644 --- a/lib_dec/jbm_pcmdsp_fifo.c +++ b/lib_dec/jbm_pcmdsp_fifo.c @@ -48,10 +48,15 @@ /* Creates a FIFO. */ -int16_t pcmdsp_fifo_create( +ivas_error pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ) { - PCMDSP_FIFO_HANDLE h = malloc( sizeof( struct PCMDSP_FIFO ) ); + PCMDSP_FIFO_HANDLE h; + + if ( ( h = malloc( sizeof( struct PCMDSP_FIFO ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } h->size = 0; h->capacity = 0; @@ -63,7 +68,7 @@ int16_t pcmdsp_fifo_create( *ph = h; - return 0; + return IVAS_ERR_OK; } @@ -95,7 +100,7 @@ void pcmdsp_fifo_destroy( } /* Initializes the FIFO with a fixed maximum allowed number audio samples. */ -int16_t pcmdsp_fifo_init( +ivas_error pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, uint16_t nSamplesPerChannel, uint16_t nChannels, @@ -106,12 +111,16 @@ int16_t pcmdsp_fifo_init( h->capacity = nSamplesPerChannel; h->nBytesPerSampleSet = nChannels * nBytesPerSample; nDataBytes = nSamplesPerChannel * h->nBytesPerSampleSet; - h->dataBegin = malloc( nDataBytes ); + if ( ( h->dataBegin = malloc( nDataBytes ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); + } + h->dataEnd = h->dataBegin + nDataBytes; h->dataWriteIterator = h->dataBegin; h->dataReadIterator = h->dataBegin; - return 0; + return IVAS_ERR_OK; } diff --git a/lib_dec/jbm_pcmdsp_fifo.h b/lib_dec/jbm_pcmdsp_fifo.h index faa482e69538ca0b7ccfb0406b5e36b85bbedc05..13ffd146f871fb1b4d7c227b965a1931ba2f1e11 100644 --- a/lib_dec/jbm_pcmdsp_fifo.h +++ b/lib_dec/jbm_pcmdsp_fifo.h @@ -66,11 +66,11 @@ struct PCMDSP_FIFO typedef struct PCMDSP_FIFO *PCMDSP_FIFO_HANDLE; -int16_t pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ); +ivas_error pcmdsp_fifo_create( PCMDSP_FIFO_HANDLE *ph ); void pcmdsp_fifo_destroy( PCMDSP_FIFO_HANDLE *ph ); -int16_t pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, uint16_t nSamplesPerChannel, uint16_t nChannels, uint16_t nBytesPerSample ); +ivas_error pcmdsp_fifo_init( PCMDSP_FIFO_HANDLE h, uint16_t nSamplesPerChannel, uint16_t nChannels, uint16_t nBytesPerSample ); int16_t pcmdsp_fifo_write( PCMDSP_FIFO_HANDLE h, const uint8_t *samples, uint16_t nSamplesPerChannel ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 237fc0c0caa74598c34f4e783372078f8638fcd6..95f7dca8a71b81d238c148f44b57ae0716a53e1d 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -547,9 +547,9 @@ ivas_error IVAS_DEC_EnableVoIP( { return error; } - if ( JB4_Init( hIvasDec->hVoIP->hJBM, jbmSafetyMargin ) != 0 ) + if ( ( error = JB4_Init( hIvasDec->hVoIP->hJBM, jbmSafetyMargin ) ) != IVAS_ERR_OK ) { - return IVAS_ERR_FAILED_ALLOC; + return error; } if ( hDecoderConfig->output_Fs == 8000 ) @@ -577,13 +577,12 @@ ivas_error IVAS_DEC_EnableVoIP( return IVAS_ERR_INIT_ERROR; } - if ( apa_init( &hIvasDec->hVoIP->hTimeScaler, - hDecoderConfig->nchan_out ) != 0 || + if ( apa_init( &hIvasDec->hVoIP->hTimeScaler, hDecoderConfig->nchan_out ) != IVAS_ERR_OK || apa_set_rate( hIvasDec->hVoIP->hTimeScaler, hDecoderConfig->output_Fs ) != 0 || apa_set_complexity_options( hIvasDec->hVoIP->hTimeScaler, wss, css ) != 0 || apa_set_quality( hIvasDec->hVoIP->hTimeScaler, 1, 4, 4 ) != 0 || - pcmdsp_fifo_create( &hIvasDec->hVoIP->hFifoAfterTimeScaler ) != 0 || - pcmdsp_fifo_init( hIvasDec->hVoIP->hFifoAfterTimeScaler, (uint16_t) ( hDecoderConfig->output_Fs * 4 / FRAMES_PER_SEC ) /* 4 frames */, hDecoderConfig->nchan_out, sizeof( int16_t ) ) != 0 ) + pcmdsp_fifo_create( &hIvasDec->hVoIP->hFifoAfterTimeScaler ) != IVAS_ERR_OK || + pcmdsp_fifo_init( hIvasDec->hVoIP->hFifoAfterTimeScaler, (uint16_t) ( hDecoderConfig->output_Fs * 4 / FRAMES_PER_SEC ) /* 4 frames */, hDecoderConfig->nchan_out, sizeof( int16_t ) ) != IVAS_ERR_OK ) { return IVAS_ERR_INIT_ERROR; } diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index a17369923cc51b78f06940f41c6f70f1073afe2d..5789f0dfd9abb6cc9e10c40fa3c5209bc0bf50d0 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -66,8 +66,7 @@ ivas_error createFdCngEnc( *hFdCngEnc = NULL; /* Allocate memory */ - hs = (HANDLE_FD_CNG_ENC) malloc( sizeof( FD_CNG_ENC ) ); - if ( hs == NULL ) + if ( ( hs = (HANDLE_FD_CNG_ENC) malloc( sizeof( FD_CNG_ENC ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG ENC structure" ); } diff --git a/lib_enc/hq_lr_enc.c b/lib_enc/hq_lr_enc.c index 9401a1bb573aebafa625d0b749975eca8f959385..e43baef59d23cc060f93c77123aca1117e194a97 100644 --- a/lib_enc/hq_lr_enc.c +++ b/lib_enc/hq_lr_enc.c @@ -320,7 +320,7 @@ void hq_lr_enc( if ( flag_spt == 1 ) { - /* initalize the desired parameters for SPT */ + /* initialize the desired parameters for SPT */ spt_shorten_domain_band_save( bands, band_start, band_end, band_width, org_band_start, org_band_end, org_band_width ); spt_shorten_domain_pre( band_start, band_end, hHQ_core->prev_SWB_peak_pos, bands, bwe_br, new_band_start, new_band_end, new_band_width ); spt_shorten_domain_set( hBstr, hHQ_core, t_audio, p2a_flags, new_band_start, new_band_end, new_band_width, bands, band_start, band_end, band_width, &bit_budget ); diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index e8486d77382b95866009ae265498450d0b562af9..f419425104264631193decc419d5a668e5dafd3f 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -30,15 +30,14 @@ *******************************************************************************************************/ -#include #include #include "options.h" #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" -#include "ivas_stat_enc.h" #ifdef DEBUGGING #include "debug.h" +#include #endif #include "wmc_auto.h" @@ -46,7 +45,7 @@ /*-------------------------------------------------------------------* * ivas_corecoder_enc_reconfig() * - * Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching + * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ ivas_error ivas_corecoder_enc_reconfig( @@ -97,6 +96,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -120,11 +120,13 @@ ivas_error ivas_corecoder_enc_reconfig( nchan_transport_old_real = nchan_transport_old; nchan_transport_real = st_ivas->nchan_transport; + /* in SCE+CPE McMASA nchan_transport is still 2, fix the numbers */ if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA ) { nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old; } + if ( hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) { nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE; @@ -282,6 +284,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index fceb67d58308a02dd3a2dc3d68242fe681e6eca9..a143ff37d27439adf9ec2ff991f8a0ec48bd4de3 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -122,14 +122,17 @@ ivas_error ivas_dirac_enc_open( } dirac_slot_ns = DIRAC_SLOT_ENC_NS; - /* initalize delay for SPAR/DirAC delay synchronization */ + /* initialize delay for SPAR/DirAC delay synchronization */ if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) { hDirAC->num_samples_synchro_delay = NS2SA( input_Fs, IVAS_FB_ENC_DELAY_NS ); for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) { - hDirAC->sba_synchro_buffer[i] = (float *) malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ); + if ( ( hDirAC->sba_synchro_buffer[i] = (float *) malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_zero( hDirAC->sba_synchro_buffer[i], hDirAC->num_samples_synchro_delay ); } } @@ -146,11 +149,17 @@ ivas_error ivas_dirac_enc_open( /* intensity 3-dim */ for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - hDirAC->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ); + if ( ( hDirAC->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - hDirAC->direction_vector_m[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ); + if ( ( hDirAC->direction_vector_m[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); } } @@ -158,14 +167,24 @@ ivas_error ivas_dirac_enc_open( hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - hDirAC->buffer_intensity_real[i] = (float **) malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ); + if ( ( hDirAC->buffer_intensity_real[i] = (float **) malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { - hDirAC->buffer_intensity_real[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ); + if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, DIRAC_MAX_NBANDS ); } } - hDirAC->buffer_energy = (float *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( float ) ); + + if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } set_f( hDirAC->buffer_energy, 0.0f, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); if ( st_ivas->hQMetaData->useLowerRes ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 5392fc8331886bac51378162281e1649c12f500b..0500a8e775da18d1c9e0b07ca3285b761ad4909a 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -237,8 +237,11 @@ ivas_error ivas_enc( ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); - ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, - ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 ); + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, + ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 ) ) != IVAS_ERR_OK ) + { + return error; + } } } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) @@ -330,7 +333,10 @@ ivas_error ivas_enc( ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); - ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 ); + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } if ( st_ivas->hMcMasa->separateChannelEnabled ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 60f3a230a589b97ce0e390957645d26e1eaba551..cce80138cb7202e2384b3304174f8f42d6281afc 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -409,7 +409,7 @@ ivas_error ivas_init_encoder( st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); - if ( ( error = create_ism_metadata_enc( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 9f9637d95e13f552f79d4fae0c4cc797d8e427bb..85b8e0c4aa8092cdaa951dfbde8472bddd650df0 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -415,8 +415,15 @@ ivas_error ivas_ism_enc_config( st_ivas->nSCE = st_ivas->nchan_transport; st_ivas->nCPE = 0; - ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); - ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ); + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 21717294729e0ac1c0fecbaa7613531d81f9eb21..2c7150b6c3107748a1db8dcf36c5a7a2a55c15fd 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -60,16 +60,16 @@ /*-------------------------------------------------------------------------* - * set_ism_metadata() + * ivas_set_ism_metadata() * - * Set metadata of for one ISM + * Set metadata of one ISM MD handle *-------------------------------------------------------------------------*/ -/*! r: 0 if success */ -ivas_error set_ism_metadata( - ISM_METADATA_HANDLE hIsmMeta, - float azimuth, - float elevation ) +ivas_error ivas_set_ism_metadata( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const float azimuth, /* i : azimuth value */ + const float elevation /* i : elevation value */ +) { if ( hIsmMeta == NULL ) { @@ -138,6 +138,7 @@ static void rate_ism_importance( return; } + /*-------------------------------------------------------------------------* * ivas_ism_metadata_enc() * @@ -694,7 +695,10 @@ ivas_error ivas_ism_metadata_enc( * Configuration and decision about bitrates per channel *----------------------------------------------------------------*/ - ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); + if ( ( error = ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ) ) != IVAS_ERR_OK ) + { + return error; + } for ( ch = 0; ch < num_obj; ch++ ) { @@ -728,18 +732,19 @@ ivas_error ivas_ism_metadata_enc( } /*------------------------------------------------------------------------- - * create_ism_metadata_enc() + * ivas_ism_metadata_enc_create() * - * Create, allocate, initialize and configure IVAS encoder ISM handles + * Create, allocate, initialize and configure IVAS encoder ISM metadata handles *-------------------------------------------------------------------------*/ -ivas_error create_ism_metadata_enc( +ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t n_ISms, /* i : number of objects */ int32_t element_brate_tmp[] /* o : element bitrate per object */ ) { int16_t ch, nchan_transport; + ivas_error error; if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { @@ -771,7 +776,10 @@ ivas_error create_ism_metadata_enc( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index c2b6b5423b154cccaed8df8aa3b9aa49b81a164b..dca9be401092af394f7a1b08ee95fd50100726cb 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -187,7 +187,7 @@ void ivas_masa_enc_close( * main MASA encoder function *-----------------------------------------------------------------------*/ -void ivas_masa_encode( +ivas_error ivas_masa_encode( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -226,7 +226,11 @@ void ivas_masa_encode( if ( Opt_DTX_ON ) { - h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ); + if ( ( h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); + } + for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) { for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) @@ -368,7 +372,7 @@ void ivas_masa_encode( hQMetaData->no_directions = numberOfDirectionsQMetaData; } - return; + return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 6ac686b01e4c149759ab2b2f82987da9d93d7ccb..153bc3ecade61d184618543f687084ae52961a7d 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -110,7 +110,7 @@ ivas_error ivas_mcmasa_enc_open( assert( st_ivas->hMasa != NULL && "MASA encoder handle is not present" ); hMasa = st_ivas->hMasa; - if ( NULL == ( hMcMasa = (MCMASA_ENC_HANDLE) malloc( sizeof( MCMASA_ENC_DATA ) ) ) ) + if ( ( hMcMasa = (MCMASA_ENC_HANDLE) malloc( sizeof( MCMASA_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } @@ -207,9 +207,16 @@ ivas_error ivas_mcmasa_enc_open( if ( hMcMasa->separateChannelEnabled ) { /* TD Energy calculation with LP */ - hMcMasa->delay_buffer_lfe[0] = (float *) malloc( NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_ENC_NS ) * sizeof( float ) ); + if ( ( hMcMasa->delay_buffer_lfe[0] = (float *) malloc( NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_ENC_NS ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } set_zero( hMcMasa->delay_buffer_lfe[0], NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_ENC_NS ) ); - hMcMasa->delay_buffer_lfe[1] = (float *) malloc( NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_ENC_NS ) * sizeof( float ) ); + + if ( ( hMcMasa->delay_buffer_lfe[1] = (float *) malloc( NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_ENC_NS ) * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } set_zero( hMcMasa->delay_buffer_lfe[1], NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_ENC_NS ) ); hMcMasa->hFbMixerLfe = NULL; } @@ -243,7 +250,10 @@ ivas_error ivas_mcmasa_enc_open( bufferSize = (int16_t) ( ( input_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES ); for ( i = 0; i < 2; i++ ) { - hMcMasa->lfeAnaRingBuffer[i] = (float *) malloc( bufferSize * sizeof( float ) ); + if ( ( hMcMasa->lfeAnaRingBuffer[i] = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } set_zero( hMcMasa->lfeAnaRingBuffer[i], bufferSize ); hMcMasa->lowpassSum[i] = 0.0f; } @@ -257,33 +267,56 @@ ivas_error ivas_mcmasa_enc_open( /* intensity 3-dim */ for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - hMcMasa->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ); + if ( ( hMcMasa->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - hMcMasa->direction_vector_m[i][j] = (float *) malloc( hMcMasa->nbands * sizeof( float ) ); + if ( ( hMcMasa->direction_vector_m[i][j] = (float *) malloc( hMcMasa->nbands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } } } hMcMasa->no_col_avg_diff = (int8_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - hMcMasa->buffer_intensity_real[i] = (float **) malloc( hMcMasa->no_col_avg_diff * sizeof( float * ) ); + if ( ( hMcMasa->buffer_intensity_real[i] = (float **) malloc( hMcMasa->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } + for ( j = 0; j < hMcMasa->no_col_avg_diff; j++ ) { - hMcMasa->buffer_intensity_real[i][j] = (float *) malloc( hMcMasa->nbands * sizeof( float ) ); + if ( ( hMcMasa->buffer_intensity_real[i][j] = (float *) malloc( hMcMasa->nbands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } set_zero( hMcMasa->buffer_intensity_real[i][j], hMcMasa->nbands ); } } - hMcMasa->buffer_intensity_real_vert = (float **) malloc( hMcMasa->no_col_avg_diff * sizeof( float * ) ); + if ( ( hMcMasa->buffer_intensity_real_vert = (float **) malloc( hMcMasa->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } + for ( j = 0; j < hMcMasa->no_col_avg_diff; j++ ) { - hMcMasa->buffer_intensity_real_vert[j] = (float *) malloc( hMcMasa->nbands * sizeof( float ) ); + if ( ( hMcMasa->buffer_intensity_real_vert[j] = (float *) malloc( hMcMasa->nbands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } set_zero( hMcMasa->buffer_intensity_real_vert[j], hMcMasa->nbands ); } - hMcMasa->buffer_energy = (float *) malloc( hMcMasa->nbands * hMcMasa->no_col_avg_diff * sizeof( float ) ); + if ( ( hMcMasa->buffer_energy = (float *) malloc( hMcMasa->nbands * hMcMasa->no_col_avg_diff * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); + } set_zero( hMcMasa->buffer_energy, hMcMasa->nbands * hMcMasa->no_col_avg_diff ); if ( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 1482cf3e2075628e6603f98abf2e6b6ab81540b4..707e74e32995ee9881271674e49351f991ce5928 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -649,7 +649,10 @@ static ivas_error ivas_mc_enc_reconfig( } else { - ivas_param_mc_enc_reconfig( st_ivas ); + if ( ( error = ivas_param_mc_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } /* De-allocate McMasa-related handles */ diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 85137454351d2307350b21c5a40797716820e31c..e878d7418372886865942dd0420090234c67367c 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -106,10 +106,7 @@ ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { -#ifdef SBA_BR_SWITCHING_CLEAN_UP - int16_t n; -#endif - int16_t nSCE_old, nCPE_old, nchan_transport_old; + int16_t n, nSCE_old, nCPE_old, nchan_transport_old; int32_t ivas_total_brate; ivas_error error; ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -295,8 +292,10 @@ ivas_error ivas_sba_enc_reconfigure( { return error; } + /*Initialization*/ hSpar->hMdEnc->table_idx = -1; + /* FB mixer handle */ ivas_FB_mixer_close( &hSpar->hFbMixer, hEncoderConfig->input_Fs ); @@ -370,11 +369,9 @@ ivas_error ivas_sba_enc_reconfigure( } } #ifndef SBA_BR_SWITCHING_CLEAN_UP - /* initalize delay for SPAR/DirAC delay synchronization */ + /* initialize delay for SPAR/DirAC delay synchronization */ if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) ) { - int16_t n; - if ( hDirAC->num_samples_synchro_delay == 0 ) { hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); @@ -395,7 +392,7 @@ ivas_error ivas_sba_enc_reconfigure( } else { - for ( int16_t n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) { if ( hDirAC->sba_synchro_buffer[n] != NULL ) { @@ -410,7 +407,10 @@ ivas_error ivas_sba_enc_reconfigure( #endif } - ivas_dirac_enc_reconfigure( st_ivas ); + if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { @@ -419,10 +419,13 @@ ivas_error ivas_sba_enc_reconfigure( } /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SCE/CPE/MCT handles + * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ); + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } } return error; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 0678cbf8e06156e20fd97a63d944cf025c93bf8b..7ed8d4f2ec2f2d967147be2326ecb124e5fd1e09 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -426,7 +426,7 @@ ivas_error IVAS_ENC_FeedObjectMetadata( return IVAS_ERR_INDEX_OUT_OF_BOUNDS; } - error = set_ism_metadata( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth, metadata.elevation ); + error = ivas_set_ism_metadata( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth, metadata.elevation ); if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 00a8d4a135a9529288207b55f20c1a9d240b8d77..caf9a562d5082559e49be3623c7acb116229dca8 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1400,10 +1400,12 @@ static ivas_error ivas_rend_initCrend( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Encountered unsupported input config in Crend" ); } + if ( outConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL && outConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Encountered unsupported output type in Crend" ); } + if ( hHrtf == NULL ) { if ( ivas_hrtf_open( &hHrtf ) != IVAS_ERR_OK ) @@ -1903,14 +1905,17 @@ ivas_error ivas_rend_initCrendWrapper( CREND_WRAPPER_HANDLE *pCrend ) { int16_t i; + if ( pCrend == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" ); } + if ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } + ( *pCrend )->binaural_latency_ns = 0; ( *pCrend )->hCrend = NULL; ( *pCrend )->hHrtfCrend = NULL; @@ -2173,6 +2178,7 @@ ivas_error ivas_rend_openCrend( #else pCrend->hCrend = hCrend; #endif + return IVAS_ERR_OK; } @@ -2355,9 +2361,17 @@ static ivas_error ivas_rend_crendConvolver( float *pFreq_filt_re, *pFreq_filt_im; float pOut[L_FRAME48k * 2]; float tmp_out_re[L_FRAME48k], tmp_out_im[L_FRAME48k]; + ivas_error error; + + if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) + { + return error; + } - getAudioConfigNumChannels( inConfig, &nchan_in ); - getAudioConfigNumChannels( outConfig, &nchan_out ); + if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + { + return error; + } subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; @@ -2528,7 +2542,11 @@ ivas_error ivas_rend_crendProcess( #endif inConfigType = getAudioConfigType( inRendConfig ); - getAudioConfigNumChannels( outRendConfig, &nchan_out ); + + if ( ( error = getAudioConfigNumChannels( outRendConfig, &nchan_out ) ) != IVAS_ERR_OK ) + { + return error; + } output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); #ifdef FIX_197_CREND_INTERFACE @@ -2554,7 +2572,12 @@ ivas_error ivas_rend_crendProcess( /* get current subframe quaternion and convert to euler angles */ Quat2Euler( hHeadTrackData->Quaternions[subframe_idx], &( pCrend->hCrend->m_fYaw ), &( pCrend->hCrend->m_fPitch ), &( pCrend->hCrend->m_fRoll ) ); ivas_orient_trk_SetAbsoluteOrientation( pCrend->hCrend->hTrack, pCrend->hCrend->m_fYaw, pCrend->hCrend->m_fPitch, pCrend->hCrend->m_fRoll ); - ivas_orient_trk_Process( pCrend->hCrend->hTrack ); + + if ( ( error = ivas_orient_trk_Process( pCrend->hCrend->hTrack ) ) != IVAS_ERR_OK ) + { + return error; + } + ivas_orient_trk_GetTrackedOrientation( pCrend->hCrend->hTrack, &( pCrend->hCrend->m_fYaw ), &( pCrend->hCrend->m_fPitch ), &( pCrend->hCrend->m_fRoll ) ); } diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 9ea9192e2ec20a1fdf708c40ef0a10eb2dbe9d9f..28c272bc0c820c180908817035d9446a12d6b819 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -114,7 +114,10 @@ IVAS_LIMITER_HANDLE ivas_limiter_open( return NULL; } - hLimiter = malloc( sizeof( IVAS_LIMITER ) ); + if ( ( hLimiter = malloc( sizeof( IVAS_LIMITER ) ) ) == NULL ) + { + return NULL; + } hLimiter->max_num_channels = max_num_channels; hLimiter->num_channels = max_num_channels; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 57390d3f914f19c1266e815fa99e4b58dc8ba70b..a8be0b5ba32adb4065b1d53ab5bc66c1458dde40 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -102,10 +102,16 @@ ivas_error ivas_td_binaural_open_unwrap( pBinRendTd->TdRend_MixSpatSpec_p->UseCommonDistAttenModel = TRUE; pBinRendTd->TdRend_MixSpatSpec_p->DistAttenModel = 0; /* 0=Turned off, else use TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED */ - TDREND_MIX_Init( pBinRendTd, hHrtfTD, pBinRendTd->TdRend_MixSpatSpec_p, output_Fs ); + if ( ( error = TDREND_MIX_Init( pBinRendTd, hHrtfTD, pBinRendTd->TdRend_MixSpatSpec_p, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } /* Set the attenuation (or can set MixSpatSpec.DistAttenModel above) */ - TDREND_MIX_SetDistAttenModel( pBinRendTd, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ); + if ( ( error = TDREND_MIX_SetDistAttenModel( pBinRendTd, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) ) != IVAS_ERR_OK ) + { + return error; + } /* Add sources to module and mixer, headphones */ PosType = TDREND_POSTYPE_ABSOLUTE; /* or TDREND_POSTYPE_RELATIVE_TO_LISTENER */ @@ -220,7 +226,7 @@ void ivas_td_binaural_close( * Call ivas_td_binaural_renderer() without st_ivas. *---------------------------------------------------------------------*/ -void ivas_td_binaural_renderer_unwrap( +ivas_error ivas_td_binaural_renderer_unwrap( #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND REVERB_HANDLE hReverb, /* i : reverb handle */ #else @@ -250,6 +256,7 @@ void ivas_td_binaural_renderer_unwrap( int16_t subframe_length; int16_t subframe_idx; float reverb_signal[BINAURAL_CHANNELS][L_FRAME48k]; + ivas_error error; subframe_length = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; #ifndef FIX_330_ENABLE_TD_RENDERER_REVERB_REND @@ -286,21 +293,20 @@ void ivas_td_binaural_renderer_unwrap( if ( ( hRenderConfig != NULL ) && ( hRenderConfig->roomAcoustics.late_reverb_on ) ) #endif { - ivas_reverb_process( + if ( ( error = ivas_reverb_process( #ifdef FIX_197_CREND_INTERFACE #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND - hReverb, + hReverb, #else - hCrendWrapper->hCrend->hReverb, + hCrendWrapper->hCrend->hReverb, #endif #else - hCrend->hReverb, + hCrend->hReverb, #endif - transport_config, - 0, - output, - reverb_signal, - subframe_idx ); + transport_config, 0, output, reverb_signal, subframe_idx ) ) != IVAS_ERR_OK ) + { + return error; + } #ifndef FIX_330_ENABLE_TD_RENDERER_REVERB_REND ivas_reverb_process( @@ -318,7 +324,10 @@ void ivas_td_binaural_renderer_unwrap( } /* Render subframe */ - TDREND_GetMix( hBinRendererTd, output, subframe_length, subframe_idx ); + if ( ( error = TDREND_GetMix( hBinRendererTd, output, subframe_length, subframe_idx ) ) != IVAS_ERR_OK ) + { + return error; + } } @@ -341,7 +350,7 @@ void ivas_td_binaural_renderer_unwrap( } #endif - return; + return IVAS_ERR_OK; } @@ -569,15 +578,20 @@ ivas_error ivas_td_binaural_open_ext( AUDIO_CONFIG transport_config; IVAS_FORMAT ivas_format; IVAS_OUTPUT_SETUP hTransSetup; + ivas_error error; if ( inConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { - getAudioConfigNumChannels( inConfig, &nchan_transport ); + if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } } else { nchan_transport = customLsInput->num_spk; } + #ifdef FIX_197_CREND_INTERFACE transport_config = getIvasAudioConfigFromRendAudioConfig( inConfig ); #else @@ -598,7 +612,6 @@ ivas_error ivas_td_binaural_open_ext( * and renders the current frame. *---------------------------------------------------------------------*/ -/*! r: TD Renderer result code. */ ivas_error ivas_td_binaural_renderer_ext( const TDREND_WRAPPER *pTDRend, /* i : TD Renderer wrapper structure */ const IVAS_REND_AudioConfig inConfig, /* i : Input audio configuration */ @@ -623,6 +636,7 @@ ivas_error ivas_td_binaural_renderer_ext( IVAS_FORMAT ivas_format; IVAS_REND_AudioConfigType inConfigType; AUDIO_CONFIG transport_config; + ivas_error error; #ifndef FIX_330_ENABLE_TD_RENDERER_REVERB_REND int32_t output_Fs; #endif @@ -641,7 +655,10 @@ ivas_error ivas_td_binaural_renderer_ext( #endif if ( inConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { - getAudioConfigNumChannels( inConfig, &num_src ); + if ( ( error = getAudioConfigNumChannels( inConfig, &num_src ) ) != IVAS_ERR_OK ) + { + return error; + } } else { @@ -661,7 +678,6 @@ ivas_error ivas_td_binaural_renderer_ext( hIsmMetaData[0]->elevation = currentPos->elevation; } - #ifndef FIX_330_ENABLE_TD_RENDERER_REVERB_REND #ifdef FIX_197_CREND_INTERFACE transport_config = getIvasAudioConfigFromRendAudioConfig( inConfig ); @@ -671,13 +687,18 @@ ivas_error ivas_td_binaural_renderer_ext( output_Fs = output_frame * 50; #endif #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND - ivas_td_binaural_renderer_unwrap( reverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, - ivas_format, hIsmMetaData, headRotData->headRotEnabled, ( headRotData != NULL ) ? headRotData->headPositions : NULL, - output, output_frame ); + if ( ( error = ivas_td_binaural_renderer_unwrap( reverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, headRotData->headRotEnabled, + ( headRotData != NULL ) ? headRotData->headPositions : NULL, output, output_frame ) ) != IVAS_ERR_OK ) + { + return error; + } #else - ivas_td_binaural_renderer_unwrap( NULL, 1, NULL, transport_config, output_Fs, pTDRend->hBinRendererTd, num_src, lfe_idx, - ivas_format, hIsmMetaData, headRotData->headRotEnabled, ( headRotData != NULL ) ? headRotData->headPositions : NULL, - output, output_frame ); + if ( ( error = error = ivas_td_binaural_renderer_unwrap( NULL, 1, NULL, transport_config, output_Fs, pTDRend->hBinRendererTd, num_src, lfe_idx, + ivas_format, hIsmMetaData, headRotData->headRotEnabled, ( headRotData != NULL ) ? headRotData->headPositions : NULL, + output, output_frame ) ) != IVAS_ERR_OK ) + { + return error; + } #endif pop_wmops(); diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 9da9c2750c32b9d2227d402ee6b147cf3024ee83..509d22d320f98ef6d1fcc17dc55b3ec8cc5ae14b 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -35,6 +35,7 @@ #include "prot.h" #include "ivas_prot_rend.h" #include "ivas_rom_TdBinauralRenderer.h" +#include "ivas_error.h" #include "wmc_auto.h" #ifdef DEBUGGING #include "debug.h" @@ -53,7 +54,7 @@ * Local functions *-------------------------------------------------------------------------*/ -static void DefaultBSplineModel( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, const int32_t output_Fs ); +static ivas_error DefaultBSplineModel( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, const int32_t output_Fs ); /*-------------------------------------------------------------------* @@ -193,6 +194,7 @@ ivas_error TDREND_MIX_Init( const int32_t output_Fs /* i : Output sampling rate */ ) { + ivas_error error; hBinRendererTd->Gain = 1.0f; @@ -225,7 +227,10 @@ ivas_error TDREND_MIX_Init( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - DefaultBSplineModel( hBinRendererTd->HrFiltSet_p, output_Fs ); + if ( ( error = DefaultBSplineModel( hBinRendererTd->HrFiltSet_p, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } *hHrtfTD = hBinRendererTd->HrFiltSet_p; } else @@ -340,15 +345,22 @@ ivas_error TDREND_MIX_AddSrc( * Allocate the B Spline HR Filter model. --------------------------------------------------------------------*/ -void BSplineModelEvalAlloc( +static ivas_error BSplineModelEvalAlloc( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i/o: Model evaluation structure */ ) { - modelEval->hrfModL = (float *) malloc( model->K * sizeof( float ) ); - modelEval->hrfModR = (float *) malloc( model->K * sizeof( float ) ); + if ( ( modelEval->hrfModL = (float *) malloc( model->K * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } - return; + if ( ( modelEval->hrfModR = (float *) malloc( model->K * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } + + return IVAS_ERR_OK; } @@ -358,7 +370,7 @@ void BSplineModelEvalAlloc( * Init default HRTF model --------------------------------------------------------------------*/ -static void DefaultBSplineModel( +static ivas_error DefaultBSplineModel( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* o : Loaded HR filter set */ const int32_t output_Fs /* i : Output sampling rate */ ) @@ -366,6 +378,7 @@ static void DefaultBSplineModel( ModelParams_t *model; ModelParamsITD_t *modelITD; int16_t i, j; + ivas_error error; HrFiltSet_p->FilterMethod = TDREND_HRFILT_Method_BSplineModel; model = &( HrFiltSet_p->ModelParams ); @@ -402,11 +415,24 @@ static void DefaultBSplineModel( model->elevKSeq = (const float *) orange53_rom_elevKSeq; model->elevBsShape = (const float *) orange53_rom_elevBsShape; - model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); + if ( ( model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } + model->azimBsShape[0] = (const float *) orange53_rom_azimBsShape; - model->azimKSeq = (float **) malloc( 18 * sizeof( float * ) ); - model->azimKSeq[0] = (float *) malloc( 2 * sizeof( float * ) ); - model->azimKSeq[17] = (float *) malloc( 2 * sizeof( float * ) ); + if ( ( model->azimKSeq = (float **) malloc( 18 * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } + if ( ( model->azimKSeq[0] = (float *) malloc( 2 * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } + if ( ( model->azimKSeq[17] = (float *) malloc( 2 * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } model->azimKSeq[0][0] = 0.0f; model->azimKSeq[17][0] = 0.0f; model->azimKSeq[0][1] = 360.0f; @@ -414,7 +440,10 @@ static void DefaultBSplineModel( for ( i = 1; i < 17; i++ ) { - model->azimKSeq[i] = (float *) malloc( model->azimDim2[i] * sizeof( float * ) ); /* azimDim2[i] = 91, i=2..15 */ + if ( ( model->azimKSeq[i] = (float *) malloc( model->azimDim2[i] * sizeof( float * ) ) ) == NULL ) /* azimDim2[i] = 91, i=2..15 */ + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } for ( j = 0; j < model->azimDim2[i]; j++ ) { model->azimKSeq[i][j] = (float) orange53_rom_azimSegSamples[0] * j; @@ -499,7 +528,10 @@ static void DefaultBSplineModel( HrFiltSet_p->SampleRate = output_Fs; HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; - BSplineModelEvalAlloc( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ); + if ( ( error = BSplineModelEvalAlloc( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ) != IVAS_ERR_OK ) + { + return error; + } - return; + return IVAS_ERR_OK; } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 694764979db139169078ac2e8b41278c43681ab6..d52422881292a65957e4c2d0c9d99a38f0d6ea7b 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -193,11 +193,11 @@ static ivas_error TDREND_SRC_REND_Alloc( *SrcRend_pp = NULL; /* Allocate the TDREND_SRC_REND_t variable */ - SrcRend_p = (TDREND_SRC_REND_t *) malloc( sizeof( TDREND_SRC_REND_t ) ); - if ( SrcRend_p == NULL ) + if ( ( SrcRend_p = (TDREND_SRC_REND_t *) malloc( sizeof( TDREND_SRC_REND_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "SrcRend_p allocation error\n" ) ); } + *SrcRend_pp = SrcRend_p; return IVAS_ERR_OK; @@ -389,8 +389,7 @@ static ivas_error TDREND_SRC_SPATIAL_Alloc( *SrcSpatial_pp = NULL; /* Allocate the TDREND_SRC_t variable */ - SrcSpatial_p = (TDREND_SRC_SPATIAL_t *) malloc( sizeof( TDREND_SRC_SPATIAL_t ) ); - if ( SrcSpatial_p == NULL ) + if ( ( SrcSpatial_p = (TDREND_SRC_SPATIAL_t *) malloc( sizeof( TDREND_SRC_SPATIAL_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "TDREND_SRC_SPATIAL_t allocation error\n" ) ); } @@ -601,8 +600,7 @@ ivas_error TDREND_SRC_Alloc( *Src_pp = NULL; /* Allocate the TDREND_SRC_t variable */ - Src_p = (TDREND_SRC_t *) malloc( sizeof( TDREND_SRC_t ) ); - if ( Src_p == NULL ) + if ( ( Src_p = (TDREND_SRC_t *) malloc( sizeof( TDREND_SRC_t ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, " TDREND_SRC_Alloc: Allocation error\n" ) ); } diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 4b72c16ce66f694a63e702e485f0c9f5f907caae..4eec8ecd562c8f4f8006972d629dc652d5d9bd41 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -133,6 +133,8 @@ void ivas_orient_trk_Init( pOTR->trkYaw = 0.0f; pOTR->trkPitch = 0.0f; pOTR->trkRoll = 0.0f; + + return; } @@ -142,12 +144,13 @@ void ivas_orient_trk_Init( * *-------------------------------------------------------------------*/ -ivas_error ivas_orient_trk_SetTrackingType( +void ivas_orient_trk_SetTrackingType( ivas_orient_trk_state_t *pOTR, - OTR_TRACKING_T trackingType ) + const OTR_TRACKING_T trackingType ) { pOTR->trackingType = trackingType; - return IVAS_ERR_OK; + + return; } @@ -157,18 +160,18 @@ ivas_error ivas_orient_trk_SetTrackingType( * *-------------------------------------------------------------------*/ -ivas_error ivas_orient_trk_SetAbsoluteOrientation( +void ivas_orient_trk_SetAbsoluteOrientation( ivas_orient_trk_state_t *pOTR, - float yaw, - float pitch, - float roll ) + const float yaw, + const float pitch, + const float roll ) { /* TODO implement condition checks */ pOTR->absYaw = yaw; pOTR->absPitch = pitch; pOTR->absRoll = roll; - return IVAS_ERR_OK; + return; } @@ -299,7 +302,7 @@ ivas_error ivas_orient_trk_Process( * *-------------------------------------------------------------------*/ -ivas_error ivas_orient_trk_GetTrackedOrientation( +void ivas_orient_trk_GetTrackedOrientation( ivas_orient_trk_state_t *pOTR, float *yaw, float *pitch, @@ -309,5 +312,5 @@ ivas_error ivas_orient_trk_GetTrackedOrientation( *pitch = pOTR->trkPitch; *roll = pOTR->trkRoll; - return IVAS_ERR_OK; + return; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index a2e14a35f19d1c56a073efdf9435e7e8d84f9e67..9e92e45d57fc01d4353b60f703f93c14abdc0a00 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -215,7 +215,7 @@ void ivas_HRTF_CRend_binary_close( * TD object renderer *----------------------------------------------------------------------------------*/ -void ivas_td_binaural_renderer_unwrap( +ivas_error ivas_td_binaural_renderer_unwrap( #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND REVERB_HANDLE hReverb, /* i : reverb handle */ #else @@ -300,11 +300,6 @@ void TDREND_Update_object_positions( float output[][L_FRAME48k] /* i/o: SCE/MC channels */ ); -void BSplineModelEvalAlloc( - ModelParams_t *model, /* i : Model parameters */ - ModelEval_t *modelEval /* i/o: Model evaluation structure */ -); - void BSplineModelEvalDealloc( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ @@ -883,23 +878,23 @@ void ivas_orient_trk_Init( ivas_orient_trk_state_t *pOTR ); -ivas_error ivas_orient_trk_SetTrackingType( +void ivas_orient_trk_SetTrackingType( ivas_orient_trk_state_t *pOTR, - OTR_TRACKING_T trackingType + const OTR_TRACKING_T trackingType ); -ivas_error ivas_orient_trk_SetAbsoluteOrientation( +void ivas_orient_trk_SetAbsoluteOrientation( ivas_orient_trk_state_t *pOTR, - float yaw, - float pitch, - float roll + const float yaw, + const float pitch, + const float roll ); ivas_error ivas_orient_trk_Process( ivas_orient_trk_state_t *pOTR ); -ivas_error ivas_orient_trk_GetTrackedOrientation( +void ivas_orient_trk_GetTrackedOrientation( ivas_orient_trk_state_t *pOTR, float *yaw, float *pitch, diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index 405ae8d72f343e7c614461aae8c83a36febe76ea..ccee4ffe724264ba1e4ef2150797b1bb634fe6b1 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -61,8 +61,7 @@ ivas_error ivas_render_config_open( ) { /* Allocate HR filter set for headphones configuration */ - *hRenderConfig = (RENDER_CONFIG_HANDLE) malloc( sizeof( RENDER_CONFIG_DATA ) ); - if ( *hRenderConfig == NULL ) + if ( ( *hRenderConfig = (RENDER_CONFIG_HANDLE) malloc( sizeof( RENDER_CONFIG_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer configuration!" ); } diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index e1349374b782fac5bb55895eb866c2041d9eb69e..d0e33a2d83849a6c66c6f2e41f75bece79ff3b04 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -571,10 +571,9 @@ static ivas_error initLimiter( ivas_limiter_close( phLimiter ); } - *phLimiter = ivas_limiter_open( (int16_t) numChannels, sampleRate ); - if ( *phLimiter == NULL ) + if ( ( *phLimiter = ivas_limiter_open( numChannels, sampleRate ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to open limiter" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Failed to open limiter handle" ); } return IVAS_ERR_OK; @@ -840,14 +839,17 @@ static ivas_error initEfap( { return error; } + if ( ( error = getSpeakerElevations( pEfapWrapper->speakerConfig, &elevations ) ) != IVAS_ERR_OK ) { return error; } + if ( ( error = getNumNonLfeChannelsInSpeakerLayout( pEfapWrapper->speakerConfig, &numNonLfeChannels ) ) != IVAS_ERR_OK ) { return error; } + if ( ( error = efap_init_data( &pEfapWrapper->hEfap, azimuths, elevations, numNonLfeChannels, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) { return error; @@ -1081,19 +1083,22 @@ static ivas_error setRendInputActiveIsm( error = IVAS_ERR_OK; if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL ) { - error = ivas_td_binaural_open_ext( &inputIsm->tdRendWrapper, inConfig, NULL, *rendCtx.pOutSampleRate ); + if ( ( error = ivas_td_binaural_open_ext( &inputIsm->tdRendWrapper, inConfig, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( outConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND if ( hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir == 0 && hRendCfg->roomAcoustics.late_reverb_on ) { - error = ivas_td_binaural_open_ext( &inputIsm->tdRendWrapper, inConfig, NULL, *rendCtx.pOutSampleRate ); - if ( ( error = ivas_reverb_open( &( inputIsm->reverb ), - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - hRendCfg, - *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_open_ext( &inputIsm->tdRendWrapper, inConfig, NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_reverb_open( &( inputIsm->reverb ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -1101,27 +1106,24 @@ static ivas_error setRendInputActiveIsm( else { #endif - error = ivas_rend_openCrend( &inputIsm->crendWrapper, - AUDIO_CONFIG_7_1_4, + if ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, AUDIO_CONFIG_7_1_4, #ifdef FIX_197_CREND_INTERFACE - getIvasAudioConfigFromRendAudioConfig( outConfig ), + getIvasAudioConfigFromRendAudioConfig( outConfig ), #else - rendAudioConfigToIvasAudioConfig( outConfig ), + rendAudioConfigToIvasAudioConfig( outConfig ), #endif - hRendCfg, + hRendCfg, #ifdef FIX_197_CREND_INTERFACE - 0, + 0, #endif - NULL, - *rendCtx.pOutSampleRate ); + NULL, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND } #endif } - if ( error != IVAS_ERR_OK ) - { - return error; - } return IVAS_ERR_OK; } @@ -1144,17 +1146,21 @@ static void clearInputIsm( { ivas_rend_closeCrend( &inputIsm->crendWrapper ); } + #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND if ( inputIsm->reverb != NULL ) { ivas_reverb_close( &inputIsm->reverb ); } #endif + if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { ivas_td_binaural_close( &inputIsm->tdRendWrapper.hBinRendererTd ); inputIsm->tdRendWrapper.hHrtfTD = NULL; } + + return; } static void copyLsConversionMatrixToPanMatrix( @@ -1270,10 +1276,12 @@ static ivas_error initMcPanGainsWithEfap( { return error; } + if ( ( error = getSpeakerAzimuths( inputMc->base.inConfig, &spkAzi ) ) != IVAS_ERR_OK ) { return error; } + if ( ( error = getSpeakerElevations( inputMc->base.inConfig, &spkEle ) ) != IVAS_ERR_OK ) { return error; @@ -1433,6 +1441,7 @@ static ivas_error initMcPanGainsWithStereoLookup( { return error; } + for ( readIdx = 0, writeIdx = 0; writeIdx < numInChannels; ++readIdx, ++writeIdx ) { if ( skipSideSpeakers && readIdx == 4 ) @@ -1465,14 +1474,17 @@ static bool configsAreEqual( { return false; } + if ( customLsA.num_lfe != customLsB.num_lfe ) { return false; } + if ( customLsA.is_planar_setup != customLsB.is_planar_setup ) { return false; } + for ( i = 0; i < customLsA.num_spk; ++i ) { /* Compare to nearest degree (hence the int cast) */ @@ -1659,10 +1671,12 @@ static ivas_error updateMcPanGainsForAmbiOut( { return error; } + if ( ( error = getSpeakerAzimuths( inputMc->base.inConfig, &spkAzi ) ) != IVAS_ERR_OK ) { return error; } + if ( ( error = getSpeakerElevations( inputMc->base.inConfig, &spkEle ) ) != IVAS_ERR_OK ) { return error; @@ -1781,6 +1795,7 @@ static ivas_error initMcBinauralRendering( ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); inputMc->tdRendWrapper.hHrtfTD = NULL; } + #ifdef FIX_197_CREND_INTERFACE if ( inputMc->crendWrapper != NULL ) #else @@ -1789,12 +1804,14 @@ static ivas_error initMcBinauralRendering( { ivas_rend_closeCrend( &inputMc->crendWrapper ); } + #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND if ( inputMc->reverb != NULL ) { ivas_reverb_close( &inputMc->reverb ); } #endif + if ( inputMc->efapInWrapper.hEfap != NULL ) { efap_free_data( &inputMc->efapInWrapper.hEfap ); @@ -1824,14 +1841,11 @@ static ivas_error initMcBinauralRendering( { return error; } + #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND if ( hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir == 0 && hRendCfg->roomAcoustics.late_reverb_on ) { - if ( ( error = ivas_reverb_open( &( inputMc->reverb ), - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - hRendCfg, - outSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &( inputMc->reverb ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -1842,8 +1856,7 @@ static ivas_error initMcBinauralRendering( { if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, #ifdef FIX_197_CREND_INTERFACE - ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? AUDIO_CONFIG_7_1_4 : getIvasAudioConfigFromRendAudioConfig( inConfig ), - getIvasAudioConfigFromRendAudioConfig( outConfig ), + ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? AUDIO_CONFIG_7_1_4 : getIvasAudioConfigFromRendAudioConfig( inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), #else ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? AUDIO_CONFIG_7_1_4 : rendAudioConfigToIvasAudioConfig( inConfig ), rendAudioConfigToIvasAudioConfig( outConfig ), @@ -1852,8 +1865,7 @@ static ivas_error initMcBinauralRendering( #ifdef FIX_197_CREND_INTERFACE 0, #endif - NULL, - outSampleRate ) ) != IVAS_ERR_OK ) + NULL, outSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -1862,10 +1874,13 @@ static ivas_error initMcBinauralRendering( /* Initialise the EFAP handle for rotation on input layout */ if ( inConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM && inputMc->base.ctx.pHeadRotData->headRotEnabled ) { - initEfap( &inputMc->efapInWrapper, inConfig, NULL ); + if ( ( error = initEfap( &inputMc->efapInWrapper, inConfig, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } } - return error; + return IVAS_ERR_OK; } static lfe_routing defaultLfeRouting( @@ -1986,6 +2001,7 @@ static void clearInputMc( { efap_free_data( &inputMc->efapInWrapper.hEfap ); } + #ifdef FIX_197_CREND_INTERFACE if ( inputMc->crendWrapper != NULL ) #else @@ -1994,12 +2010,14 @@ static void clearInputMc( { ivas_rend_closeCrend( &inputMc->crendWrapper ); } + #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND if ( inputMc->reverb != NULL ) { ivas_reverb_close( &inputMc->reverb ); } #endif + if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) { ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd ); @@ -2152,6 +2170,7 @@ static ivas_error updateSbaPanGains( { return error; } + error = ivas_rend_openCrend( &inputSba->crendWrapper, AUDIO_CONFIG_7_1_4, #ifdef FIX_197_CREND_INTERFACE @@ -2442,6 +2461,7 @@ static ivas_error initMasaDummyDecForBinauralOut( { return error; } + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &decDummy->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; @@ -2496,13 +2516,8 @@ static ivas_error updateMasaDummyDec( default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; } - /* Check error here to keep switch statement more compact */ - if ( error != IVAS_ERR_OK ) - { - return error; - } - return IVAS_ERR_OK; + return error; } static DecoderDummy *initDecoderDummy( @@ -2686,6 +2701,8 @@ static void freeDecoderDummy( free( pDecDummy ); pDecDummy = NULL; + + return; } static void clearInputMasa( @@ -2697,6 +2714,8 @@ static void clearInputMasa( initRendInputBase( &inputMasa->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx ); freeDecoderDummy( &inputMasa->decDummy ); + + return; } ivas_error IVAS_REND_Open( @@ -2717,10 +2736,12 @@ ivas_error IVAS_REND_Open( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + if ( ( error = validateOutputAudioConfig( outConfig ) ) != IVAS_ERR_OK ) { return error; } + if ( ( error = validateOutputSampleRate( outputSampleRate, outConfig ) ) != IVAS_ERR_OK ) { return error; @@ -2748,13 +2769,20 @@ ivas_error IVAS_REND_Open( { return error; } - initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ); + + if ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, outputSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } /* Initialize headrotation data */ initHeadRotation( hIvasRend ); /* Initialize EFAP */ - initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ); + if ( ( error = initEfap( &hIvasRend->efapOutWrapper, outConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) + { + return error; + } /* Initialize inputs */ for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) @@ -2770,6 +2798,7 @@ ivas_error IVAS_REND_Open( #endif hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL; } + for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); @@ -2784,6 +2813,7 @@ ivas_error IVAS_REND_Open( #endif hIvasRend->inputsMc[i].tdRendWrapper.hBinRendererTd = NULL; } + for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsSba[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); @@ -2793,6 +2823,7 @@ ivas_error IVAS_REND_Open( hIvasRend->inputsSba[i].crendWrapper.hCrend = NULL; #endif } + for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); @@ -2840,11 +2871,13 @@ static ivas_error validateCustomLsLayout( { return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; } + /* There must be at least one speaker or LFE in the layout */ if ( layout.num_spk + layout.num_lfe <= 0 ) { return IVAS_ERR_INVALID_CUSTOM_LS_LAYOUT; } + /* LFE indices must be positive */ for ( i = 0; i < layout.num_lfe; ++i ) { @@ -2874,11 +2907,13 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + if ( hIvasRend->outputConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { /* Specifying details of custom speaker layout only makes sense if output config is set to custom speaker layout */ return IVAS_ERR_INVALID_OUTPUT_FORMAT; } + if ( ( error = validateCustomLsLayout( layout ) ) != IVAS_ERR_OK ) { return error; @@ -2891,10 +2926,17 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( { return error; } - initLimiter( &hIvasRend->hLimiter, numOutChannels, hIvasRend->sampleRateOut ); + + if ( ( error = initLimiter( &hIvasRend->hLimiter, numOutChannels, hIvasRend->sampleRateOut ) ) != IVAS_ERR_OK ) + { + return error; + } /* Re-initialize EFAP - output layout has changed or has been fully defined for the first time */ - initEfap( &hIvasRend->efapOutWrapper, hIvasRend->outputConfig, &hIvasRend->customLsOut ); + if ( ( error = initEfap( &hIvasRend->efapOutWrapper, hIvasRend->outputConfig, &hIvasRend->customLsOut ) ) != IVAS_ERR_OK ) + { + return error; + } /* Re-initialize panning gains for each active MC input, This includes re-initializing * LFE handling for the new output layout, which means custom LFE handling is overwritten, @@ -2920,11 +2962,13 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { inputSba = &hIvasRend->inputsSba[i]; + if ( inputSba->base.inConfig == IVAS_REND_AUDIO_CONFIG_UNKNOWN ) { /* Input inactive, skip. */ continue; } + if ( ( error = updateSbaPanGains( inputSba, hIvasRend->outputConfig, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK ) { return error; @@ -2954,16 +2998,14 @@ ivas_error IVAS_REND_NumOutChannels( { case IVAS_REND_AUDIO_CONFIG_LS_CUSTOM: *numOutChannels = hIvasRend->customLsOut.num_spk + hIvasRend->customLsOut.num_lfe; - error = IVAS_ERR_OK; break; default: - error = getAudioConfigNumChannels( hIvasRend->outputConfig, numOutChannels ); + if ( ( error = getAudioConfigNumChannels( hIvasRend->outputConfig, numOutChannels ) ) != IVAS_ERR_OK ) + { + return error; + } break; } - if ( error != IVAS_ERR_OK ) - { - return error; - } return IVAS_ERR_OK; } @@ -3272,7 +3314,10 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, inputMc->customLsInput, hIvasRend->outputConfig, *inputMc->base.ctx.pCustomLsOut ); - initEfap( &inputMc->efapInWrapper, inputMc->base.inConfig, &inputMc->customLsInput ); + if ( ( error = initEfap( &inputMc->efapInWrapper, inputMc->base.inConfig, &inputMc->customLsInput ) ) != IVAS_ERR_OK ) + { + return error; + } if ( hIvasRend->outputConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL || hIvasRend->outputConfig == IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) { @@ -4031,6 +4076,8 @@ static void renderBufferChannelLerp( } } } + + return; } /* Take one channel from input buffer and copy it to each channel @@ -4068,19 +4115,26 @@ static ivas_error rotateFrameMc( rotation_matrix Rmat; rotation_gains gains; float tmp_gains[MAX_INPUT_CHANNELS]; + ivas_error error; push_wmops( "rotateFrameMc" ); if ( inConfig != IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) { - getAudioConfigNumChannels( inConfig, &nchan ); + if ( ( error = getAudioConfigNumChannels( inConfig, &nchan ) ) != IVAS_ERR_OK ) + { + return error; + } } else { nchan = inCustomLs.num_spk + inCustomLs.num_lfe; } - getMcConfigValues( inConfig, inCustomLs, &ls_azimuth, &ls_elevation, &lfe_idx, &is_planar_setup ); + if ( ( error = getMcConfigValues( inConfig, inCustomLs, &ls_azimuth, &ls_elevation, &lfe_idx, &is_planar_setup ) ) != IVAS_ERR_OK ) + { + return error; + } /* initialize gains to passthrough */ for ( ch_in = 0; ch_in < nchan; ch_in++ ) @@ -4176,10 +4230,14 @@ static ivas_error rotateFrameSba( rotation_matrix Rmat; float tmpRot[2 * HEADROT_ORDER + 1]; rotation_gains gains; + ivas_error error; push_wmops( "rotateFrameSba" ); - getAmbisonicsOrder( inConfig, &shd_rot_max_order ); + if ( ( error = getAmbisonicsOrder( inConfig, &shd_rot_max_order ) ) != IVAS_ERR_OK ) + { + return error; + } /* subframe loop */ subframe_len = inAudio.config.numSamplesPerChannel / RENDERER_HEAD_POSITIONS_PER_FRAME; @@ -4371,6 +4429,7 @@ static ivas_error renderIsmToBinauralRoom( rotatedPos.azimuth = (float) azi_rot; rotatedPos.elevation = (float) ele_rot; } + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, ( headRotData->headRotEnabled ) ? rotatedPos.azimuth : ismInput->previousPos.azimuth, ( headRotData->headRotEnabled ) ? rotatedPos.elevation : ismInput->previousPos.elevation, @@ -4386,6 +4445,7 @@ static ivas_error renderIsmToBinauralRoom( rotatedPos.azimuth = (float) azi_rot; rotatedPos.elevation = (float) ele_rot; } + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, ( headRotData->headRotEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, ( headRotData->headRotEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, @@ -4401,7 +4461,12 @@ static ivas_error renderIsmToBinauralRoom( /* intermediate rendering to 7_1_4 */ tmpMcBuffer = ismInput->base.inputBuffer; - getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ); + + if ( ( error = getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) + { + return error; + } + tmpMcBuffer.config.numChannels = tmp; tmpMcBuffer.data = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels ); @@ -4415,26 +4480,25 @@ static ivas_error renderIsmToBinauralRoom( #endif - ivas_rend_crendProcess( + if ( ( error = ivas_rend_crendProcess( #ifdef FIX_197_CREND_INTERFACE - ismInput->crendWrapper, + ismInput->crendWrapper, #else - &ismInput->crendWrapper, + &ismInput->crendWrapper, #endif - AUDIO_CONFIG_7_1_4, - AUDIO_CONFIG_BINAURAL_ROOM, + AUDIO_CONFIG_7_1_4, AUDIO_CONFIG_BINAURAL_ROOM, #ifdef FIX_197_CREND_INTERFACE - NULL, - NULL, - NULL, - NULL, + NULL, NULL, NULL, NULL, #endif #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND - tmpRendBuffer, + tmpRendBuffer, #else - tmpCrendBuffer, + tmpCrendBuffer, #endif - *ismInput->base.ctx.pOutSampleRate ); + *ismInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); @@ -4486,6 +4550,7 @@ static ivas_error renderIsmToMc( { return error; } + // TODO tmu review when #215 is resolved if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, (int16_t) floorf( ismInput->previousPos.azimuth + 0.5f ), @@ -4495,6 +4560,7 @@ static ivas_error renderIsmToMc( return error; } } + /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, outAudio ); @@ -4625,6 +4691,7 @@ static ivas_error renderActiveInputsIsm( /* Skip inactive inputs */ continue; } + if ( ( error = renderInputIsm( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; @@ -4691,7 +4758,6 @@ static ivas_error renderMcToBinaural( int8_t headRotEnabled; float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; IVAS_REND_AudioConfig inConfig; - ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; @@ -4728,13 +4794,16 @@ static ivas_error renderMcToBinaural( tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpRotBuffer.data, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); - rotateFrameMc( mcInput->base.inputBuffer, - mcInput->base.inConfig, - mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - mcInput->rot_gains_prev, - mcInput->efapInWrapper.hEfap, - tmpRotBuffer ); + if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, + mcInput->base.inConfig, + mcInput->customLsInput, + mcInput->base.ctx.pHeadRotData, + mcInput->rot_gains_prev, + mcInput->efapInWrapper.hEfap, + tmpRotBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } copyBufferTo2dArray( tmpRotBuffer, tmpRendBuffer ); free( tmpRotBuffer.data ); @@ -4745,23 +4814,16 @@ static ivas_error renderMcToBinaural( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( #ifdef FIX_197_CREND_INTERFACE - mcInput->crendWrapper, - getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - NULL, - NULL, - NULL, + mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, #else &mcInput->crendWrapper, rendAudioConfigToIvasAudioConfig( mcInput->base.inConfig ), rendAudioConfigToIvasAudioConfig( outConfig ), #endif - tmpRendBuffer, - *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -4770,7 +4832,10 @@ static ivas_error renderMcToBinaural( accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); /* TODO tmu : needs delay compensation */ - renderLfeToBinaural( mcInput, outAudio ); + if ( ( error = renderLfeToBinaural( mcInput, outAudio ) ) != IVAS_ERR_OK ) + { + return error; + } pop_wmops(); @@ -4789,7 +4854,6 @@ static ivas_error renderMcToBinauralRoom( #else float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; #endif - ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; @@ -4829,13 +4893,16 @@ static ivas_error renderMcToBinauralRoom( tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpRotBuffer.data, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); - rotateFrameMc( mcInput->base.inputBuffer, - mcInput->base.inConfig, - mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - mcInput->rot_gains_prev, - mcInput->efapInWrapper.hEfap, - tmpRotBuffer ); + if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, + mcInput->base.inConfig, + mcInput->customLsInput, + mcInput->base.ctx.pHeadRotData, + mcInput->rot_gains_prev, + mcInput->efapInWrapper.hEfap, + tmpRotBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef FIX_330_ENABLE_TD_RENDERER_REVERB_REND copyBufferTo2dArray( tmpRotBuffer, tmpRendBuffer ); @@ -4856,13 +4923,8 @@ static ivas_error renderMcToBinauralRoom( /* call CREND */ if ( ( error = ivas_rend_crendProcess( #ifdef FIX_197_CREND_INTERFACE - mcInput->crendWrapper, - getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - NULL, - NULL, - NULL, + mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, #else &mcInput->crendWrapper, rendAudioConfigToIvasAudioConfig( mcInput->base.inConfig ), @@ -4886,7 +4948,10 @@ static ivas_error renderMcToBinauralRoom( #endif /* TODO tmu : needs delay compensation */ - renderLfeToBinaural( mcInput, outAudio ); + if ( ( error = renderLfeToBinaural( mcInput, outAudio ) ) != IVAS_ERR_OK ) + { + return error; + } pop_wmops(); @@ -4920,18 +4985,20 @@ static ivas_error renderMcCustomLsToBinauralRoom( tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpRotBuffer.data, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); - rotateFrameMc( mcInput->base.inputBuffer, - mcInput->base.inConfig, - mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - mcInput->rot_gains_prev, - mcInput->efapInWrapper.hEfap, - tmpRotBuffer ); + if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, mcInput->base.inConfig, mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, mcInput->rot_gains_prev, mcInput->efapInWrapper.hEfap, tmpRotBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } } /* intermediate conversion to 7_1_4 */ tmpMcBuffer = mcInput->base.inputBuffer; - getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ); + + if ( ( error = getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) + { + return error; + } + tmpMcBuffer.config.numChannels = (int16_t) tmp; tmpMcBuffer.data = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels ); @@ -4946,20 +5013,13 @@ static ivas_error renderMcCustomLsToBinauralRoom( /* call CREND */ if ( ( error = ivas_rend_crendProcess( #ifdef FIX_197_CREND_INTERFACE - mcInput->crendWrapper, - AUDIO_CONFIG_7_1_4, - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - NULL, - NULL, - NULL, + mcInput->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, NULL, NULL, NULL, #else &mcInput->crendWrapper, AUDIO_CONFIG_7_1_4, rendAudioConfigToIvasAudioConfig( outConfig ), #endif - tmpCrendBuffer, - *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -4967,7 +5027,10 @@ static ivas_error renderMcCustomLsToBinauralRoom( accumulate2dArrayToBuffer( tmpCrendBuffer, &outAudio ); /* TODO tmu : needs delay compensation */ - renderLfeToBinaural( mcInput, outAudio ); + if ( ( error = renderLfeToBinaural( mcInput, outAudio ) ) != IVAS_ERR_OK ) + { + return error; + } if ( headRotEnabled ) { @@ -4980,7 +5043,7 @@ static ivas_error renderMcCustomLsToBinauralRoom( return IVAS_ERR_OK; } -static ivas_error renderMcToMc( +static void renderMcToMc( const input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { @@ -4998,10 +5061,10 @@ static ivas_error renderMcToMc( pop_wmops(); - return IVAS_ERR_OK; + return; } -static ivas_error renderMcToSba( +static void renderMcToSba( const input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { @@ -5019,7 +5082,7 @@ static ivas_error renderMcToSba( pop_wmops(); - return IVAS_ERR_OK; + return; } static ivas_error renderInputMc( @@ -5030,6 +5093,8 @@ static ivas_error renderInputMc( ivas_error error; IVAS_REND_AudioBuffer inAudio; + error = IVAS_ERR_OK; + inAudio = mcInput->base.inputBuffer; if ( mcInput->base.numNewSamplesPerChannel != outAudio.config.numSamplesPerChannel ) @@ -5048,10 +5113,10 @@ static ivas_error renderInputMc( switch ( getAudioConfigType( outConfig ) ) { case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - error = renderMcToMc( mcInput, outAudio ); + renderMcToMc( mcInput, outAudio ); break; case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - error = renderMcToSba( mcInput, outAudio ); + renderMcToSba( mcInput, outAudio ); break; case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: switch ( outConfig ) @@ -5077,13 +5142,7 @@ static ivas_error renderInputMc( return IVAS_ERR_INVALID_OUTPUT_FORMAT; } - /* Check error here to keep switch statement more compact */ - if ( error != IVAS_ERR_OK ) - { - return error; - } - - return IVAS_ERR_OK; + return error; } static ivas_error renderActiveInputsMc( @@ -5111,7 +5170,7 @@ static ivas_error renderActiveInputsMc( return IVAS_ERR_OK; } -static ivas_error renderSbaToMc( +static void renderSbaToMc( const input_sba *sbaInput, IVAS_REND_AudioBuffer outAudio ) { @@ -5129,10 +5188,10 @@ static ivas_error renderSbaToMc( pop_wmops(); - return IVAS_ERR_OK; + return; } -static ivas_error renderSbaToSba( +static void renderSbaToSba( const input_sba *sbaInput, IVAS_REND_AudioBuffer outAudio ) { @@ -5150,7 +5209,7 @@ static ivas_error renderSbaToSba( pop_wmops(); - return IVAS_ERR_OK; + return; } static ivas_error renderSbaToBinaural( @@ -5172,14 +5231,12 @@ static ivas_error renderSbaToBinaural( tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); /* copy input for in-place rotation */ - mvr2r( sbaInput->base.inputBuffer.data, tmpRotBuffer.data, - tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + mvr2r( sbaInput->base.inputBuffer.data, tmpRotBuffer.data, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); - rotateFrameSba( sbaInput->base.inputBuffer, - sbaInput->base.inConfig, - sbaInput->base.ctx.pHeadRotData, - sbaInput->rot_gains_prev, - tmpRotBuffer ); + if ( ( error = rotateFrameSba( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->rot_gains_prev, tmpRotBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } copyBufferTo2dArray( tmpRotBuffer, tmpCrendBuffer ); free( tmpRotBuffer.data ); @@ -5192,20 +5249,13 @@ static ivas_error renderSbaToBinaural( /* call CREND */ if ( ( error = ivas_rend_crendProcess( #ifdef FIX_197_CREND_INTERFACE - sbaInput->crendWrapper, - getIvasAudioConfigFromRendAudioConfig( sbaInput->base.inConfig ), - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - NULL, - NULL, - NULL, + sbaInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( sbaInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, NULL, NULL, NULL, #else &sbaInput->crendWrapper, rendAudioConfigToIvasAudioConfig( sbaInput->base.inConfig ), rendAudioConfigToIvasAudioConfig( outConfig ), #endif - tmpCrendBuffer, - *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5226,7 +5276,6 @@ static ivas_error renderSbaToBinauralRoom( int16_t i; int16_t tmp; float tmpCrendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - ivas_error error; IVAS_REND_AudioBuffer tmpRotBuffer; IVAS_REND_AudioBuffer tmpMcBuffer; @@ -5243,15 +5292,24 @@ static ivas_error renderSbaToBinauralRoom( { tmpRotBuffer = sbaInput->base.inputBuffer; tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); + /* copy input for in-place rotation */ mvr2r( sbaInput->base.inputBuffer.data, tmpRotBuffer.data, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); - rotateFrameSba( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->rot_gains_prev, tmpRotBuffer ); + if ( ( error = rotateFrameSba( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->rot_gains_prev, tmpRotBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } } /* intermediate rendering to 7_1_4 */ tmpMcBuffer = sbaInput->base.inputBuffer; - getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ); + + if ( ( error = getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) + { + return error; + } + tmpMcBuffer.config.numChannels = (int16_t) tmp; tmpMcBuffer.data = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); @@ -5267,20 +5325,14 @@ static ivas_error renderSbaToBinauralRoom( /* call CREND */ if ( ( error = ivas_rend_crendProcess( #ifdef FIX_197_CREND_INTERFACE - sbaInput->crendWrapper, - AUDIO_CONFIG_7_1_4, - getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, - NULL, - NULL, - NULL, + sbaInput->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, #else &sbaInput->crendWrapper, AUDIO_CONFIG_7_1_4, rendAudioConfigToIvasAudioConfig( outConfig ), #endif - tmpCrendBuffer, - *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5306,6 +5358,8 @@ static ivas_error renderInputSba( ivas_error error; IVAS_REND_AudioBuffer inAudio; + error = IVAS_ERR_OK; + inAudio = sbaInput->base.inputBuffer; if ( sbaInput->base.numNewSamplesPerChannel != outAudio.config.numSamplesPerChannel ) @@ -5324,10 +5378,10 @@ static ivas_error renderInputSba( switch ( getAudioConfigType( outConfig ) ) { case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - error = renderSbaToMc( sbaInput, outAudio ); + renderSbaToMc( sbaInput, outAudio ); break; case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - error = renderSbaToSba( sbaInput, outAudio ); + renderSbaToSba( sbaInput, outAudio ); break; case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: switch ( outConfig ) @@ -5346,13 +5400,7 @@ static ivas_error renderInputSba( return IVAS_ERR_INVALID_OUTPUT_FORMAT; } - /* Check error here to keep switch statement more compact */ - if ( error != IVAS_ERR_OK ) - { - return error; - } - - return IVAS_ERR_OK; + return error; } static ivas_error renderActiveInputsSba( @@ -5416,7 +5464,7 @@ static void copyMasaMetadataToDiracRenderer( return; } -static ivas_error renderMasaToMc( +static void renderMasaToMc( input_masa *masaInput, IVAS_REND_AudioBuffer outAudio ) { @@ -5437,10 +5485,10 @@ static ivas_error renderMasaToMc( accumulate2dArrayToBuffer( tmpBuffer, &outAudio ); - return IVAS_ERR_OK; + return; } -static ivas_error renderMasaToSba( +static void renderMasaToSba( input_masa *masaInput, IVAS_REND_AudioBuffer outAudio ) { @@ -5453,10 +5501,10 @@ static ivas_error renderMasaToSba( accumulate2dArrayToBuffer( tmpBuffer, &outAudio ); - return IVAS_ERR_OK; + return; } -static ivas_error renderMasaToBinaural( +static void renderMasaToBinaural( input_masa *masaInput, IVAS_REND_AudioBuffer outAudio ) { @@ -5469,7 +5517,7 @@ static ivas_error renderMasaToBinaural( accumulate2dArrayToBuffer( tmpBuffer, &outAudio ); - return IVAS_ERR_OK; + return; } static ivas_error renderInputMasa( @@ -5477,7 +5525,6 @@ static ivas_error renderInputMasa( const IVAS_REND_AudioConfig outConfig, IVAS_REND_AudioBuffer outAudio ) { - ivas_error error; IVAS_REND_AudioBuffer inAudio; if ( !masaInput->metadataHasBeenFed ) @@ -5503,20 +5550,20 @@ static ivas_error renderInputMasa( switch ( getAudioConfigType( outConfig ) ) { case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - error = renderMasaToMc( masaInput, outAudio ); + renderMasaToMc( masaInput, outAudio ); break; case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - error = renderMasaToSba( masaInput, outAudio ); + renderMasaToSba( masaInput, outAudio ); break; case IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL: switch ( outConfig ) { case IVAS_REND_AUDIO_CONFIG_BINAURAL: - error = renderMasaToBinaural( masaInput, outAudio ); + renderMasaToBinaural( masaInput, outAudio ); break; /* ToDo */ // case IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM: - // error = renderMasaToBinauralRoom( masaInput, outConfig, outAudio ); + // renderMasaToBinauralRoom( masaInput, outConfig, outAudio ); // break; default: return IVAS_ERR_INVALID_OUTPUT_FORMAT; @@ -5526,12 +5573,6 @@ static ivas_error renderInputMasa( return IVAS_ERR_INVALID_OUTPUT_FORMAT; } - /* Check error here to keep switch statement more compact */ - if ( error != IVAS_ERR_OK ) - { - return error; - } - return IVAS_ERR_OK; } diff --git a/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c b/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c index a0e2ddd94ce4f4c69f1fdc3fcb758aa2dd869965..a7d4391c7520be27e06d0127aecac706bc1d8b6d 100644 --- a/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c +++ b/scripts/binauralRenderer_interface/Table_Format_Converter/generate_tables_from_rom_to_bin.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 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 diff --git a/scripts/binauralRenderer_interface/Table_Format_Converter/table_format_converter_readme.txt b/scripts/binauralRenderer_interface/Table_Format_Converter/table_format_converter_readme.txt index 391ad644e942c007d498b7ac5fa1eb234d9c752b..dda6738a9ae8ea0be8f875ef85b36fa0489b916b 100644 --- a/scripts/binauralRenderer_interface/Table_Format_Converter/table_format_converter_readme.txt +++ b/scripts/binauralRenderer_interface/Table_Format_Converter/table_format_converter_readme.txt @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 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 diff --git a/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c b/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c index 0aae3c6cabb404550c52e0fd7df00bb946dfce69..3f847f83cf30ff3f786f47463d308efc833afdbe 100644 --- a/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c +++ b/scripts/binauralRenderer_interface/generate_crend_ivas_tables_from_sofa.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 Baseline Development Group with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 Baseline Development Group 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 Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation. All Rights Reserved. diff --git a/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c b/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c index 456997b5a1202344911e0313c17343458439f17f..7e9658bd8030b2d5a93a4defb7731263423217fe 100644 --- a/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c +++ b/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 Baseline Development Group with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 Baseline Development Group 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 Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation. All Rights Reserved. diff --git a/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.h b/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.h index 9b8fdbcde916440319990b039e1a141d21c79cee..28d3c1225023d0343c66d19bf5d5e7c6706619d8 100644 --- a/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.h +++ b/scripts/binauralRenderer_interface/ivas_crend_binaural_filter_design.h @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 Baseline Development Group with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 Baseline Development Group 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 Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation. All Rights Reserved. diff --git a/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt b/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt index ead4b2d4374b4c829aa00a14c948ca19fc775aaa..73314c5cd5188ed690ecc00d4d4b5fd30737db40 100644 --- a/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt +++ b/scripts/binauralRenderer_interface/mixer_conv_sofa_to_rom_table_converter_readme.txt @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 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 diff --git a/scripts/binauralRenderer_interface/resolve_build_dep.py b/scripts/binauralRenderer_interface/resolve_build_dep.py index 5a1a823033b5bbc9480bbc4d0da0c8e55b2f86a2..a251e7fe327b7b8366562ae31a627411d1b0be3c 100644 --- a/scripts/binauralRenderer_interface/resolve_build_dep.py +++ b/scripts/binauralRenderer_interface/resolve_build_dep.py @@ -1,5 +1,5 @@ """ - (C) 2022 Baseline Development Group with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 Baseline Development Group 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 Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation. All Rights Reserved.