diff --git a/apps/encoder.c b/apps/encoder.c index c0811679599b226af424a63b2a8fff12152ffc19..3e0a9a90079dbb5697527b25831869502619736e 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -190,13 +190,19 @@ int main( /*------------------------------------------------------------------------------------------* * Open and initialize IVAS encoder *------------------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED + if ((error = IVAS_ENC_Open_fx(&hIvasEnc)) != IVAS_ERR_OK) + { + fprintf(stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage(error)); + goto cleanup; + } +#else if ( ( error = IVAS_ENC_Open( &hIvasEnc ) ) != IVAS_ERR_OK ) { fprintf( stderr, "Opening IVAS encoder failed: %s\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } - +#endif /*------------------------------------------------------------------------------------------* * Open output bitstream file *------------------------------------------------------------------------------------------*/ @@ -364,13 +370,21 @@ int main( } break; case IVAS_ENC_INPUT_SBA: +#if 0 + if ((error = IVAS_ENC_ConfigureForAmbisonics_fx(hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba.order, arg.inputFormatConfig.sba.isPlanar, + arg.pca)) != IVAS_ERR_OK) + { + fprintf(stderr, "\nIVAS_ENC_ConfigureForAmbisonics failed: %s\n\n", IVAS_ENC_GetErrorMessage(error)); + goto cleanup; + } +#else if ( ( error = IVAS_ENC_ConfigureForAmbisonics( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba.order, arg.inputFormatConfig.sba.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForAmbisonics failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } - +#endif break; case IVAS_ENC_INPUT_MASA: if ( ( error = IVAS_ENC_ConfigureForMasa( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masaVariant ) ) != IVAS_ERR_OK ) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 973a114b1f980363ddd9e89907509ed64b0e64fd..0be46047b50c4581bed64f8c9ffba595de60dcee 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -1428,6 +1428,7 @@ static int16_t allocate_unused( *--------------------------------------------------------------------*/ /*! r: ACELP16k flag */ + #ifndef IVAS_FLOAT_FIXED int16_t set_ACELP_flag_IVAS( const int16_t element_mode, /* i : element mode */ @@ -1439,49 +1440,49 @@ int16_t set_ACELP_flag_IVAS( const int16_t cng_type /* i : CNG type */ ) { - if ( element_mode == IVAS_CPE_DFT && idchan == 0 && total_brate <= SID_2k40 && bwidth == WB && cng_type == LP_CNG ) + IF ( EQ_16(element_mode, IVAS_CPE_DFT) && EQ_16(idchan, 0) && LE_32(total_brate, SID_2k40) && EQ_16(bwidth, WB) && EQ_16(cng_type, LP_CNG )) { return 1; } - else if ( element_mode == IVAS_CPE_TD ) + ELSE IF (EQ_16(element_mode, IVAS_CPE_TD )) { - if ( element_brate >= IVAS_24k4 && idchan == 0 && ( tdm_LRTD_flag == 0 || element_brate > IVAS_24k4 ) ) + IF ( GE_32(element_brate, IVAS_24k4) && EQ_16(idchan, 0) && (EQ_16(tdm_LRTD_flag, 0 )|| GT_32(element_brate, IVAS_24k4 )) ) { return 1; } - else + ELSE { return 0; } } - else if ( element_mode == IVAS_CPE_DFT ) + ELSE IF (EQ_16(element_mode, IVAS_CPE_DFT )) { - if ( element_brate >= IVAS_24k4 ) + IF (GE_32(element_brate, IVAS_24k4) ) { return 1; } - else + ELSE { return 0; } } - else if ( element_mode == IVAS_SCE ) + ELSE IF (EQ_16(element_mode, IVAS_SCE )) { - if ( element_brate >= SCE_CORE_16k_LOW_LIMIT ) + IF (GE_32(element_brate, SCE_CORE_16k_LOW_LIMIT )) { return 1; } - else + ELSE { return 0; } } - else if ( total_brate >= ACELP_16k_LOW_LIMIT ) /* EVS_MONO */ + ELSE IF (GE_32(total_brate, ACELP_16k_LOW_LIMIT) ) /* EVS_MONO */ { return 1; } - else + ELSE { return 0; } diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index d44daf6ad04b9dcf34b3952f5e23b9ba666c5564..1b1046b27fd6f227f47eeabeb9d4ba92ea31893e 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -560,7 +560,276 @@ int16_t get_ivas_max_num_indices( return 2450; } - +Word16 get_ivas_max_num_indices_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +) +{ + IF(EQ_16(ivas_format, STEREO_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 300; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + { + return 400; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 450; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 650; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) + { + return 750; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) + { + return 850; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 950; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 1350; + } + ELSE + { + return 1650; + } + } + ELSE IF(EQ_16(ivas_format, ISM_FORMAT) || EQ_16(ivas_format, MONO_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 250; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + { + return 350; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 450; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 550; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_64k)) + { + return 620; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) + { + return 670; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) + { + return 780; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) + { + return 880; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 950; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 1100; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 1300; + } + ELSE + { + return 1650; + } + } + ELSE IF(EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 250; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + { + return 350; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 400; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 650; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) + { + return 750; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) + { + return 1020; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) + { + return 1160; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 1220; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 1300; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 1720; + } + ELSE + { + return 2000; + } + } + ELSE IF(EQ_16(ivas_format, MASA_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 300; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 400; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 650; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) + { + return 750; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) + { + return 850; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 950; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 1150; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 1450; + } + ELSE + { + return 1650; + } + } + ELSE IF(EQ_16(ivas_format, MASA_ISM_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 300; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 400; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 650; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) + { + return 750; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) + { + return 1150; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 1250; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 1400; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 1650; + } + ELSE + { + return 1850; + } + } + ELSE IF(EQ_16(ivas_format, MC_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 250; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + { + return 350; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 400; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 650; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_64k)) + { + return 750; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_80k)) + { + return 850; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) + { + return 1150; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) + { + return 1420; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 2120; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 2250; + } + ELSE + { + return 2450; + } + } + + return 2450; +} /*-----------------------------------------------------------------------* * get_BWE_max_num_indices() * @@ -771,6 +1040,185 @@ int16_t get_ivas_max_num_indices_metadata( return 50; } +Word16 get_ivas_max_num_indices_metadata_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +) +{ + /* set the maximum required number of metadata indices */ + IF(EQ_16(ivas_format, MONO_FORMAT)) + { + return 0; + } + ELSE IF(EQ_16(ivas_format, STEREO_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 60; + } + ELSE + { + return 80; + } + } + ELSE IF(EQ_16(ivas_format, ISM_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 20; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 65; + } + ELSE + { + return 80; + } + } + ELSE IF(EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 100; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + { + return 200; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 300; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 500; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 1050; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 2000; + } + ELSE + { + return 2500; + } + } + ELSE IF(EQ_16(ivas_format, MASA_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 80; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 125; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 205; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) + { + return 240; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) + { + return 305; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) + { + return 425; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 630; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 850; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 1000; + } + ELSE + { + return 1750; + } + } + ELSE IF(EQ_16(ivas_format, MASA_ISM_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_16k4)) + { + return 80; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_32k)) + { + return 125 + 100; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_48k)) + { + return 205 + 100; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) + { + return 240 + 150; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_128k)) + { + return 305 + 30; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_160k)) + { + return 425 + 30; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_192k)) + { + return 630 + 30; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_256k)) + { + return 850 + 30; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_384k)) + { + return 1000 + 30; + } + ELSE + { + return 1750 + 30; + } + } + ELSE IF(EQ_16(ivas_format, MC_FORMAT)) + { + IF(LE_32(ivas_total_brate, IVAS_13k2)) + { + return 80; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_24k4)) + { + return 100; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_64k)) + { + return 210; + } + ELSE IF(LE_32(ivas_total_brate, IVAS_96k)) + { + return 220; + } + ELSE + { + return 300; + } + } + + return 50; +} /*-------------------------------------------------------------------* * move_indices() * @@ -1313,15 +1761,15 @@ uint16_t get_indice_1( void reset_indices_enc( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t max_num_indices /* i : max number of indices */ + const Word16 max_num_indices /* i : max number of indices */ ) { - int16_t i; + Word16 i; hBstr->nb_bits_tot = 0; hBstr->nb_ind_tot = 0; - for ( i = 0; i < max_num_indices; i++ ) + FOR ( i = 0; i < max_num_indices; i++ ) { hBstr->ind_list[i].nb_bits = -1; } diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 26d3409a3f9add305531be75efe0290962d2e8fe..f75e321a7e39304d366a9c558efcabf505e70567 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -110,9 +110,9 @@ typedef enum _IVAS_ENC_FEC_INDICATOR typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG { - int16_t channelAwareModeEnabled; + Word16 channelAwareModeEnabled; IVAS_ENC_FEC_INDICATOR fec_indicator; - int16_t fec_offset; + Word16 fec_offset; } IVAS_ENC_CHANNEL_AWARE_CONFIG; diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 63843b4c060294ef71803e0cb60f347d7f0bb62b..429695227390f167e3a7f0da13a1153393994912 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -569,6 +569,7 @@ typedef enum #define STEREO_DFT_BITDIFF_LP_FAC (0.06f) /* Low-pass filter coefficient for filtering bit difference between absolute and differential coding */ #define STEREO_DFT_BITDIFF_ABS_SELECT (0.8f) /* Constant to set tendency for selecting absolute coding mode */ #define STEREO_DFT_BITDIFF_INIT (12.0f) /* Init value for low-pass bit difference */ +#define STEREO_DFT_BITDIFF_INIT_FX (12288) /* Init value for low-pass bit difference in Q10*/ #define STEREO_DFT_SIDE_GAIN_NBITS 5 #define STEREO_DFT_IPD_NBITS 3 diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index eb1c24937422dda5bc3b04b2e02d0e379da97592..650c326d9714fefa9d0754dc1fb4c5a07ef421c2 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -2002,7 +2002,6 @@ int32_t calculate_cpe_brate_MASA_ISM( } -#ifdef IVAS_FLOAT_FIXED /*--------------------------------------------------------------- * calculate_cpe_brate_MASA_ISM_fx() * @@ -2052,4 +2051,3 @@ Word32 calculate_cpe_brate_MASA_ISM_fx( return cpe_brate; } -#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 40d2b2d070588f412f808ddf18b6e9a7db428ec7..ac997fe6dcffbf11530de1278d0a5cb86b7dcdae 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -92,6 +92,12 @@ ivas_error create_sce_enc( const int32_t element_brate /* i : element bitrate */ ); +ivas_error create_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ +); + ivas_error create_evs_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -104,6 +110,12 @@ ivas_error create_cpe_enc( const int32_t element_brate /* i : element bitrate */ ); +ivas_error create_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + const Word32 element_brate /* i : element bitrate */ +); + ivas_error create_mct_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -276,6 +288,10 @@ ivas_error ivas_init_encoder( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +ivas_error ivas_init_encoder_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + void destroy_core_enc( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ); @@ -754,6 +770,10 @@ int16_t is_IVAS_bitrate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + int16_t is_DTXrate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); @@ -1338,14 +1358,28 @@ ivas_error stereo_dft_enc_create( const int16_t max_bwidth /* i : maximum encoded bandwidth */ ); +ivas_error stereo_dft_enc_create_fx( + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +); + void stereo_dft_enc_reset( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ); +void stereo_dft_enc_reset_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ +); + void stereo_enc_itd_init( ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ); +void stereo_enc_itd_init_fx( + ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ +); + void stereo_dft_enc_update( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ const int16_t max_bwidth /* i : maximum encoded bandwidth */ @@ -1776,8 +1810,8 @@ int16_t read_BS_adapt_GR_sg( void stereo_dft_hybrid_ITD_flag( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ - const int32_t input_Fs, /* i : CPE element sampling rate */ - const int16_t hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ + const Word32 input_Fs, /* i : CPE element sampling rate */ + const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ ); void stereo_dft_enc_compute_itd( @@ -1997,6 +2031,11 @@ void stereo_tca_init_enc( const int32_t input_Fs /* i : input sampling frequency */ ); +void stereo_tca_init_enc_fx( + STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ + const Word32 input_Fs /* i : input sampling frequency */ +); + void stereo_tca_enc( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int16_t input_frame /* i : length of a frame per channel */ @@ -2052,6 +2091,10 @@ void stereo_icBWE_init_enc( STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ); +void stereo_icBWE_init_enc_fx( + STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ +); + void spectral_balancer( float *signal, float *mem, @@ -2109,6 +2152,10 @@ void stereo_classifier_init( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); +void stereo_classifier_init_fx( + STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ +); + void stereo_classifier_features( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ const int16_t idchan, /* i : channel ID */ @@ -2152,6 +2199,11 @@ void stereo_td_init_enc( const int16_t last_element_mode /* i : last element mode */ ); +void stereo_td_init_enc_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const Word16 last_element_mode /* i : last element mode */ +); + ivas_error stereo_set_tdm( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int16_t input_frame /* i : input frame length per channel */ @@ -2543,11 +2595,27 @@ void initMdctStereoEncData( const int16_t mem_init /* i : initialize memory after malloc */ ); +void initMdctStereoEncData_fx( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 igf, /* i : flag indicating IGF activity */ + const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ + const Word16 mem_init /* i : initialize memory after malloc */ +); + ivas_error initMdctItdHandling( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const int32_t input_Fs /* i : input sampling rate */ ); +ivas_error initMdctItdHandling_fx( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const Word32 input_Fs /* i : input sampling rate */ +); + void stereo_mdct_enc_destroy( STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle */ ); @@ -3002,6 +3070,11 @@ ivas_error front_vad_create( const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ ); +ivas_error front_vad_create_fx( + FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +); + void front_vad_destroy( FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ ); @@ -3951,9 +4024,9 @@ Word16 ivas_sba_get_order_fx( #endif /*! r: Ambisonic (SBA) order used for analysis and coding */ -int16_t ivas_sba_get_analysis_order( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ +Word16 ivas_sba_get_analysis_order( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ ); /*! r: number of Ambisonic channels */ @@ -3976,17 +4049,17 @@ int16_t ivas_sba_get_nchan_metadata( #endif void ivas_sba_get_spar_hoa_ch_ind( - const int16_t num_md_chs, /* i : number of MD channels */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] + const Word16 num_md_chs, /* i : number of MD channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); /*! r: flag indicating to code SPAR HOA MD for all bands */ void ivas_sba_get_spar_hoa_md_flag( - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - int16_t *spar_hoa_md_flag, - int16_t *spar_hoa_dirac2spar_md_flag + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 *spar_hoa_md_flag, + Word16 *spar_hoa_dirac2spar_md_flag ); void ivas_sba_zero_vert_comp( @@ -4668,6 +4741,11 @@ ivas_error ivas_spar_enc_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +ivas_error ivas_spar_enc_open_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + void ivas_spar_enc_close( SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -4779,6 +4857,12 @@ ivas_error ivas_spar_md_enc_init const int16_t sba_order /* i : Ambisonic (SBA) order */ ); +ivas_error ivas_spar_md_enc_init_fx( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + void ivas_agc_dec_process( ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ float *pcm_in[], /* i : input audio channels */ @@ -4845,6 +4929,15 @@ void ivas_spar_set_bitrate_config( const int16_t agc_flag ); +void ivas_spar_set_bitrate_config_fx( + ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ + const Word16 table_idx, /* i : config. table index */ + const Word16 num_bands, /* i : number of bands */ + const Word16 dirac2spar_md_flag, + const Word16 enc_flag, + const Word16 pca_flag, + const Word16 agc_flag); + void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ const int16_t nAvailBits, /* i : number of available bits */ @@ -4965,6 +5058,12 @@ ivas_error ivas_spar_md_enc_open( const int16_t sba_order /* i : Ambisonic (SBA) order */ ); +ivas_error ivas_spar_md_enc_open_fx( + ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); @@ -5378,18 +5477,16 @@ void ivas_huffman_encode( ); void ivas_spar_huff_coeffs_com_init( - ivas_huff_coeffs_t *pHuff_coeffs, - ivas_spar_md_com_cfg *pSpar_cfg, - const int16_t table_idx, - const int16_t enc_dec -); + ivas_huff_coeffs_t *pHuff_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec); void ivas_spar_arith_coeffs_com_init( - ivas_arith_coeffs_t *pArith_coeffs, - ivas_spar_md_com_cfg *pSpar_cfg, - const int16_t table_idx, - const int16_t enc_dec -); + ivas_arith_coeffs_t *pArith_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec); int16_t ivas_arith_encode_cmplx_cell_array( ivas_arith_t *pArith_re, @@ -5490,11 +5587,20 @@ void ivas_spar_get_uniform_quant_strat( const int16_t table_idx ); +void ivas_spar_get_uniform_quant_strat_fx( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const Word16 table_idx); + void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, float *min_max ); +void ivas_spar_quant_dtx_init_fx( + ivas_spar_md_t *spar_md, + Word32 *min_max +); + void ivas_map_prior_coeffs_quant( ivas_spar_md_prev_t *pSpar_md_prior, ivas_spar_md_com_cfg *pSpar_md_cfg, @@ -5515,6 +5621,10 @@ void ivas_clear_band_coeffs( const uint16_t num_bands ); +void ivas_clear_band_coeffs_fx( + ivas_band_coeffs_t *pband_coeffs, + const UWord16 num_bands); + void ivas_clear_band_coeff_idx( ivas_band_coeffs_ind_t *pband_coeff_idx, const uint16_t num_bands diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index e2a114758949b40dc028e579e574acfb57c40c7c..ad2bf714f077b054fc49e1f090969ecccdb41e4c 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -66,7 +66,7 @@ ivas_error ivas_qmetadata_open( ) { /* allocate MetaData handle */ - if ( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) + IF ( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); } diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 1f262adf71a58c0ac7205b92e1d2d209fa35cff6..c1534f075258cbb958506fbf9841fe06e4450357 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -1085,6 +1085,69 @@ const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] = { { 31, 11, 11, 1 },{ 1, 1, 1, 1 },{ 1, 1, 1, 1 } }, 1, 2, 0 }, }; +const ivas_spar_br_table_t ivas_spar_br_table_consts_fx[IVAS_SPAR_BR_TABLE_LEN] = /*ceilf(log2f)*/ +{ + /* When AGC is ON additional (AGC_BITS_PER_CH+1) bits may be taken from each core-coder channel + so minimum core-coder bitrate per channel can be min core-coder bitrates as per the table - AGC_BITS_PER_CH */ + { 13200, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 10000, 8150, 13150 } }, + { { 4, 0, 3, 0 },{ 4, 0, 2, 0 },{ 3, 0, 2, 0 } }, 0, 0, 0 }, + + { 16400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 13200, 11350, 16350 } }, + { { 4, 0, 3, 0 },{ 4, 0, 2, 0 },{ 3, 0, 2, 0 } }, 0, 0, 0 }, + + { 24400, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 16400, 14850, 24350 } }, + { { 4, 0, 3, 0 },{ 4, 0, 2, 0 },{ 3, 0, 2, 0 } }, 0, 0, 0 }, + + { 32000, 0, SBA_FOA_ORDER, FB, 24000, 1, WYXZ, 1, 0, { { 24000, 20450, 31950 } }, + { { 5, 0, 3, 0 },{ 4, 0, 3, 0 },{ 4, 0, 2, 0 } }, 0, 0, 0 }, + + { 48000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0, { { 24000, 21000, 31950 },{ 16000, 15000, 20400 } }, + { { 4, 3, 3, 0 },{ 4, 3, 2, 0 },{ 3, 3, 2, 0 } }, 1, 0, 0 }, + + { 64000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0, { { 38000, 34050, 56000 },{ 16000, 15600, 20400 } },{ { 5, 3, 3, 0 },{ 4, 3, 3, 0 },{ 4, 3, 2, 0 } }, 1, 1, 0 }, + + { 80000, 0, SBA_FOA_ORDER, FB, 24000, 2, WYXZ, 0, 0, { { 46000, 43000, 56000 },{ 24000, 23000, 31950 } }, + { { 5, 3, 3, 0 },{ 4, 3, 3, 0 },{ 4, 3, 2, 0 } }, 1, 0, 0 }, + + { 96000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 47000, 42600, 56000 },{ 23000, 22600, 31950 },{ 16000, 15600, 20400 } }, + { { 5, 4, 4, 0 },{ 5, 3, 3, 0 },{ 5, 3, 3, 0 } }, 1, 0, 0 }, + + { 128000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 55000, 50000, 56000 },{ 36000, 36000, 56000 },{ 27000, 27000, 31950 } }, + { { 5, 4, 4, 0 },{ 5, 4, 3, 0 },{ 5, 3, 3, 0 } }, 1, 0, 0 }, + + { 160000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 74000, 70900, 112000 },{ 41000, 40050, 56000 },{ 35000, 34050, 56000 } }, + { { 5, 4, 4, 0 },{ 5, 4, 4, 0 },{ 5, 3, 3, 0 } }, 1, 0, 0 }, + + { 192000, 0, SBA_FOA_ORDER, FB, 24000, 3, WYXZ, 0, 0, { { 90000, 87900, 112000 },{ 50000, 48050, 56000 },{ 42000, 41050, 56000 } }, + { { 5, 4, 4, 0 },{ 5, 4, 4, 0 },{ 5, 3, 3, 0 } }, 1, 0, 0 }, + + { 256000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 90000, 85000, 112000 },{ 70000, 69000, 112000 },{ 50000, 48950, 56000 },{ 36400, 35600, 56000 } }, + { { 5, 0, 0, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 256000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 84650, 83000, 112000 },{ 65850, 64550, 56000 },{ 47000, 46100, 48000 },{ 28200, 27650, 40000 } }, + { { 5, 4, 4, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 256000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 76300, 73550, 112000 },{ 59350, 57200, 56000 },{ 42400, 40850, 48000 },{ 25450, 24500, 40000 } }, + { { 5, 4, 4, 0 },{ 0, 0, 0, 0 }, { 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 384000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 128000, 128000, 128000 },{ 100000, 100000, 128000 },{ 79850, 79850, 104000 },{ 66600, 66600, 104000 } }, + { { 5, 0, 0, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 384000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 128000, 128000, 128000 },{ 105350, 103300, 112000 },{ 75200, 73750, 96000 },{ 45100, 44250, 48000 } }, + { { 5, 4, 4, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 384000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 124300, 121550, 128000 },{ 96700, 94550, 112000 },{ 69050, 67500, 96000 },{ 41450, 40500, 48000 } }, + { { 5, 4, 4, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 512000, 0, SBA_FOA_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 128000, 128000, 128000 },{ 128000, 128000, 128000 },{ 128000, 128000, 128000 }, {118450, 118450, 128000 } }, + { { 5, 0, 0, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 512000, 0, SBA_HOA2_ORDER, FB, 24000, 4, WYXZ, 0, 0,{ { 124000, 124000, 128000 },{ 124000, 124000, 128000 },{ 125200, 118450, 128000 },{ 76300, 73000, 128000 } }, + { { 5, 4, 4, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, + + { 512000, 0, SBA_HOA3_ORDER, FB, 24000, 4, WYXZ, 0, 0, { { 118000, 118000, 128000 },{ 118000, 118000, 128000 },{ 117200, 109250, 128000 },{ 72300, 69000, 128000 } }, + { { 5, 4, 4, 0 },{ 0, 0, 0, 0 },{ 0, 0, 0, 0 } }, 1, 2, 0 }, +}; const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH] = { /* entry for 1 quantization points */ @@ -6031,6 +6094,13 @@ const float ivas_fb_fcs_12band_1ms[IVAS_FB_BANDS_12] = 0.2166666667f, 0.3333333333f, 0.5083333333f, 0.8083333333f }; +const Word32 ivas_fb_fcs_12band_1ms_fx[IVAS_FB_BANDS_12] = +{ + 17895696, 53687092, 89478488, 125269880, + 161061280, 196852672, 232644064, 304226848, + 465288128, 715827904, 1091637520, 1735882615 +};/*Q31*/ + const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 291, 367 }, diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 05539e1d782d8bb5f34d384c3ac6e2cc17305747..01cebf30498f9956ec2f4115b3f8d252dee7d6e9 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -207,6 +207,7 @@ extern const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ extern const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS]; extern const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; extern const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN]; +extern const ivas_spar_br_table_t ivas_spar_br_table_consts_fx[IVAS_SPAR_BR_TABLE_LEN]; extern const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS]; extern const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN]; extern const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH]; @@ -480,6 +481,7 @@ extern const Word32 dirac_gains_trg_term_int[181][2]; *------------------------------------------------------------------------------------------*/ extern const float ivas_fb_fcs_12band_1ms[IVAS_FB_BANDS_12]; +extern const Word32 ivas_fb_fcs_12band_1ms_fx[IVAS_FB_BANDS_12]; extern const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN]; extern const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN]; diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 47c47c15e29ceab9426978f35493230a5e9b190c..4c103f70ea089bec0ddc130bc5964df339f3cc76 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -241,16 +241,16 @@ Word16 ivas_sba_get_order_fx( *-------------------------------------------------------------------*/ /*! r: Ambisonic (SBA) order used for analysis and coding */ -int16_t ivas_sba_get_analysis_order( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ +Word16 ivas_sba_get_analysis_order( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ ) { - int16_t sba_analysis_order; + Word16 sba_analysis_order; sba_analysis_order = sba_order; - if ( ivas_total_brate < SBA_MIN_BRATE_HOA ) + IF ( LT_32(ivas_total_brate, SBA_MIN_BRATE_HOA )) { /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ sba_analysis_order = SBA_FOA_ORDER; @@ -286,7 +286,6 @@ int16_t ivas_sba_get_nchan( return ( nb_channels ); } -#ifdef IVAS_FLOAT_FIXED Word16 ivas_sba_get_nchan_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word16 sba_planar /* i : SBA planar flag */ @@ -305,7 +304,7 @@ Word16 ivas_sba_get_nchan_fx( return (nb_channels); } -#endif + /*-------------------------------------------------------------------* * ivas_sba_get_nchan_metadata() * @@ -380,23 +379,23 @@ int16_t ivas_sba_get_nchan_metadata( /*! r: flag indicating to code SPAR HOA MD for all bands */ void ivas_sba_get_spar_hoa_ch_ind( - const int16_t num_md_chs, /* i : number of MD channels */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ) + const Word16 num_md_chs, /* i : number of MD channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ) { - int16_t ch; - const int16_t *hoa_ind; + Word16 ch; + const Word16 *hoa_ind; - if ( ivas_total_brate >= IVAS_512k ) + IF (GE_32(ivas_total_brate, IVAS_512k)) { hoa_ind = HOA_keep_ind_spar512; } - else + ELSE { hoa_ind = HOA_keep_ind_spar; } - for ( ch = 0; ch < num_md_chs; ch++ ) + FOR ( ch = 0; ch < num_md_chs; ch++ ) { HOA_md_ind[ch] = hoa_ind[ch]; } @@ -412,25 +411,25 @@ void ivas_sba_get_spar_hoa_ch_ind( *-------------------------------------------------------------------*/ void ivas_sba_get_spar_hoa_md_flag( - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - int16_t *spar_hoa_md_flag, - int16_t *spar_hoa_dirac2spar_md_flag ) + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 *spar_hoa_md_flag, + Word16 *spar_hoa_dirac2spar_md_flag ) { - if ( sba_order > 1 && ivas_total_brate >= IVAS_256k ) + IF ( GT_16(sba_order, 1) && GE_32(ivas_total_brate, IVAS_256k )) { *spar_hoa_md_flag = 1; } - else + ELSE { *spar_hoa_md_flag = 0; } - if ( sba_order > 1 && ivas_total_brate >= IVAS_512k ) + IF (GT_16(sba_order, 1) && GE_32(ivas_total_brate, IVAS_512k)) { *spar_hoa_dirac2spar_md_flag = 0; } - else + ELSE { *spar_hoa_dirac2spar_md_flag = 1; } diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index be9eb075def19a56eb62e496d4a853b5519f8715..5fcfd9ed7753deffb8873379b13f29ce8ec51517 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -41,6 +41,8 @@ #include "cnst.h" #include #include "wmc_auto.h" +#include "basop_util.h" +#include "basop32.h" /*------------------------------------------------------------------------------------------* @@ -2308,7 +2310,174 @@ void ivas_spar_set_bitrate_config( return; } +static Word32 ceil32_fx(Word32 var1, Word16 q) +{ + Word32 ans, temp; + ans = L_shr(var1, q); + temp = L_shl(ans, q); + IF(GT_32(ans, temp)) + return ans; + ELSE + return add(ans, 1); +} +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_set_bitrate_config_fx( + ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ + const Word16 table_idx, /* i : config. table index */ + const Word16 num_bands, /* i : number of bands */ + const Word16 dirac2spar_md_flag, + const Word16 enc_flag, + const Word16 pca_flag, + const Word16 agc_flag) +{ + Word32 ivas_total_brate; + Word16 i, total_bits, max_bits, code, length; + Word16 sba_order; + Word16 md_coding_bits_header; + Word16 agc_bits, pca_bits, num_PR_bits_dirac_bands; + Word16 bits_PR, bits_C, bits_P; + Word16 wc_coarse_strat; + Word16 n_input, n_dmx, n_dec; + Word16 quant_strat; + Word16 bands_bw; + + pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + + FOR (i = 0; i < pSpar_md_cfg->nchan_transport; i++) + { + pSpar_md_cfg->max_freq_per_chan[i] = ivas_spar_br_table_consts[table_idx].fpcs; + } + + pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; + pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; +#if 0 //Some issues + ivas_spar_get_uniform_quant_strat_fx(pSpar_md_cfg, table_idx); +#endif + pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode(MAX_QUANT_STRATS); + + /* BLOCK: getEntropyCoderModels */ + + pSpar_md_cfg->remix_unmix_order = ivas_spar_br_table_consts[table_idx].dmx_str; + + /* bits per block*/ + total_bits = 0; + max_bits = 0; + + ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; + sba_order = ivas_spar_br_table_consts[table_idx].sba_order; + ivas_get_spar_table_idx_fx(ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code); + Word16 temp; + Word16 div1; + FOR (i = 0; i < pSpar_md_cfg->nchan_transport; i++) + { + div1 = BASOP_Util_Divide3232_Scale(ivas_spar_br_table_consts[table_idx].core_brs[i][0], FRAMES_PER_SEC, &temp); + total_bits = add(total_bits, shr(div1, sub(15, temp))); + div1 = BASOP_Util_Divide3232_Scale(ivas_spar_br_table_consts[table_idx].core_brs[i][1], FRAMES_PER_SEC, &temp); + max_bits = add(max_bits, shr(div1, sub(15, temp))); + } + + + div1 = BASOP_Util_Divide3232_Scale(ivas_total_brate, FRAMES_PER_SEC, &temp); + pSpar_md_cfg->tgt_bits_per_blk = sub(shr(div1, sub(15, temp)), add(add(add(add(add(IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS), 0), SBA_ORDER_BITS), length), total_bits)); + pSpar_md_cfg->max_bits_per_blk = sub(shr(div1, sub(15, temp)), add(add(add(add(add(IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS), 0), SBA_ORDER_BITS), length), max_bits)); + md_coding_bits_header = add(SPAR_NUM_CODING_STRAT_BITS, pSpar_md_cfg->quant_strat_bits); + + pSpar_md_cfg->tgt_bits_per_blk = sub(pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header); + pSpar_md_cfg->max_bits_per_blk = sub(pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header); + + IF (LT_32(ivas_total_brate, IVAS_24k4)) + { + bands_bw = 2; + } + ELSE + { + bands_bw = 1; + } + + div1 = BASOP_Util_Divide3232_Scale(i_mult(pSpar_md_cfg->tgt_bits_per_blk, num_bands), IVAS_MAX_NUM_BANDS, &temp); + pSpar_md_cfg->tgt_bits_per_blk = (Word16)ceil32_fx(div1, 15 - temp); + + div1 = BASOP_Util_Divide3232_Scale(i_mult(pSpar_md_cfg->max_bits_per_blk, num_bands), IVAS_MAX_NUM_BANDS, &temp); + pSpar_md_cfg->max_bits_per_blk = (Word16)ceil32_fx(div1, 15 - temp); + + pSpar_md_cfg->tgt_bits_per_blk = add(pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header); + pSpar_md_cfg->max_bits_per_blk = add(pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header); + + IF (enc_flag) + { + /*calculate the actual worst case bits*/ + IF (GE_32(ivas_total_brate, BRATE_SPAR_Q_STRAT)) + { + quant_strat = QUANT_STRAT_0; + } + ELSE + { + quant_strat = QUANT_STRAT_2; + } + + num_PR_bits_dirac_bands = (EQ_16(dirac2spar_md_flag, 1)) ? sub(num_bands, SPAR_DIRAC_SPLIT_START_BAND) : 0; + div1 = BASOP_Util_Divide3232_Scale(num_PR_bits_dirac_bands, bands_bw, &temp); + num_PR_bits_dirac_bands = shr(div1, sub(15, temp)); + num_PR_bits_dirac_bands = s_max(0, num_PR_bits_dirac_bands); + num_PR_bits_dirac_bands = i_mult(num_PR_bits_dirac_bands, DIRAC_TO_SPAR_HBR_PRED_CHS); + + n_input = ivas_sba_get_nchan_metadata(sba_order, ivas_total_brate); + n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; + n_dec = sub(n_input, n_dmx); + bits_PR = ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][0]; + num_PR_bits_dirac_bands = i_mult(num_PR_bits_dirac_bands, bits_PR); + bits_PR = i_mult(bits_PR, sub(n_input, 1)); + bits_C = i_mult(ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][1], i_mult( sub(n_dmx, 1), n_dec)); + bits_P = i_mult(ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][2], n_dec); + + wc_coarse_strat = add(add(bits_PR, bits_C), bits_P); + wc_coarse_strat = i_mult(wc_coarse_strat, num_bands); + div1 = BASOP_Util_Divide3232_Scale(wc_coarse_strat, bands_bw, &temp); + wc_coarse_strat = shr(div1, sub(15, temp)); + wc_coarse_strat = sub(wc_coarse_strat, num_PR_bits_dirac_bands); + wc_coarse_strat = add(wc_coarse_strat, md_coding_bits_header); + + IF (LT_16(pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat)) + { + assert(0); + } + + IF (agc_flag) + { + IF (EQ_16(pSpar_md_cfg->nchan_transport, 1)) + { + agc_bits = AGC_BITS_PER_CH; + } + ELSE + { + agc_bits = add(i_mult(AGC_BITS_PER_CH, pSpar_md_cfg->nchan_transport), AGC_SIGNALLING_BITS); + } + } + ELSE + { + agc_bits = AGC_SIGNALLING_BITS; + } + + IF (EQ_32(ivas_total_brate, PCA_BRATE) && EQ_32(sba_order, SBA_FOA_ORDER)) + { + pca_bits = 1; + IF (pca_flag) + { + pca_bits = add(pca_bits, sub(add(IVAS_PCA_QBITS, IVAS_PCA_QBITS), 1)); + } + } + ELSE + { + pca_bits = 0; + } + + pSpar_md_cfg->max_md_bits_spar = add(add(pSpar_md_cfg->max_bits_per_blk, agc_bits), pca_bits); + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_bitrate_dist() * diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index c218efa9f851095edd30bdebb0000e047530cf87..40f4dafcc101886889c8899f3c46350c94a49790 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -38,7 +38,7 @@ #include "ivas_rom_com.h" #include #include "wmc_auto.h" - +#include "prot_fx1.h" /*-----------------------------------------------------------------------------------------* * Function ivas_quantise_real_values() * @@ -156,8 +156,73 @@ void ivas_spar_get_uniform_quant_strat( return; } +#if 0 +void ivas_spar_get_uniform_quant_strat_fx( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const Word16 table_idx) +{ + Word16 i; + Word16 active_w = ivas_spar_br_table_consts[table_idx].active_w; + Word16 PQ_q_lvl, C_q_lvl, Pr_q_lvl, Pc_q_lvl; + + pSpar_md_com_cfg->num_quant_strats = MAX_QUANT_STRATS; + FOR (i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++) + { + PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; + C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; + Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; + Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3]; + IF (active_w) + { + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -1288490188;//Q30 + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 1288490188;//Q30 + + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -858993459;//Q30 + pSpar_md_com_cfg->quant_strat[i].C.max_fx = 858993459;//Q30 + + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 858993459;//Q30 + + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -858993459;//Q30 + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 858993459;//Q30 + } + ELSE + { + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q30;//Q30 + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q30;//Q30 + + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.max_fx = 2147483648;//Q30 + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -2147483648;//Q30 + + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q30;//Q30 + pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; + + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 536870912;//Q30 + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -536870912;//Q30 + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_map_prior_coeffs_quant() * @@ -227,8 +292,17 @@ void ivas_spar_quant_dtx_init( return; } +#if 0 +void ivas_spar_quant_dtx_init_fx( + ivas_spar_md_t *spar_md, + Word32 *min_max) +{ + spar_md->min_max_fx[0] = min_max[0]; + spar_md->min_max_fx[1] = min_max[1]; - + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_copy_band_coeffs_idx_to_arr() * @@ -306,8 +380,26 @@ void ivas_clear_band_coeffs( return; } - - +#if 0 +void ivas_clear_band_coeffs_fx( + ivas_band_coeffs_t *pband_coeffs, + const UWord16 num_bands) +{ + UWord16 i; + + for (i = 0; i < num_bands; i++) + { + set32_fx((Word32 *)pband_coeffs[i].C_re_fx, 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); + set32_fx((Word32 *)pband_coeffs[i].P_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); + set32_fx((Word32 *)pband_coeffs[i].C_quant_re_fx, 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); + set32_fx((Word32 *)pband_coeffs[i].P_quant_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); + set32_fx(pband_coeffs[i].pred_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); + set32_fx(pband_coeffs[i].pred_quant_re_fx, 0, (IVAS_SPAR_MAX_CH - 1)); + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_clear_band_coeff_idx() * @@ -316,15 +408,15 @@ void ivas_clear_band_coeffs( void ivas_clear_band_coeff_idx( ivas_band_coeffs_ind_t *pband_coeff_idx, - const uint16_t num_bands ) + const UWord16 num_bands ) { - uint16_t i = 0; + UWord16 i = 0; for ( i = 0; i < num_bands; i++ ) { - set_s( pband_coeff_idx[i].pred_index_re, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); - set_s( pband_coeff_idx[i].drct_index_re, 0, IVAS_SPAR_MAX_C_COEFF ); - set_s( pband_coeff_idx[i].decd_index_re, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); + set16_fx( pband_coeff_idx[i].pred_index_re, 0, ( sub(IVAS_SPAR_MAX_CH, 1 )) ); + set16_fx( pband_coeff_idx[i].drct_index_re, 0, IVAS_SPAR_MAX_C_COEFF ); + set16_fx( pband_coeff_idx[i].decd_index_re, 0, sub( IVAS_SPAR_MAX_CH, 1 ) ); } return; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index cbbe26c8a1b42f916565517c5e82f984f9003359..6dfb0b6ede7f3c90e0335fafc852b54d61f6600d 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -186,7 +186,6 @@ typedef struct ivas_band_coeffs_t float pred_quant_re[IVAS_SPAR_MAX_CH - 1]; float C_quant_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; float P_quant_re[IVAS_SPAR_MAX_CH - 1]; - } ivas_band_coeffs_t; typedef struct ivas_band_coeffs_ind_t @@ -208,7 +207,6 @@ typedef struct ivas_spar_md_t float ref_pow_slow[IVAS_MAX_NUM_BANDS]; int16_t res_ind; int16_t prior_dyn_active_w_flag; - } ivas_spar_md_t; typedef struct ivas_spar_md_prev_t @@ -223,7 +221,6 @@ typedef struct ivas_quant_coeffs_t float min; float max; int16_t q_levels[2]; - } ivas_quant_coeffs_t; typedef struct ivas_quant_strat_t diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index ae8b78dfe78a61bc5b731debf8ce58626bb0f6e7..88aac4a76bdc902be6629a24013e9b146602b273 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -2366,6 +2366,25 @@ int16_t is_IVAS_bitrate( return 1; } +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +) +{ + Word16 j; + + j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ + WHILE (LE_16(j, SIZE_IVAS_BRATE_TBL) && NE_32(ivas_total_brate, ivas_brate_tbl[j])) + { + j++; + } + + IF (j >= SIZE_IVAS_BRATE_TBL) + { + return 0; + } + + return 1; +} /*-------------------------------------------------------------------* * is_DTXrate() diff --git a/lib_com/prot.h b/lib_com/prot.h index 15cd04ba10c8266567ae5efcfa79923a13323a8c..845f39f597463da1767baae646c1cf57d91b1ae9 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -537,6 +537,11 @@ int16_t get_ivas_max_num_indices( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); +Word16 get_ivas_max_num_indices_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + /*! r: maximum number of indices */ int16_t get_BWE_max_num_indices( const int32_t extl_brate /* i : extensiona layer bitrate */ @@ -548,6 +553,10 @@ int16_t get_ivas_max_num_indices_metadata( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); +Word16 get_ivas_max_num_indices_metadata_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); ivas_error ind_list_realloc( INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */ @@ -2287,6 +2296,17 @@ ivas_error init_encoder( const int32_t element_brate /* element bitrate */ ); +ivas_error init_encoder_ivas_fx( + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ + const Word16 interval_SID, /* i : interval for SID update */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ +); + void LPDmem_enc_init( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); @@ -9367,6 +9387,7 @@ ivas_error config_acelp1_IVAS( ); /*! r: ACELP16k flag */ + #ifndef IVAS_FLOAT_FIXED int16_t set_ACELP_flag_IVAS( const int16_t element_mode, /* i : element mode */ diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index d716096c77955e17c3e448a0aeed9eab158867d6..71197decb6139a03f64a5e3e922b3e78f6bd90ad 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -275,7 +275,7 @@ void deleteFdCngEnc( HANDLE_FD_CNG_ENC hsEnc = *hFdCngEnc; - if ( hsEnc != NULL ) + IF ( hsEnc != NULL ) { deleteFdCngCom_flt( &( hsEnc->hFdCngCom ) ); free( hsEnc ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 750173b416c65cf7c463932e72006aa297752977..a5ac653ee75c9aeb679259af2898c13e87cc3244 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -46,6 +46,8 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #endif +#include "tools_fx.c" +#include "prot_fx_enc.h" /*-----------------------------------------------------------------------* * init_encoder() @@ -880,8 +882,843 @@ ivas_error init_encoder( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error init_encoder_ivas_fx( + Encoder_State *st, /* i/o: state structure */ + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + const Word16 idchan, /* i : channel ID */ + const Word16 var_SID_rate_flag, /* i : flag for variable SID update rate */ + const Word16 interval_SID, /* i : interval for SID update */ + const Word16 vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word32 element_brate /* i : element bitrate */ +) +{ + Word16 i; + ivas_error error; + Word32 igf_brate; + + error = IVAS_ERR_OK; + + /*-----------------------------------------------------------------* + * General parameters + *-----------------------------------------------------------------*/ + + IF (st->Opt_AMR_WB) + { + st->last_core = AMR_WB_CORE; + } + ELSE + { + st->last_core = -1; + } + + st->L_frame = L_FRAME; + st->last_coder_type = GENERIC; + st->coder_type = GENERIC; + st->last_total_brate = st->total_brate; + st->last_bits_frame_nominal = -1; + st->last_total_brate_cng = -1; + st->last_core_brate = st->total_brate; + st->dtx_sce_sba = 0; + st->extl = -1; + st->last_extl = -1; + st->last_L_frame = L_FRAME; + st->rate_switching_reset = 0; + st->rate_switching_reset_16kHz = 0; + st->clas = UNVOICED_CLAS; + st->low_rate_mode = 0; + st->ini_frame = 0; + st->inactive_coder_type_flag = 0; + st->sba_br_sw_while_no_data = 0; + + st->coder_type_raw = VOICED; + st->last_coder_type_raw = st->coder_type_raw; + + st->flag_ACELP16k = set_ACELP_flag_IVAS(st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1); + + st->is_ism_format = 0; + IF (ism_mode != ISM_MODE_NONE) + { + st->is_ism_format = 1; + } + + /*-----------------------------------------------------------------* + * Bitstream + *-----------------------------------------------------------------*/ + + IF (!vad_only_flag) + { + IF ((st->hBstr = (BSTR_ENC_HANDLE)malloc(sizeof(BSTR_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Bitstream structure\n")); + } + + /* set pointer to the buffer of indices */ + st->hBstr->ind_list = st_ivas->ind_list; + st->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + st->hBstr->ivas_max_num_indices = &st_ivas->ivas_max_num_indices; + st->hBstr->nb_ind_tot = 0; + st->hBstr->nb_bits_tot = 0; + st->hBstr->st_ivas = st_ivas; + } + ELSE + { + st->hBstr = NULL; + } + + /*-----------------------------------------------------------------* + * Pre-processing and ACELP core parameters + *-----------------------------------------------------------------*/ + + Copy(GEWB_Ave_fx, st->mem_AR_fx, M); + Copy(GEWB_Ave_fx, st->lsfoldbfi0_fx, M); + Copy(GEWB_Ave_fx, st->lsfoldbfi1_fx, M); + Copy(GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M); + + st->next_force_safety_net = 0; + + st->pstreaklen = 0; + st->streaklimit_fx = MAX_WORD16; + set16_fx(st->mem_MA_fx, 0, M); + + init_gp_clip_fx(st->clip_var_fx); + pitch_ol_init_fx(&st->old_thres_fx, &st->old_pitch, &st->delta_pit, &st->old_corr_fx); + set16_fx(st->old_wsp_fx, 0, L_WSP_MEM); + set16_fx(st->old_wsp2_fx, 0, (L_WSP_MEM - L_INTERPOL) / OPL_DECIM); //Needs to change depending on usage. + + st->mem_preemph_fx = 0; + st->mem_preemph16k_fx = 0; + st->mem_preemph_enc = 0; + + /* AVQ pre-quantizer memory */ + st->mem_preemp_preQ_fx = 0; + st->mem_deemp_preQ_fx = 0; + st->last_nq_preQ = 0; + st->last_code_preq = 0; + st->use_acelp_preq = 0; + st->last_harm_flag_acelp = 0; + + /* (Decimated) Weighted Speech Memory */ + st->mem_wsp_enc = 0; + st->mem_wsp_fx = 0; + + set16_fx(st->mem_decim2_fx, 0, 3); + set32_fx(st->Bin_E_fx, 0, L_FFT); + + st->ee_old_fx = 640;/*chk //10 in Q6 */ + st->Nb_ACELP_frames = 0; + st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ + + /* adaptive lag window memory */ + st->old_pitch_la = 0; + + IF (EQ_32(st->input_Fs, 8000)) + { + st->min_band = 1; + st->max_band = 16; + } + ELSE + { + st->min_band = 0; + st->max_band = 19; + } + + IF (st->Opt_AMR_WB) + { + Copy(mean_isf_amr_wb_fx, st->lsf_old_fx, M); + E_LPC_isf_isp_conversion(st->lsf_old_fx, st->lsp_old1_fx, M); + } + ELSE + { + Copy(GEWB_Ave_fx, st->lsf_old_fx, M); + lsf2lsp_fx(st->lsf_old_fx, st->lsp_old1_fx, M, INT_FS_12k8); + } + + Copy(st->lsf_old_fx, st->lsf_old1_fx, M); + Copy(st->lsp_old1_fx, st->lsp_old_fx, M); + Copy(st->lsp_old_fx, st->lsp_old16k_fx, M); + Copy(st->lsp_old_fx, st->lspold_enc_fx, M); + + st->stab_fac_fx = 0; + + /* Bass post-filter memories - encoder side of MODE2 */ + st->bpf_off = 0; + st->pst_mem_deemp_err_fx = 0; + st->pst_lp_ener_fx = 0; + + /* TC coder type */ + st->tc_cnt = 0; + + /* find_uv() parameters */ + st->old_dE1_fx = 0; + st->old_ind_deltaMax = 0; + set32_fx(st->old_enr_ssf_fx, 0, shl(NB_SSF, 1)); + st->spike_hyst = -1; + + /* stereo switching memories */ + st->mem_preemph_DFT_fx = 0; + set32_fx(st->inp_12k8_mem_stereo_sw_fx, 0, sub(sub(STEREO_DFT_OVL_12k8, L_MEM_RECALC_12K8), L_FILT)); + st->mem_preemph16k_DFT_fx = 0; + set32_fx(st->inp_16k_mem_stereo_sw_fx, 0, sub(sub(STEREO_DFT_OVL_16k, L_MEM_RECALC_16K), L_FILT16k)); + + st->sharpFlag = 0; + + /* Stationary noise UV modification */ + st->ge_sm_fx = 10;/*chk //10 in Q6 */ + st->uv_count = 0; + st->act_count = 3; + Copy(st->lsp_old_fx, st->lspold_s_fx, M); + st->noimix_seed = RANDOM_INITSEED; + st->min_alpha_fx = 1; + st->exc_pe = 0; + + /* FEC */ + st->last_clas = UNVOICED_CLAS; + st->prev_fmerit = 0; + st->fmerit_dt = 0; + st->Last_pulse_pos = 0; + + FOR (i = 0; i < shl(NB_SUBFR16k, 1); i++) + { + st->old_pitch_buf[i] = L_SUBFR; + } + + /* mode1 core switching */ + st->old_Es_pred = 0; + set16_fx(st->old_Aq_12_8_fx + 1, 0, M); + st->old_Aq_12_8_fx[0] = 1; + + /* stable short pitch detection */ + st->voicing0_sm_fx = 0; + st->voicing_sm_fx = 0; + st->LF_EnergyRatio_sm_fx = 1; + st->predecision_flag = 0; + st->diff_sm_fx = 0; + st->energy_sm_fx = 0; + + set16_fx(st->pitch, L_SUBFR, 3); + set16_fx(st->voicing_fx, 0, 3); + + /*-----------------------------------------------------------------* + * General signal buffers + *-----------------------------------------------------------------*/ + + IF (!vad_only_flag) + { + IF ((st->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE)malloc(sizeof(SIGNAL_BUFFERS_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n")); + } + + st->Bin_E_old_fx = st->hSignalBuf->Bin_E_old_fx; + st->mem_decim_fx = st->hSignalBuf->mem_decim_fx; + st->mem_decim16k_fx = st->hSignalBuf->mem_decim16k_fx; + st->old_inp_12k8_fx = st->hSignalBuf->old_inp_12k8_fx; + st->old_inp_16k_fx = st->hSignalBuf->old_inp_16k_fx; + st->buf_speech_enc_pe = st->hSignalBuf->buf_speech_enc_pe; + st->buf_synth = st->hSignalBuf->buf_synth; + st->buf_speech_enc = st->hSignalBuf->buf_speech_enc; + st->buf_wspeech_enc = st->hSignalBuf->buf_wspeech_enc; + + /* initializations */ + set32_fx(st->Bin_E_old_fx, 0, shr(L_FFT, 2)); + set16_fx(st->mem_decim_fx, 0, shl(L_FILT_MAX, 1)); + set16_fx(st->mem_decim16k_fx, 0, shl(L_FILT_MAX, 1)); + set16_fx(st->old_inp_12k8_fx, 0, L_INP_MEM); + set16_fx(st->old_inp_16k_fx, 0, L_INP_MEM); + + st->input_buff_fx = st->hSignalBuf->input_buff; + set16_fx(st->input_buff_fx, 0, add(L_FRAME48k, add( L_FRAME48k , NS2SA(48000, DELAY_FIR_RESAMPL_NS)))); + st->old_input_signal_fx = st->input_buff_fx; + Word16 temp; + Word16 frame_length = BASOP_Util_Divide3232_Scale(st->input_Fs, FRAMES_PER_SEC, &temp); + + IF (EQ_16(st->element_mode, EVS_MONO)) + { + st->input_fx = st->input_buff_fx + add(frame_length, (Word16)NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS)); + } + ELSE + { + st->input_fx = st->input_buff_fx + frame_length; + } + } + ELSE + { + st->hSignalBuf = NULL; + st->Bin_E_old_fx = NULL; + st->mem_decim_fx = NULL; + st->mem_decim16k_fx = NULL; + st->old_inp_12k8_fx = NULL; + st->old_inp_16k_fx = NULL; + st->buf_speech_enc_pe = NULL; + st->buf_synth = NULL; + st->buf_speech_enc = NULL; + st->buf_wspeech_enc = NULL; + st->input_buff_fx = NULL; + } + + /*-----------------------------------------------------------------* + * Noise estimator + *-----------------------------------------------------------------*/ + + IF (EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hNoiseEst = (NOISE_EST_HANDLE)malloc(sizeof(NOISE_EST_DATA))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n"); + } + + noise_est_init_fx(st->hNoiseEst); + } + ELSE + { + st->hNoiseEst = NULL; + } + + /*-----------------------------------------------------------------* + * VAD + *-----------------------------------------------------------------*/ + + st->vad_flag = 1; + st->localVAD = 0; + + IF ((EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->element_mode, EVS_MONO)) && (!vad_only_flag)) + { + IF ((st->hVAD = (VAD_HANDLE)malloc(sizeof(VAD_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n")); + } + + wb_vad_init_ivas_fx(st->hVAD); + } + ELSE + { + st->hVAD = NULL; + } + st->Pos_relE_cnt = 20; + + /* CLDFB-based VAD */ + IF (st->element_mode == EVS_MONO) + { + IF ((st->hVAD_CLDFB = (VAD_CLDFB_HANDLE)malloc(sizeof(T_CldfbVadState))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n")); + } + + vad_init_ivas_fx(st->hVAD_CLDFB); + } + ELSE + { + st->hVAD_CLDFB = NULL; + } + + /*-----------------------------------------------------------------* + * Speech/music classifier + *-----------------------------------------------------------------*/ + + IF (EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_TD) || EQ_16(st->element_mode, IVAS_CPE_MDCT) || EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hSpMusClas = (SP_MUS_CLAS_HANDLE)malloc(sizeof(SP_MUS_CLAS_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Speech/music classifier\n")); + } + + speech_music_clas_init_fx(st->hSpMusClas); + + st->sp_aud_decision0 = 0; + st->sp_aud_decision1 = 0; + st->sp_aud_decision2 = 0; + } + ELSE + { + st->hSpMusClas = NULL; + } + + + /*-----------------------------------------------------------------* + * WB, SWB and FB bandwidth detector + *-----------------------------------------------------------------*/ + + st->lt_mean_NB_fx = 0; + st->lt_mean_WB_fx = 0; + st->lt_mean_SWB_fx = 0; + st->count_WB = BWD_COUNT_MAX; + st->count_SWB = BWD_COUNT_MAX; + st->count_FB = BWD_COUNT_MAX; + st->bwidth = st->max_bwidth; + st->last_input_bwidth = st->bwidth; + st->last_bwidth = st->bwidth; + st->last_bwidth_cng = st->bwidth; + st->bwidth_sw_cnt = 0; + + + /*-----------------------------------------------------------------* + * DTX + *-----------------------------------------------------------------*/ + + st->lp_speech_fx = 11520; /*Q8 (45.0) */ /* Initialize the long-term active speech level in dB */ + st->lp_noise_fx = 0; + st->flag_noisy_speech_snr = 0; + st->fd_cng_reset_flag = 0; + st->cng_type = -1; + st->bckr_tilt_lt = 0; + st->active_cnt = 0; + + IF (((EQ_16(idchan, 0) && st->Opt_DTX_ON) || EQ_16(st->element_mode, EVS_MONO)) || (EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->Opt_DTX_ON)) + { + IF ((st->hDtxEnc = (DTX_ENC_HANDLE)malloc(sizeof(DTX_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX variables\n")); + } + dtx_enc_init_fx(st, var_SID_rate_flag, interval_SID); + } + ELSE + { + st->hDtxEnc = NULL; + } + + /*-----------------------------------------------------------------* + * No other handles needed to be allocated for front-VAD structure + *-----------------------------------------------------------------*/ + + IF (vad_only_flag) + { + st->hTdCngEnc = NULL; + st->cldfbAnaEnc = NULL; + st->hFdCngEnc = NULL; + st->hSC_VBR = NULL; + st->hAmrwb_IO = NULL; + st->hLPDmem = NULL; + st->hGSCEnc = NULL; + st->hBWE_TD = NULL; + st->cldfbSynTd = NULL; + st->hBWE_FD = NULL; + st->hHQ_core = NULL; + st->hRF = NULL; + st->hTECEnc = NULL; + st->hTcxEnc = NULL; + st->hTcxCfg = NULL; + st->hIGFEnc = NULL; + st->hPlcExt = NULL; + st->hTranDet = NULL; + + st->element_mode = IVAS_SCE; + st->idchan = 100; /* indicates hCoreCoderVAD */ + st->core = -1; + st->rf_mode = 0; + + return error; + } + + /*-----------------------------------------------------------------* + * LP-CNG + *-----------------------------------------------------------------*/ + + IF (((EQ_16(idchan, 0) && st->Opt_DTX_ON && NE_16(st->element_mode, IVAS_CPE_MDCT)) || EQ_16(st->element_mode, EVS_MONO)) && !(EQ_16(ism_mode, ISM_MODE_PARAM) || EQ_16(ism_mode, ISM_MODE_DISC))) + { + IF ((st->hTdCngEnc = (TD_CNG_ENC_HANDLE)malloc(sizeof(TD_CNG_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n")); + } + + td_cng_enc_init_fx(st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth); + } + ELSE + { + st->hTdCngEnc = NULL; + } + + /*-----------------------------------------------------------------* + * CLDFB & resampling tools parameters + *-----------------------------------------------------------------*/ + + IF ((NE_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(idchan, 0)) || (EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->Opt_DTX_ON)) + { + IF ((error = openCldfb_ivas(&st->cldfbAnaEnc, CLDFB_ANALYSIS, st->input_Fs, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + } + ELSE + { + st->cldfbAnaEnc = NULL; + } + + st->currEnergyLookAhead = 130996; /* 6.1e-5f in Q31 */ + + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + + IF (st->Opt_SC_VBR || EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hSC_VBR = (SC_VBR_ENC_HANDLE)malloc(sizeof(SC_VBR_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n")); + } + + sc_vbr_enc_init_fx(st->hSC_VBR); + } + ELSE + { + st->hSC_VBR = NULL; + } + + st->last_Opt_SC_VBR = 0; + + + /*-----------------------------------------------------------------* + * AMR-WB IO initialization + *-----------------------------------------------------------------*/ + + IF (st->Opt_AMR_WB || EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hAmrwb_IO = (AMRWB_IO_ENC_HANDLE)malloc(sizeof(AMRWB_IO_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n")); + } + + amr_wb_enc_init_fx(st->hAmrwb_IO); + } + ELSE + { + st->hAmrwb_IO = NULL; + } + + /*-----------------------------------------------------------------* + * ACELP LPDmem + *-----------------------------------------------------------------*/ + + IF ((EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) || EQ_16(st->element_mode, IVAS_CPE_TD)) + { + IF ((st->hLPDmem = (LPD_state_HANDLE)malloc(sizeof(LPD_state))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LPDmem\n")); + } + LPDmem_enc_init_fx(st->hLPDmem); + } + ELSE + { + st->hLPDmem = NULL; + } + /*-----------------------------------------------------------------* + * parameters for AC coder type (GSC) + *-----------------------------------------------------------------*/ + + st->GSC_noisy_speech = 0; + st->GSC_IVAS_mode = 0; + + IF ((EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) || EQ_16(st->element_mode, IVAS_CPE_TD)) + { + IF ((st->hGSCEnc = (GSC_ENC_HANDLE)malloc(sizeof(GSC_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); + } + + GSC_enc_init_fx(st->hGSCEnc); + } + ELSE + { + st->hGSCEnc = NULL; + } + + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ + + IF (EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + IF ((st->hBWE_TD = (TD_BWE_ENC_HANDLE)malloc(sizeof(TD_BWE_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n")); + } + + IF ((error = openCldfb_ivas(&st->cldfbSynTd, CLDFB_SYNTHESIS, 16000, CLDFB_PROTOTYPE_1_25MS)) != IVAS_ERR_OK) + { + return error; + } + + InitSWBencBuffer_fx(st); + ResetSHBbuffer_Enc_fx(st); + } + ELSE + { + st->hBWE_TD = NULL; + st->cldfbSynTd = NULL; + } + + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + + IF (EQ_16(idchan, 0) && NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + IF ((st->hBWE_FD = (FD_BWE_ENC_HANDLE)malloc(sizeof(FD_BWE_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n")); + } + + fd_bwe_enc_init_fx(st->hBWE_FD); + } + ELSE + { + st->hBWE_FD = NULL; + } + + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ + + IF (NE_16(st->element_mode, IVAS_CPE_TD) && NE_16(st->element_mode, IVAS_CPE_MDCT) && EQ_16(idchan, 0)) + { + IF ((st->hHQ_core = (HQ_ENC_HANDLE)malloc(sizeof(HQ_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n")); + } + + HQ_core_enc_init_fx(st->hHQ_core); + } + ELSE + { + st->hHQ_core = NULL; + } + + /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ + st->old_hpfilt_in_fx = 0; + st->old_hpfilt_out_fx = 0; + st->EnergyLT_fx = 0; + st->Energy_Old_fx = 0; + st->TransientHangOver = 0; + + /*-----------------------------------------------------------------* + * Channel-aware mode + *-----------------------------------------------------------------*/ + + IF (!st->Opt_RF_ON || (NE_16(st->bwidth, WB) && NE_16(st->bwidth, SWB)) || NE_32(st->total_brate, ACELP_13k20)) + { + st->rf_mode = 0; + } + ELSE + { + st->rf_mode = st->Opt_RF_ON; + } + + st->rf_mode_last = st->rf_mode; + + IF (st->Opt_RF_ON || EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hRF = (RF_ENC_HANDLE)malloc(sizeof(RF_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for RF\n")); + } + + /* initialize RF indice buffers */ + reset_rf_indices_fx(st); + } + ELSE + { + st->hRF = NULL; + } + + /*-----------------------------------------------------------------* + * Temporal Envelope Coding + *-----------------------------------------------------------------*/ + + IF (EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hTECEnc = (TEC_ENC_HANDLE)malloc(sizeof(TEC_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); + } + } + ELSE + { + st->hTECEnc = NULL; + } + /* note: initialization done later in init_coder_ace_plus() */ + + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ + + // ToDo: reduction possible for MCT_CHAN_MODE_LFE channel + IF (EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_MDCT)) + { + IF ((st->hTcxEnc = (TCX_ENC_HANDLE)malloc(sizeof(TCX_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n")); + } + + /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ + st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; + st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; + + set16_fx(st->hTcxEnc->old_out_fx, 0, L_FRAME32k); + + /* MDCT selector */ + MDCT_selector_reset_fx(st->hTcxEnc); + + /* MDCT classifier */ + MDCT_classifier_reset_fx(st->hTcxEnc); + + IF ((st->hTcxCfg = (TCX_CONFIG_HANDLE)malloc(sizeof(TCX_config))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n")); + } + } + ELSE + { + st->hTcxEnc = NULL; + st->hTcxCfg = NULL; + } + + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ + + igf_brate = st->total_brate; + IF (EQ_16(st->element_mode, IVAS_SCE) && (EQ_16(st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT) || EQ_16(st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT))) + { + igf_brate = L_sub(st->total_brate, i_mult(ISM_NB_BITS_METADATA_NOMINAL, FRAMES_PER_SEC)); + } + ELSE IF (EQ_16(st->element_mode, IVAS_CPE_DFT) || (EQ_16(st->element_mode, IVAS_SCE) && (EQ_16(st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT) || + EQ_16(st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT) || + EQ_16(st_ivas->hEncoderConfig->ivas_format, MC_FORMAT) || + EQ_16(st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT)))) + { + /* use nominal bitrates for DFT Stereo and (O)SBA, same as in stereo_dft_config()/ivas_spar_config() */ + IF (EQ_32(element_brate, IVAS_13k2)) + { + igf_brate = ACELP_9k60; + } + ELSE IF (EQ_32(element_brate, IVAS_16k4)) + { + igf_brate = ACELP_13k20; + } + ELSE IF (EQ_32(element_brate, IVAS_24k4)) + { + igf_brate = ACELP_16k40; + } + ELSE IF (EQ_32(element_brate, IVAS_32k)) + { + igf_brate = ACELP_24k40; + } + } + ELSE IF (st->element_mode == IVAS_CPE_MDCT) + { + igf_brate = element_brate; + } + + IF (EQ_16(st->codec_mode, MODE2) || GT_16(st->element_mode, EVS_MONO)) + { + st->igf = getIgfPresent_fx(st->element_mode, igf_brate, st->max_bwidth, st->rf_mode); + } + ELSE + { + st->igf = 0; + } + + IF ((EQ_16(idchan, 0) || EQ_16(st->element_mode, IVAS_CPE_MDCT)) && (st->igf || EQ_16(st->element_mode, EVS_MONO))) + { + IF ((st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE)malloc(sizeof(IGF_ENC_INSTANCE))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n")); + } + } + ELSE + { + st->hIGFEnc = NULL; + } + + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ + + st->last_sr_core = L_mult(st->last_L_frame, FRAMES_PER_SEC); + + + /* PLC encoder */ + IF (EQ_16(st->element_mode, EVS_MONO)) + { + IF ((st->hPlcExt = (PLC_ENC_EVS_HANDLE)malloc(sizeof(PLC_ENC_EVS))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hPlcExt\n")); + } + } + ELSE + { + st->hPlcExt = NULL; + } + + /* Init Mode 2 core coder */ + st->last_totalNoise_fx = 0; + set16_fx(st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE); + st->totalNoise_increase_len = 0; + + init_coder_ace_plus_fx(st, st->last_total_brate, 0, -10 /* initialization value */); + + /*-----------------------------------------------------------------* + * FD-CNG encoder + *-----------------------------------------------------------------*/ + + IF ((EQ_16(idchan, 0) && st->Opt_DTX_ON) || EQ_16(st->element_mode, EVS_MONO) || (EQ_16(st->element_mode, IVAS_CPE_MDCT) && st->Opt_DTX_ON)) + { +#if 0 + IF ((error = createFdCngEnc_fx(&st->hFdCngEnc)) != IVAS_ERR_OK) + { + return error; + } +#endif + createFdCngEnc_fx(&st->hFdCngEnc); + initFdCngEnc_fx(st->hFdCngEnc, st->input_Fs, st->cldfbAnaEnc->scale); + + /* initialization for IVAS modes happens in first frame pre-processing */ + IF (EQ_16(st->element_mode, EVS_MONO)) + { + configureFdCngEnc_fx(st->hFdCngEnc, st->bwidth, st->rf_mode && st->total_brate == ACELP_13k20 ? ACELP_9k60 : st->total_brate); + } + } + ELSE + { + st->hFdCngEnc = NULL; + } + + /*-----------------------------------------------------------------* + * Transient detector + *-----------------------------------------------------------------*/ + + IF ((st->hTranDet = (TRAN_DET_HANDLE)malloc(sizeof(TRAN_DET_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n")); + } + Word16 temp; + Word16 frame_length = BASOP_Util_Divide3232_Scale(st->input_Fs, FRAMES_PER_SEC, &temp); + frame_length = shr(frame_length, sub(15, temp)); + + IF (GT_16(st->element_mode, EVS_MONO)) + { + InitTransientDetection_ivas_fx(frame_length, 0, st->hTranDet, 1); + } + ELSE + { + InitTransientDetection_ivas_fx(frame_length, NS2SA(st->input_Fs, DELAY_FIR_RESAMPL_NS), st->hTranDet, 0); + } + + /*-----------------------------------------------------------------* + * IVAS parameters + *-----------------------------------------------------------------*/ + + st->tdm_LRTD_flag = 0; + st->cng_sba_flag = 0; + st->bits_frame_channel = 0; + st->side_bits_frame_channel = 0; + + return error; +} +#endif /*-----------------------------------------------------------------------* * LPDmem_enc_init() * @@ -926,4 +1763,4 @@ void destroy_cldfb_encoder( deleteFdCngEnc( &st->hFdCngEnc ); return; -} +} \ No newline at end of file diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 4c5df31f3edae6c8cd538a24051f08da4422891f..4a6116d772c0dc43e59c15d7f8410498dd3eab8f 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -39,9 +39,9 @@ ISM_MODE ism_mode = ISM_MODE_NONE; /*-----------------------------------------------------------------* * General signal buffers *-----------------------------------------------------------------*/ - if (!vad_only_flag) + IF (!vad_only_flag) { - if ((st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE)count_malloc(sizeof(SIGNAL_BUFFERS_ENC_DATA))) == NULL) + IF ((st_fx->hSignalBuf = (SIGNAL_BUFFERS_ENC_HANDLE)count_malloc(sizeof(SIGNAL_BUFFERS_ENC_DATA))) == NULL) { return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Signal buffers\n")); } @@ -76,7 +76,7 @@ ISM_MODE ism_mode = ISM_MODE_NONE; st_fx->input_fx = st_fx->input_buff_fx + st_fx->input_Fs / FRAMES_PER_SEC; } } - else + ELSE { st_fx->hSignalBuf = NULL; st_fx->Bin_E_old_fx = NULL; @@ -96,7 +96,8 @@ ISM_MODE ism_mode = ISM_MODE_NONE; *-----------------------------------------------------------------*/ st_fx->last_core = -1; move16(); - if ( st_fx->Opt_AMR_WB ) + + IF ( st_fx->Opt_AMR_WB ) { st_fx->last_core = AMR_WB_CORE; move16(); diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index e4cd66d9512d746568d2f2cadfeacae77fe58103..0bf9255844d77cb29c4b2bed00362ed2a221e547 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -54,14 +54,14 @@ *-----------------------------------------------------------------------------------------*/ /*! r: AGC enable flag */ -int16_t ivas_agc_enc_get_flag( - const int16_t nchan_transport /* i : number of transport channels */ +Word16 ivas_agc_enc_get_flag( + const Word16 nchan_transport /* i : number of transport channels */ ) { - int16_t agc_flag; + Word16 agc_flag; /* AGC is enabled only if there is one transport channel. */ - agc_flag = (int16_t) ( nchan_transport == 1 ); + agc_flag = (Word16) ( EQ_16(nchan_transport, 1 )); return agc_flag; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index f15d9eb7854cf8134aba9152f39f51f9fdadf03e..b6fb7a18ecacc31353f06c80c6dde2e6bc4a7723 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -38,6 +38,7 @@ #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" +#include "prot_fx_enc.h" #include "ivas_rom_com.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED @@ -970,8 +971,264 @@ ivas_error create_cpe_enc( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error create_cpe_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + const Word32 element_brate /* i : element bitrate */ +) +{ + Word16 n; + Word16 ivas_format, element_mode_init, max_bwidth; + Word32 input_Fs; + CPE_ENC_HANDLE hCPE; + Encoder_State *st; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + error = IVAS_ERR_OK; + + hEncoderConfig = st_ivas->hEncoderConfig; + + ivas_format = hEncoderConfig->ivas_format; + element_mode_init = hEncoderConfig->element_mode_init; + input_Fs = hEncoderConfig->input_Fs; + max_bwidth = hEncoderConfig->max_bwidth; + + /*-----------------------------------------------------------------* + * Allocate CPE handle + *-----------------------------------------------------------------*/ + + IF ((hCPE = (CPE_ENC_HANDLE)malloc(sizeof(CPE_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n")); + } + + /*-----------------------------------------------------------------* + * Initialization - general parameters + *-----------------------------------------------------------------*/ + + hCPE->cpe_id = cpe_id; + hCPE->element_brate = element_brate; + hCPE->last_element_brate = hCPE->element_brate; + hCPE->element_mode = element_mode_init; + hCPE->last_element_mode = element_mode_init; + + hCPE->hStereoDft = NULL; + hCPE->hStereoTD = NULL; + hCPE->hStereoMdct = NULL; + hCPE->hStereoTCA = NULL; + hCPE->hStereoICBWE = NULL; + hCPE->hMetaData = NULL; + + hCPE->hStereoCng = NULL; + hCPE->hFrontVad[0] = NULL; + hCPE->hFrontVad[1] = NULL; + + hCPE->brate_surplus = 0; + + /*-----------------------------------------------------------------* + * Input memory buffer: allocate and initialize + *-----------------------------------------------------------------*/ + + FOR (n = 0; n < CPE_CHANNELS; n++) + { + IF (EQ_16(ivas_format, STEREO_FORMAT) || EQ_16(ivas_format, MASA_FORMAT) || (EQ_16(ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCMASA)) || EQ_16(ivas_format, MASA_ISM_FORMAT)) + { + IF((hCPE->input_mem_fx[n] = (Word32 *)malloc(sizeof(Word32) * NS2SA(input_Fs, STEREO_DFT_OVL_NS))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n")); + } + + set_zero_fx(hCPE->input_mem_fx[n], NS2SA(input_Fs, STEREO_DFT_OVL_NS)); + } + ELSE + { + hCPE->input_mem[n] = NULL; + hCPE->input_mem_fx[n] = NULL; + } + } + + /*-----------------------------------------------------------------* + * stereo classifier: allocate and initialize + *-----------------------------------------------------------------*/ + + IF ((hCPE->hStereoClassif = (STEREO_CLASSIF_HANDLE)malloc(sizeof(STEREO_CLASSIF_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n")); + } + + stereo_classifier_init_fx(hCPE->hStereoClassif); + + /*-----------------------------------------------------------------* + * Metadata: allocate and initialize + *-----------------------------------------------------------------*/ + + IF (EQ_16( cpe_id, sub(st_ivas->nCPE, 1))) + { + IF ((error = ivas_initialize_MD_bstr_enc(&(hCPE->hMetaData), st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CoreCoder, 2 instances: allocate and initialize + *-----------------------------------------------------------------*/ + + FOR (n = 0; n < CPE_CHANNELS; n++) + { + IF ((st = (ENC_CORE_HANDLE)malloc(sizeof(Encoder_State))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n")); + } + + copy_encoder_config_fx(st_ivas, st, 1); + IF(GT_16(st_ivas->nCPE, 1)) + { + st->total_brate = hCPE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + ELSE + { + st->total_brate = L_shr(hCPE->element_brate, CPE_CHANNELS); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + + IF ((error = init_encoder_ivas_fx(st, st_ivas, n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, ISM_MODE_NONE, hCPE->element_brate)) != IVAS_ERR_OK) + { + return error; + } + + IF (st->hFdCngEnc != NULL) + { + st->hFdCngEnc->hFdCngCom->CngBitrate = sub(hCPE->element_brate, 1); + } + hCPE->hCoreCoder[n] = st; + } + + /*-----------------------------------------------------------------* + * LR VAD initialization + *-----------------------------------------------------------------*/ + + IF (hEncoderConfig->Opt_DTX_ON) + { + IF (EQ_16(hCPE->element_mode, IVAS_CPE_TD) || EQ_16(hCPE->element_mode, IVAS_CPE_DFT)) + { + IF ((hCPE->hStereoCng = (STEREO_CNG_ENC_HANDLE)malloc(sizeof(STEREO_CNG_ENC))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo Cng for Unified/TD \n")); + } + + stereo_enc_cng_init(hCPE->hStereoCng); + } + } + ELSE + { + hCPE->hStereoCng = NULL; + } + + IF (hEncoderConfig->Opt_DTX_ON && EQ_16(element_mode_init, IVAS_CPE_MDCT)) + { + FOR (n = 0; n < CPE_CHANNELS; n++) + { + IF ((error = front_vad_create_fx(&(hCPE->hFrontVad[n]), hEncoderConfig)) != IVAS_ERR_OK) + { + return error; + } + } + } + ELSE + { + FOR (n = 0; n < CPE_CHANNELS; n++) + { + hCPE->hFrontVad[n] = NULL; + } + } + + /*-----------------------------------------------------------------* + * DFT stereo initialization + *-----------------------------------------------------------------*/ + + IF (EQ_16(hCPE->element_mode, IVAS_CPE_DFT)) + { + IF ((error = stereo_dft_enc_create_fx(&(hCPE->hStereoDft), input_Fs, max_bwidth)) != IVAS_ERR_OK) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * Temporal inter-channel alignment initialization + *-----------------------------------------------------------------*/ + + IF (NE_16(hCPE->element_mode, IVAS_CPE_MDCT)) + { + IF ((hCPE->hStereoTCA = (STEREO_TCA_ENC_HANDLE)malloc(sizeof(STEREO_TCA_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n")); + } + + stereo_tca_init_enc_fx(hCPE->hStereoTCA, input_Fs); + } + + /*-----------------------------------------------------------------* + * Stereo IC BWE initialization + *-----------------------------------------------------------------*/ + + IF (NE_16(hCPE->element_mode, IVAS_CPE_MDCT)) + { + IF ((hCPE->hStereoICBWE = (STEREO_ICBWE_ENC_HANDLE)malloc(sizeof(STEREO_ICBWE_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n")); + } + + stereo_icBWE_init_enc_fx(hCPE->hStereoICBWE); + } + + /*-----------------------------------------------------------------* + * TD stereo initialization + *-----------------------------------------------------------------*/ + + IF (hCPE->element_mode == IVAS_CPE_TD) + { + IF ((hCPE->hStereoTD = (STEREO_TD_ENC_DATA_HANDLE)malloc(sizeof(STEREO_TD_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n")); + } + + stereo_td_init_enc_fx(hCPE->hStereoTD, hCPE->last_element_mode); + } + + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ + + IF (EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) && EQ_16(st_ivas->nCPE, 1)) + { + IF ((hCPE->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE)malloc(sizeof(STEREO_MDCT_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n")); + } + + initMdctStereoEncData_fx(hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1); + hCPE->hStereoMdct->isSBAStereoMode = ((EQ_16(ivas_format, SBA_FORMAT) || EQ_16(ivas_format, SBA_ISM_FORMAT)) && EQ_16(st_ivas->nchan_transport, 2)); + + IF (EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) && LE_32(element_brate, MAX_MDCT_ITD_BRATE) && EQ_16(ivas_format, STEREO_FORMAT)) + { + IF ((error = initMdctItdHandling_fx(hCPE->hStereoMdct, input_Fs)) != IVAS_ERR_OK) + { + return error; + } + } + } + + st_ivas->hCPE[cpe_id] = hCPE; + + return error; +} +#endif /*------------------------------------------------------------------------- * destroy_cpe_enc() * @@ -982,18 +1239,18 @@ void destroy_cpe_enc( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ) { - int16_t n; + Word16 n; Encoder_State *st; - if ( hCPE->hStereoClassif != NULL ) + IF ( hCPE->hStereoClassif != NULL ) { free( hCPE->hStereoClassif ); hCPE->hStereoClassif = NULL; } - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { - if ( hCPE->input_mem[n] != NULL ) + IF ( hCPE->input_mem[n] != NULL ) { free( hCPE->input_mem[n] ); hCPE->input_mem[n] = NULL; @@ -1002,56 +1259,56 @@ void destroy_cpe_enc( ivas_destroy_MD_bstr_enc( &( hCPE->hMetaData ) ); - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { st = hCPE->hCoreCoder[n]; - if ( st != NULL ) + IF ( st != NULL ) { destroy_core_enc( st ); st = NULL; } } - if ( hCPE->hStereoDft != NULL ) + IF ( hCPE->hStereoDft != NULL ) { stereo_dft_enc_destroy( &hCPE->hStereoDft ); hCPE->hStereoDft = NULL; } - if ( hCPE->hStereoTD != NULL ) + IF ( hCPE->hStereoTD != NULL ) { free( hCPE->hStereoTD ); hCPE->hStereoTD = NULL; } - if ( hCPE->hStereoMdct != NULL ) + IF ( hCPE->hStereoMdct != NULL ) { stereo_mdct_enc_destroy( &hCPE->hStereoMdct ); hCPE->hStereoMdct = NULL; } - if ( hCPE->hStereoTCA != NULL ) + IF ( hCPE->hStereoTCA != NULL ) { free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; } - if ( hCPE->hStereoICBWE != NULL ) + IF ( hCPE->hStereoICBWE != NULL ) { free( hCPE->hStereoICBWE ); hCPE->hStereoICBWE = NULL; } - if ( hCPE->hStereoCng != NULL ) + IF ( hCPE->hStereoCng != NULL ) { free( hCPE->hStereoCng ); hCPE->hStereoCng = NULL; } - if ( hCPE->hFrontVad[0] != NULL ) + IF ( hCPE->hFrontVad[0] != NULL ) { - for ( n = 0; n < CPE_CHANNELS; n++ ) + FOR ( n = 0; n < CPE_CHANNELS; n++ ) { front_vad_destroy( &hCPE->hFrontVad[n] ); hCPE->hFrontVad[n] = NULL; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 1ae255b607caf7b9cf657c3659bef82b21157213..7e0b163f05189feb07e9c1daca3ef787d4465ef2 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -38,6 +38,8 @@ #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" +#include "prot_fx_enc.h" +#include "prot_fx1.h" #include #include "wmc_auto.h" #include @@ -294,7 +296,56 @@ ivas_error front_vad_create( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error front_vad_create_fx( + FRONT_VAD_ENC_HANDLE *hFrontVad_out, /* i/o: front-VAD handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +) +{ + FRONT_VAD_ENC_HANDLE hFrontVad; + + IF ((hFrontVad = (FRONT_VAD_ENC_HANDLE)malloc(sizeof(FRONT_VAD_ENC))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for front-VAD structure \n")); + } + + IF ((hFrontVad->hNoiseEst = (NOISE_EST_HANDLE)malloc(sizeof(NOISE_EST_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Noise estimation\n")); + } + noise_est_init_fx(hFrontVad->hNoiseEst); + + IF ((hFrontVad->hVAD = (VAD_HANDLE)malloc(sizeof(VAD_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD\n")); + } + wb_vad_init_ivas_fx(hFrontVad->hVAD); + + hFrontVad->lp_speech_fx = 23040; /* Initialize the long-term active speech level in dB */ + hFrontVad->lp_noise_fx = 0; /* Initialize the long-term noise level in dB */ + set32_fx(hFrontVad->mem_decim_fx, 0, shl(L_FILT_MAX, 1)); + set32_fx(hFrontVad->buffer_12k8_fx, 0, i_mult(3, shr(L_FRAME, 1))); + hFrontVad->mem_preemph_fx = 0; + hFrontVad->ini_frame = 0; + hFrontVad->hVAD->vad_flag = 1; + + /* allocate delay buffer to compensate for filterbank delay */ + hFrontVad->delay_samples = NS2SA(hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS); + hFrontVad->delay_buf_fx = NULL; + IF (GT_16(hFrontVad->delay_samples, 0)) + { + IF ((hFrontVad->delay_buf_fx = (Word16 *)malloc(hFrontVad->delay_samples * sizeof(Word16))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for VAD delay buffer\n")); + } + set16_fx(hFrontVad->delay_buf_fx, 0, hFrontVad->delay_samples); + } + + *hFrontVad_out = hFrontVad; + return IVAS_ERR_OK; +} +#endif /*-----------------------------------------------------------------------------------------* * Function front_vad_destroy() @@ -306,7 +357,7 @@ void front_vad_destroy( FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ ) { - if ( *hFrontVad != NULL ) + IF ( *hFrontVad != NULL ) { free( ( *hFrontVad )->hNoiseEst ); ( *hFrontVad )->hNoiseEst = NULL; @@ -314,7 +365,7 @@ void front_vad_destroy( free( ( *hFrontVad )->hVAD ); ( *hFrontVad )->hVAD = NULL; - if ( ( *hFrontVad )->delay_buf != NULL ) + IF ( ( *hFrontVad )->delay_buf != NULL ) { free( ( *hFrontVad )->delay_buf ); ( *hFrontVad )->delay_buf = NULL; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1623fc44ae16a6523ac27d0c981e5b1b34297941..999679228df21b3cf2cd0e24c164fe5c8e6c92a6 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -279,10 +279,10 @@ void copy_encoder_config( void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st_fx, /* o : encoder state structure */ - const int16_t flag_all /* i : flag 1==update all, 0=partial update*/ + const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ ) { - if ( flag_all ) + IF ( flag_all ) { st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; @@ -319,14 +319,14 @@ void ivas_initialize_handles_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { - int16_t i; + Word16 i; - for ( i = 0; i < MAX_SCE; i++ ) + FOR ( i = 0; i < MAX_SCE; i++ ) { st_ivas->hSCE[i] = NULL; } - for ( i = 0; i < MAX_CPE; i++ ) + FOR ( i = 0; i < MAX_CPE; i++ ) { st_ivas->hCPE[i] = NULL; } @@ -334,7 +334,7 @@ void ivas_initialize_handles_enc( st_ivas->mem_hp20_in = NULL; /* ISM metadata handles */ - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR ( i = 0; i < MAX_NUM_OBJECTS; i++ ) { st_ivas->hIsmMetaData[i] = NULL; } @@ -945,8 +945,559 @@ ivas_error ivas_init_encoder( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_init_encoder_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 i, n; + Word16 nchan_inp_buff; + Word16 sce_id, cpe_id; + IVAS_FORMAT ivas_format; + Word32 input_Fs, ivas_total_brate; + Word32 element_brate_tmp[MAX_NUM_OBJECTS]; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + error = IVAS_ERR_OK; + + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_format = hEncoderConfig->ivas_format; + input_Fs = hEncoderConfig->input_Fs; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + + IF (NE_16(ivas_format, MONO_FORMAT)) + { + /* In IVAS, ensure that minimum coded bandwidth is WB */ + hEncoderConfig->max_bwidth = L_max(hEncoderConfig->max_bwidth, WB); + } + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->mc_mode = MC_MODE_NONE; + + st_ivas->nchan_transport = -1; + + /*-----------------------------------------------------------------* + * Allocate floating-point input audio buffers + *-----------------------------------------------------------------*/ + + nchan_inp_buff = hEncoderConfig->nchan_inp; + IF (EQ_16(ivas_format, MONO_FORMAT)) + { + nchan_inp_buff = 0; + } + ELSE IF (EQ_16(ivas_format, MASA_ISM_FORMAT)) + { + IF (EQ_16(sub(hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism), 1)) /* mono is duplicated in monoMASA */ + { + nchan_inp_buff++; + } + + nchan_inp_buff++; /* for *data_separated_object */ + } + + FOR (n = 0; n < nchan_inp_buff; n++) + { + /* note: these are intra-frame heap memories */ + IF ((st_ivas->p_data_f[n] = (float *)malloc((input_Fs / FRAMES_PER_SEC) * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n")); + } + } + FOR (; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++) + { + st_ivas->p_data_f[n] = NULL; + } + + /*-----------------------------------------------------------------* + * Allocate and initialize buffer of indices + *-----------------------------------------------------------------*/ + + /* set the maximum allowed number of indices in the list */ + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx(ivas_format, ivas_total_brate); + + /* allocate buffer of indices */ + IF ((st_ivas->ind_list = (INDICE_HANDLE)malloc(st_ivas->ivas_max_num_indices * sizeof(Indice))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n")); + } + + /* reset the list of indices */ + FOR (i = 0; i < st_ivas->ivas_max_num_indices; i++) + { + st_ivas->ind_list[i].nb_bits = -1; + } + + /* set the maximum allowed number of metadata indices in the list */ + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx(st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate); + + /* allocate buffer of metadata indices */ + IF (st_ivas->ivas_max_num_indices_metadata > 0) + { + IF ((st_ivas->ind_list_metadata = (INDICE_HANDLE)malloc(st_ivas->ivas_max_num_indices_metadata * sizeof(Indice))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n")); + } + + /* reset the list of metadata indices */ + FOR (i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++) + { + st_ivas->ind_list_metadata[i].nb_bits = -1; + } + } + ELSE + { + st_ivas->ind_list_metadata = NULL; + } + + /*-----------------------------------------------------------------* + * Allocate and initialize SCE/CPE and other handles + *-----------------------------------------------------------------*/ + + IF (EQ_16(ivas_format, MONO_FORMAT)) + { + st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ + st_ivas->nCPE = 0; + st_ivas->nchan_transport = 1; + sce_id = 0; + IF ((error = create_sce_enc_fx(st_ivas, sce_id, ivas_total_brate)) != IVAS_ERR_OK) + { + return error; + } +#ifndef EVS_FLOAT_ENC + if ((error = create_evs_sce_enc(st_ivas, sce_id)) != IVAS_ERR_OK) + { + return error; + } +#endif + + /* prepare stereo downmix for EVS */ + IF (hEncoderConfig->stereo_dmx_evs == 1) + { + IF ((error = stereo_dmx_evs_init_encoder(&(st_ivas->hStereoDmxEVS), input_Fs)) != IVAS_ERR_OK) + { + return error; + } + } + } + ELSE IF (ivas_format == STEREO_FORMAT) + { + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ + st_ivas->nchan_transport = CPE_CHANNELS; + cpe_id = 0; + + IF ((error = create_cpe_enc(st_ivas, cpe_id, ivas_total_brate)) != IVAS_ERR_OK) + { + return error; + } + } + ELSE IF (ivas_format == ISM_FORMAT) + { + st_ivas->ism_mode = ivas_ism_mode_select(hEncoderConfig->nchan_inp, ivas_total_brate); + + IF ((error = ivas_ism_metadata_enc_create(st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp)) != IVAS_ERR_OK) + { + return error; + } + + FOR (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + { + IF ((error = create_sce_enc_fx(st_ivas, sce_id, element_brate_tmp[sce_id])) != IVAS_ERR_OK) + { + return error; + } + } + + IF (st_ivas->ism_mode == ISM_MODE_PARAM) + { + IF ((error = ivas_param_ism_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + + IF (st_ivas->hEncoderConfig->Opt_DTX_ON) + { + IF ((error = ivas_ism_dtx_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + } + ELSE IF (ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT) + { + IF ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) + { + return error; + } + + IF (ivas_format == SBA_FORMAT) + { + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order(ivas_total_brate, st_ivas->hEncoderConfig->sba_order); + + IF ((error = ivas_spar_enc_open_fx(st_ivas, 0)) != IVAS_ERR_OK) + { + return error; + } + + IF ((error = ivas_dirac_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + ELSE + { + st_ivas->nchan_transport = hEncoderConfig->nchan_inp; + + IF ((error = ivas_masa_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + + FOR (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + { + IF ((error = create_sce_enc_fx(st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport)) != IVAS_ERR_OK) + { + return error; + } + + IF (EQ_16(ivas_format, SBA_FORMAT) && st_ivas->hEncoderConfig->Opt_DTX_ON) + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + } + } + + FOR (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + IF ((error = create_cpe_enc_fx(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) + { + return error; + } + + FOR (n = 0; n < CPE_CHANNELS; n++) + { + IF (hEncoderConfig->Opt_DTX_ON) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + } + + if (st_ivas->nCPE > 1) + { + if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + } + else if (ivas_format == MASA_ISM_FORMAT) + { + int32_t ism_total_brate; + int16_t k; + + st_ivas->ism_mode = ivas_omasa_ism_mode_select(ivas_total_brate, hEncoderConfig->nchan_ism); + st_ivas->nchan_transport = 2; + + if ((error = ivas_ism_metadata_enc_create(st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp)) != IVAS_ERR_OK) + { + return error; + } + + k = 0; + while (k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k]) + { + k++; + } + + ism_total_brate = 0; + for (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + { + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + if ((error = create_sce_enc_fx(st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1])) != IVAS_ERR_OK) + { + return error; + } + } + + if ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) + { + return error; + } + if ((error = ivas_masa_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + if (st_ivas->ism_mode != ISM_MASA_MODE_DISC) + { + if ((error = ivas_omasa_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + + if (ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + else + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + if ((error = create_cpe_enc(st_ivas, 0, ivas_total_brate - ism_total_brate)) != IVAS_ERR_OK) + { + return error; + } + } + else if (ivas_format == SBA_ISM_FORMAT) + { + st_ivas->ism_mode = ISM_MODE_NONE; + + if (ivas_total_brate >= IVAS_256k) + { + st_ivas->ism_mode = ISM_SBA_MODE_DISC; + } + + if ((error = ivas_ism_metadata_enc_create(st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp)) != IVAS_ERR_OK) + { + return error; + } + + /* allocate and initialize SBA handles */ + if ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) + { + return error; + } + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order(ivas_total_brate, st_ivas->hEncoderConfig->sba_order); + + if ((error = ivas_spar_enc_open_fx(st_ivas, 0)) != IVAS_ERR_OK) + { + return error; + } + + if ((error = ivas_dirac_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + if (st_ivas->ism_mode == ISM_MODE_NONE) + { + /* allocate and initialize SBA core-coders */ + if (st_ivas->nchan_transport == 1) + { + if ((error = create_sce_enc_fx(st_ivas, 0, ivas_total_brate)) != IVAS_ERR_OK) + { + return error; + } + } + for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) + { + return error; + } + } + + if (st_ivas->nCPE > 1) + { + if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + } + else + { + /* allocate and initialize MCT core coder */ + st_ivas->nCPE += (st_ivas->hEncoderConfig->nchan_ism + 1) >> 1; + + for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nchan_transport) * CPE_CHANNELS)) != IVAS_ERR_OK) + { + return error; + } + } + + if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + + if ((error = ivas_osba_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + else if (ivas_format == MC_FORMAT) + { + st_ivas->mc_mode = ivas_mc_mode_select(hEncoderConfig->mc_input_setup, ivas_total_brate); + + if ((error = ivas_create_lfe_lpf_enc(&st_ivas->hLfeLpf, hEncoderConfig->input_Fs)) != IVAS_ERR_OK) + { + return error; + } + + if (st_ivas->mc_mode == MC_MODE_MCT) + { + st_ivas->nSCE = 0; + st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; + + for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / (hEncoderConfig->nchan_inp - 1) * CPE_CHANNELS))) != IVAS_ERR_OK) + { + return error; + } + } + + if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + if ((error = ivas_create_lfe_enc(&st_ivas->hLFE, input_Fs)) != IVAS_ERR_OK) + { + return error; + } + + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels(st_ivas->hEncoderConfig->mc_input_setup); + } + else if (st_ivas->mc_mode == MC_MODE_PARAMUPMIX) + { + st_ivas->nSCE = 0; + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + + if ((error = ivas_mc_paramupmix_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + if ((error = create_cpe_enc(st_ivas, cpe_id, (ivas_total_brate / st_ivas->nCPE))) != IVAS_ERR_OK) + { + return error; + } + } + + if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + if ((error = ivas_create_lfe_enc(&st_ivas->hLFE, input_Fs)) != IVAS_ERR_OK) + { + return error; + } + } + else if (st_ivas->mc_mode == MC_MODE_PARAMMC) + { + if ((error = ivas_param_mc_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + if ((error = create_cpe_enc(st_ivas, cpe_id, ivas_total_brate / (st_ivas->nCPE + st_ivas->nSCE))) != IVAS_ERR_OK) + { + return error; + } + } + + if (st_ivas->nCPE > 1) + { + if ((error = create_mct_enc(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + } + } + else if (st_ivas->mc_mode == MC_MODE_MCMASA) + { + int32_t brate_sce, brate_cpe; + + ivas_mcmasa_setNumTransportChannels(&(st_ivas->nchan_transport), &(hEncoderConfig->element_mode_init), ivas_total_brate); + + if ((error = ivas_qmetadata_open(&(st_ivas->hQMetaData))) != IVAS_ERR_OK) + { + return error; + } + + if ((error = ivas_masa_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + if ((error = ivas_mcmasa_enc_open(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + ivas_mcmasa_split_brate(st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe); + + for (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + { + if ((error = create_sce_enc_fx(st_ivas, sce_id, brate_sce)) != IVAS_ERR_OK) + { + return error; + } + } + + for (cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + + if ((error = create_cpe_enc(st_ivas, cpe_id, brate_cpe)) != IVAS_ERR_OK) + { + return error; + } + } + } + } + + /*-----------------------------------------------------------------* + * Allocate and initialize HP20 filter memories + *-----------------------------------------------------------------*/ + + /* set number of input channels used for analysis/coding */ + n = getNumChanAnalysis(st_ivas); + + if (n > 0) + { + if ((st_ivas->mem_hp20_in = (float **)malloc(n * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + } + } + else + { + st_ivas->mem_hp20_in = NULL; + } + + for (i = 0; i < n; i++) + { + if ((st_ivas->mem_hp20_in[i] = (float *)malloc(L_HP20_MEM * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + } + + set_f(st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM); + } + + return error; +} +#endif /*------------------------------------------------------------------------- * destroy_core_enc() * @@ -957,20 +1508,20 @@ void destroy_core_enc( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ) { - int16_t i; + Word16 i; destroy_cldfb_encoder( hCoreCoder ); - if ( hCoreCoder->hSignalBuf != NULL ) + IF ( hCoreCoder->hSignalBuf != NULL ) { free( hCoreCoder->hSignalBuf ); hCoreCoder->hSignalBuf = NULL; } - if ( hCoreCoder->hBstr != NULL ) + IF ( hCoreCoder->hBstr != NULL ) { /* reset buffer of indices */ - for ( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) + FOR ( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ ) { hCoreCoder->hBstr->ind_list[i].nb_bits = -1; } @@ -978,121 +1529,121 @@ void destroy_core_enc( hCoreCoder->hBstr = NULL; } - if ( hCoreCoder->hLPDmem != NULL ) + IF ( hCoreCoder->hLPDmem != NULL ) { free( hCoreCoder->hLPDmem ); hCoreCoder->hLPDmem = NULL; } - if ( hCoreCoder->hTranDet != NULL ) + IF ( hCoreCoder->hTranDet != NULL ) { free( hCoreCoder->hTranDet ); hCoreCoder->hTranDet = NULL; } - if ( hCoreCoder->hNoiseEst != NULL ) + IF ( hCoreCoder->hNoiseEst != NULL ) { free( hCoreCoder->hNoiseEst ); hCoreCoder->hNoiseEst = NULL; } - if ( hCoreCoder->hVAD != NULL ) + IF ( hCoreCoder->hVAD != NULL ) { free( hCoreCoder->hVAD ); hCoreCoder->hVAD = NULL; } - if ( hCoreCoder->hVAD_CLDFB != NULL ) + IF ( hCoreCoder->hVAD_CLDFB != NULL ) { free( hCoreCoder->hVAD_CLDFB ); hCoreCoder->hVAD_CLDFB = NULL; } - if ( hCoreCoder->hTdCngEnc != NULL ) + IF ( hCoreCoder->hTdCngEnc != NULL ) { free( hCoreCoder->hTdCngEnc ); hCoreCoder->hTdCngEnc = NULL; } - if ( hCoreCoder->hDtxEnc != NULL ) + IF ( hCoreCoder->hDtxEnc != NULL ) { free( hCoreCoder->hDtxEnc ); hCoreCoder->hDtxEnc = NULL; } - if ( hCoreCoder->hSpMusClas != NULL ) + IF ( hCoreCoder->hSpMusClas != NULL ) { free( hCoreCoder->hSpMusClas ); hCoreCoder->hSpMusClas = NULL; } - if ( hCoreCoder->hGSCEnc != NULL ) + IF ( hCoreCoder->hGSCEnc != NULL ) { free( hCoreCoder->hGSCEnc ); hCoreCoder->hGSCEnc = NULL; } - if ( hCoreCoder->hSC_VBR != NULL ) + IF ( hCoreCoder->hSC_VBR != NULL ) { free( hCoreCoder->hSC_VBR ); hCoreCoder->hSC_VBR = NULL; } - if ( hCoreCoder->hAmrwb_IO != NULL ) + IF ( hCoreCoder->hAmrwb_IO != NULL ) { free( hCoreCoder->hAmrwb_IO ); hCoreCoder->hAmrwb_IO = NULL; } - if ( hCoreCoder->hBWE_TD != NULL ) + IF ( hCoreCoder->hBWE_TD != NULL ) { free( hCoreCoder->hBWE_TD ); hCoreCoder->hBWE_TD = NULL; } - if ( hCoreCoder->hBWE_FD != NULL ) + IF ( hCoreCoder->hBWE_FD != NULL ) { free( hCoreCoder->hBWE_FD ); hCoreCoder->hBWE_FD = NULL; } - if ( hCoreCoder->hRF != NULL ) + IF ( hCoreCoder->hRF != NULL ) { free( hCoreCoder->hRF ); hCoreCoder->hRF = NULL; } - if ( hCoreCoder->hTECEnc != NULL ) + IF ( hCoreCoder->hTECEnc != NULL ) { free( hCoreCoder->hTECEnc ); hCoreCoder->hTECEnc = NULL; } - if ( hCoreCoder->hTcxEnc != NULL ) + IF ( hCoreCoder->hTcxEnc != NULL ) { free( hCoreCoder->hTcxEnc ); hCoreCoder->hTcxEnc = NULL; } - if ( hCoreCoder->hTcxCfg != NULL ) + IF ( hCoreCoder->hTcxCfg != NULL ) { free( hCoreCoder->hTcxCfg ); hCoreCoder->hTcxCfg = NULL; } - if ( hCoreCoder->hIGFEnc != NULL ) + IF ( hCoreCoder->hIGFEnc != NULL ) { free( hCoreCoder->hIGFEnc ); hCoreCoder->hIGFEnc = NULL; } - if ( hCoreCoder->hPlcExt != NULL ) + IF ( hCoreCoder->hPlcExt != NULL ) { free( hCoreCoder->hPlcExt ); hCoreCoder->hPlcExt = NULL; } - if ( hCoreCoder->hHQ_core != NULL ) + IF ( hCoreCoder->hHQ_core != NULL ) { free( hCoreCoder->hHQ_core ); hCoreCoder->hHQ_core = NULL; @@ -1103,7 +1654,6 @@ void destroy_core_enc( return; } - /*------------------------------------------------------------------------- * ivas_destroy_enc() * @@ -1250,7 +1800,7 @@ ivas_error ivas_initialize_MD_bstr_enc( { BSTR_ENC_HANDLE hMetaData; - if ( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + IF ( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); } @@ -1279,7 +1829,7 @@ void ivas_destroy_MD_bstr_enc( BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */ ) { - if ( hMetaData == NULL || *hMetaData == NULL ) + IF ( hMetaData == NULL || *hMetaData == NULL ) { return; } diff --git a/lib_enc/ivas_rom_enc.c b/lib_enc/ivas_rom_enc.c index 27c95d52e626ef0f8219345d37dd2c394a56ce72..565093d56a90a260295414ee36aa78ce7a0d0206 100644 --- a/lib_enc/ivas_rom_enc.c +++ b/lib_enc/ivas_rom_enc.c @@ -268,6 +268,101 @@ const float win_ana_48k[STEREO_DFT_OVL_MAX] = { 0.9993626f, 0.9994536f, 0.9995375f, 0.9996144f, 0.9996844f, 0.9997473f, 0.9998033f, 0.9998523f, 0.9998942f, 0.9999292f, 0.9999572f, 0.9999781f, 0.9999921f, 0.9999991f }; +const Word32 win_ana_8k_fx[STEREO_DFT_OVL_8k] = { + 227468560, 393953952, 508506944, 601521984, 681832704, 753477952, 818704064, 878911808, 935043776, 987769024, 1037582080, 1084861312, 1129901952, 1172940800, + 1214170112, 1253748608, 1291809152, 1328463616, 1363808000, 1397923968, 1430883328, 1462748160, 1493572736, 1523405312, 1552288384, 1580259968, 1607353984, + 1633600512, 1659026944, 1683658112, 1707516160, 1730621440, 1752992000, 1774644864, 1795595264, 1815857024, 1835442688, 1854364416, 1872632832, 1890257664, + 1907248128, 1923612288, 1939358336, 1954493184, 1969022976, 1982954624, 1996292864, 2009043584, 2021211008, 2032799616, 2043813632, 2054256640, 2064132352, + 2073443840, 2082193664, 2090384896, 2098019840, 2105100672, 2111629440, 2117608320, 2123038464, 2127921536, 2132258816, 2136051456, 2139300608, 2142006912, + 2144171136, 2145793792, 2146875264, 2147416064 +}; + +const Word32 win_ana_12k8_fx[STEREO_DFT_OVL_12k8] = { + 179830704, 311465888, 402074208, 475693824, 539315392, 596138048, 647942656, 695842240, 740586368, 782707968, 822602432, 860572480, 896855296, 931641344, 965086016, + 997318016, 1028445376, 1058559552, 1087739136, 1116051968, 1143556992, 1170305792, 1196344064, 1221712512, 1246446976, 1270579968, 1294140160, 1317154176, + 1339645440, 1361635584, 1383144576, 1404190208, 1424788864, 1444955648, 1464704768, 1484048896, 1502999936, 1521569024, 1539766400, 1557601408, 1575083008, + 1592219776, 1609018880, 1625487744, 1641633152, 1657461376, 1672978432, 1688189696, 1703100800, 1717716352, 1732040960, 1746078976, 1759834880, 1773312384, + 1786515072, 1799446400, 1812109568, 1824508160, 1836644608, 1848522112, 1860142976, 1871509888, 1882625280, 1893491328, 1904110208, 1914484096, 1924614528, + 1934503680, 1944153216, 1953565056, 1962740096, 1971680768, 1980387712, 1988862720, 1997106944, 2005121792, 2012908160, 2020467456, 2027800576, 2034908288, + 2041792000, 2048452480, 2054890624, 2061106944, 2067102720, 2072878080, 2078434560, 2083771904, 2088891520, 2093793536, 2098478464, 2102947456, 2107200256, + 2111237504, 2115060096, 2118668032, 2122061952, 2125241984, 2128208512, 2130961920, 2133502464, 2135830272, 2137945984, 2139849344, 2141540736, 2143020288, + 2144288384, 2145344768, 2146189824, 2146823552, 2147246080, 2147457280 +}; + +const Word32 win_ana_16k_fx[STEREO_DFT_OVL_16k] = { + 160845664, 278587264, 359639520, 425504352, 482436064, 533297280, 579682048, 622587072, 662683200, 700448576, 736237504, 770321280, 802913024, 834183808, 864273280, + 893297152, 921352704, 948522688, 974877696, 1000478720, 1025379648, 1049626688, 1073261632, 1096321152, 1118837888, 1140841216, 1162357504, 1183411072, 1204023168, + 1224213888, 1244001152, 1263401344, 1282429952, 1301100672, 1319426432, 1337419136, 1355090048, 1372449024, 1389506048, 1406269824, 1422748544, 1438950016, + 1454881536, 1470549760, 1485961344, 1501122176, 1516037760, 1530713472, 1545154432, 1559365376, 1573350656, 1587114496, 1600660864, 1613993728, 1627116544, + 1640032896, 1652745728, 1665258496, 1677573632, 1689694208, 1701623040, 1713362304, 1724914688, 1736282240, 1747467392, 1758471936, 1769298048, 1779947776, + 1790422656, 1800724736, 1810855296, 1820816128, 1830608896, 1840235008, 1849695744, 1858992384, 1868126336, 1877098880, 1885911168, 1894564352, 1903059456, + 1911397504, 1919579520, 1927606400, 1935479296, 1943199104, 1950766208, 1958182144, 1965447040, 1972561920, 1979527424, 1986344576, 1993013632, 1999535616, + 2005910528, 2012139776, 2018223360, 2024162048, 2029956352, 2035606784, 2041113856, 2046477824, 2051699200, 2056778624, 2061716352, 2066513024, 2071168512, + 2075683584, 2080058624, 2084293760, 2088389248, 2092345728, 2096163072, 2099841920, 2103382272, 2106784512, 2110048896, 2113175680, 2116165120, 2119017216, + 2121732352, 2124310400, 2126751872, 2129056896, 2131225472, 2133258112, 2135154304, 2136914816, 2138539136, 2140028032, 2141381120, 2142598784, 2143680896, + 2144627456, 2145438848, 2146114816, 2146655616, 2147061248, 2147331584, 2147466624 +}; + +const Word32 win_ana_32k_fx[STEREO_DFT_OVL_32k] = { + 113735456, 196994480, 254315968, 300906048, 341188128, 377187904, 410033440, 440430432, 468854304, 495643936, 521050624, 545266688, 568444096, 590704256, 612146432, + 632853120, 652893888, 672327552, 691204736, 709569408, 727459456, 744909056, 761947584, 778601792, 794894912, 810848576, 826481856, 841811904, 856854784, 871624960, + 886135488, 900398464, 914424960, 928225344, 941809216, 955185280, 968361792, 981346368, 994146176, 1006767808, 1019217408, 1031501056, 1043623808, 1055591296, + 1067408256, 1079079168, 1090608384, 1101999872, 1113257856, 1124385664, 1135387008, 1146264960, 1157022720, 1167663488, 1178189824, 1188604672, 1198910464, + 1209109760, 1219204864, 1229197952, 1239091200, 1248886912, 1258586752, 1268192768, 1277706752, 1287130624, 1296465792, 1305713920, 1314876544, 1323955456, + 1332951680, 1341866752, 1350701952, 1359458688, 1368137984, 1376741504, 1385269760, 1393724160, 1402105856, 1410415872, 1418655232, 1426824704, 1434925184, + 1442957824, 1450923520, 1458823040, 1466657024, 1474426624, 1482132224, 1489774848, 1497355136, 1504873856, 1512331648, 1519729024, 1527066880, 1534345728, + 1541565952, 1548728704, 1555834112, 1562882816, 1569875200, 1576812160, 1583694080, 1590521344, 1597294464, 1604013952, 1610680320, 1617293952, 1623855360, + 1630365056, 1636823040, 1643229952, 1649586560, 1655892608, 1662148864, 1668355584, 1674513280, 1680621952, 1686682240, 1692694528, 1698658688, 1704575488, + 1710445184, 1716267904, 1722043904, 1727773824, 1733457664, 1739095552, 1744688128, 1750235264, 1755737472, 1761195136, 1766608256, 1771976960, 1777301888, + 1782582784, 1787820288, 1793014400, 1798165376, 1803273344, 1808338688, 1813361408, 1818341888, 1823280128, 1828176512, 1833031040, 1837843968, 1842615680, + 1847345920, 1852035200, 1856683392, 1861291136, 1865858176, 1870384640, 1874870912, 1879317120, 1883723008, 1888089344, 1892415872, 1896702848, 1900950400, + 1905158528, 1909327744, 1913457536, 1917548544, 1921600768, 1925614208, 1929589248, 1933525504, 1937423616, 1941283328, 1945105024, 1948888704, 1952634496, + 1956342144, 1960012416, 1963644928, 1967239808, 1970797056, 1974317184, 1977800064, 1981245696, 1984654080, 1988025728, 1991360256, 1994657920, 1997918720, + 2001142912, 2004330624, 2007481728, 2010596224, 2013674368, 2016716032, 2019721728, 2022691072, 2025624320, 2028521472, 2031382528, 2034207744, 2036996864, + 2039750400, 2042468096, 2045150080, 2047796352, 2050407296, 2052982400, 2055522176, 2058026368, 2060495360, 2062928896, 2065327104, 2067689984, 2070017920, + 2072310528, 2074567936, 2076790656, 2078978048, 2081130496, 2083248128, 2085330688, 2087378432, 2089391360, 2091369728, 2093312896, 2095221888, 2097095680, + 2098935296, 2100739968, 2102510208, 2104245760, 2105947008, 2107613696, 2109245824, 2110843520, 2112406912, 2113935872, 2115430528, 2116891008, 2118316928, + 2119708800, 2121066368, 2122389632, 2123678592, 2124933504, 2126154368, 2127340928, 2128493440, 2129611904, 2130696064, 2131746432, 2132762624, 2133744896, + 2134692992, 2135607168, 2136487296, 2137333504, 2138145792, 2138924160, 2139668480, 2140378880, 2141055616, 2141698304, 2142307200, 2142882048, 2143422976, + 2143930240, 2144403456, 2144843136, 2145248768, 2145620480, 2145958528, 2146262784, 2146533120, 2146769792, 2146972544, 2147141504, 2147276672, 2147378048, + 2147445632, 2147479296 +}; + +const Word32 win_ana_48k_fx[STEREO_DFT_OVL_MAX] = { + 92864496, 160845664, 207650080, 245693168, 278587264, 307986080, 334811584, 359639520, 382858336, 404744832, 425504352, 445294272, 464238496, 482436064, 499968544, + 516903392, 533297280, 549198336, 564648000, 579682048, 594332224, 608625856, 622587072, 636237760, 649597248, 662683200, 675511168, 688095232, 700448576, 712582976, + 724509248, 736237504, 747776576, 759135232, 770321280, 781341760, 792203520, 802913024, 813475840, 823897792, 834183808, 844338624, 854367104, 864273280, 874061056, + 883734592, 893297152, 902752320, 912103104, 921352704, 930504256, 939559936, 948522688, 957395008, 966179328, 974877696, 983492352, 992025344, 1000478720, + 1008854528, 1017154112, 1025379648, 1033532352, 1041614400, 1049626688, 1057571264, 1065449088, 1073261632, 1081010432, 1088696448, 1096321152, 1103885440, + 1111390592, 1118837888, 1126228096, 1133562112, 1140841216, 1148066176, 1155238016, 1162357504, 1169425792, 1176443264, 1183411072, 1190329728, 1197200256, + 1204023168, 1210799360, 1217529344, 1224213888, 1230853632, 1237449216, 1244001152, 1250510208, 1256976768, 1263401344, 1269784960, 1276127616, 1282429952, + 1288692736, 1294916096, 1301100672, 1307246976, 1313355520, 1319426432, 1325460352, 1331457920, 1337419136, 1343344640, 1349234816, 1355090048, 1360910592, + 1366696832, 1372449024, 1378168064, 1383853440, 1389506048, 1395126272, 1400713984, 1406269824, 1411793920, 1417286784, 1422748544, 1428179456, 1433579776, + 1438950016, 1444290176, 1449600640, 1454881536, 1460133248, 1465355904, 1470549760, 1475715328, 1480852352, 1485961344, 1491042560, 1496096000, 1501122176, + 1506120960, 1511092736, 1516037760, 1520956160, 1525847936, 1530713472, 1535553024, 1540366592, 1545154432, 1549916928, 1554653568, 1559365376, 1564052096, + 1568713600, 1573350656, 1577963008, 1582550912, 1587114496, 1591653888, 1596169344, 1600660864, 1605128704, 1609573120, 1613993728, 1618391296, 1622765568, + 1627116544, 1631444864, 1635750272, 1640032896, 1644292992, 1648530688, 1652745728, 1656938880, 1661109504, 1665258496, 1669385344, 1673490432, 1677573632, + 1681635328, 1685675648, 1689694208, 1693691776, 1697668096, 1701623040, 1705557120, 1709470208, 1713362304, 1717233792, 1721084416, 1724914688, 1728724352, + 1732513408, 1736282240, 1740030848, 1743759104, 1747467392, 1751155456, 1754823552, 1758471936, 1762100352, 1765709184, 1769298048, 1772867584, 1776417408, + 1779947776, 1783458816, 1786950400, 1790422656, 1793875712, 1797309824, 1800724736, 1804120576, 1807497216, 1810855296, 1814194432, 1817514624, 1820816128, + 1824099072, 1827363456, 1830608896, 1833836160, 1837044736, 1840235008, 1843406848, 1846560384, 1849695744, 1852812800, 1855911680, 1858992384, 1862055168, + 1865099648, 1868126336, 1871135104, 1874125952, 1877098880, 1880054016, 1882991616, 1885911168, 1888813184, 1891697536, 1894564352, 1897413504, 1900245120, + 1903059456, 1905856128, 1908635520, 1911397504, 1914142208, 1916869504, 1919579520, 1922272256, 1924948096, 1927606400, 1930247808, 1932872064, 1935479296, + 1938069632, 1940642688, 1943199104, 1945738240, 1948260736, 1950766208, 1953254912, 1955726848, 1958182144, 1960620416, 1963042048, 1965447040, 1967835264, + 1970206976, 1972561920, 1974900224, 1977222144, 1979527424, 1981816192, 1984088704, 1986344576, 1988584064, 1990807168, 1993013632, 1995203840, 1997377792, + 1999535616, 2001676800, 2003801984, 2005910528, 2008003328, 2010079744, 2012139776, 2014183808, 2016211584, 2018223360, 2020219008, 2022198656, 2024162048, + 2026109568, 2028041088, 2029956352, 2031855872, 2033739392, 2035606784, 2037458432, 2039294080, 2041113856, 2042917504, 2044705536, 2046477824, 2048233984, + 2049974528, 2051699200, 2053408128, 2055101312, 2056778624, 2058440448, 2060086272, 2061716352, 2063331072, 2064929920, 2066513024, 2068080384, 2069632384, + 2071168512, 2072689152, 2074194304, 2075683584, 2077157632, 2078615808, 2080058624, 2081485952, 2082897408, 2084293760, 2085674368, 2087039488, 2088389248, + 2089723392, 2091042432, 2092345728, 2093633536, 2094905984, 2096163072, 2097404800, 2098630912, 2099841920, 2101037440, 2102217472, 2103382272, 2104531840, + 2105665920, 2106784512, 2107888128, 2108976256, 2110048896, 2111106560, 2112148736, 2113175680, 2114187520, 2115184000, 2116165120, 2117131136, 2118081792, + 2119017216, 2119937408, 2120842368, 2121732352, 2122606720, 2123466240, 2124310400, 2125139456, 2125953152, 2126751872, 2127535488, 2128303872, 2129056896, + 2129795072, 2130517888, 2131225472, 2131918208, 2132595584, 2133258112, 2133905280, 2134537344, 2135154304, 2135756288, 2136342912, 2136914816, 2137471232, + 2138012800, 2138539136, 2139050496, 2139546752, 2140028032, 2140494208, 2140945152, 2141381120, 2141802112, 2142207872, 2142598784, 2142974592, 2143335168, + 2143680896, 2144011392, 2144327040, 2144627456, 2144913152, 2145183488, 2145438848, 2145679360, 2145904640, 2146114816, 2146310272, 2146490496, 2146655616, + 2146805888, 2146940928, 2147061248, 2147166464, 2147256448, 2147331584, 2147391744, 2147436672, 2147466624, 2147481728 +}; + const float win_syn_8k[STEREO_DFT_OVL_8k] = { 0.0011884f, 0.0061737f, 0.0132770f, 0.0219768f, 0.0320069f, 0.0431939f, 0.0554104f, 0.0685561f, 0.0825479f, 0.0973143f, 0.1127919f, 0.1289238f, 0.1456574f, 0.1629441f, 0.1807378f, 0.1989949f, 0.2176735f, 0.2367334f, 0.2561357f, 0.2758425f, 0.2958170f, 0.3160233f, 0.3364260f, 0.3569906f, 0.3776832f, 0.3984704f, 0.4193193f, 0.4401978f, @@ -364,6 +459,107 @@ const float win_mdct_8k[STEREO_DFT_OVL_8k] = { 0.9544637f, 0.9609173f, 0.9668870f, 0.9723699f, 0.9773632f, 0.9818643f, 0.9858710f, 0.9893813f, 0.9923935f, 0.9949059f, 0.9969173f, 0.9984268f, 0.9994336f, 0.9999371f }; +const Word32 win_syn_8k_fx[STEREO_DFT_OVL_8k] = { + 2552069, 13257920, 28512140, 47194820, 68734296, 92758192, 118992928, 147223104, 177270272, 208980864, 242218768, 276861760, 312796896, 349919776, 388131456, + 427338304, 467450272, 508381120, 550047232, 592367232, 635262144, 678654848, 722469312, 766631488, 811068480, 855708672, 900481344, 945317568, 990149120, + 1034908672, 1079530112, 1123948672, 1168100352, 1211922048, 1255352192, 1298330112, 1340796288, 1382692352, 1423961216, 1464546688, 1504394496, 1543451264, + 1581664640, 1618984448, 1655360896, 1690746752, 1725095296, 1758361984, 1790503424, 1821478016, 1851245952, 1879768704, 1907009664, 1932933888, 1957508224, + 1980701440, 2002483840, 2022827776, 2041707136, 2059098624, 2074979712, 2089330176, 2102132224, 2113369344, 2123027840, 2131095296, 2137561472, 2142418176, + 2145659392, 2147280896 +}; + +const Word32 win_syn_12k8_fx[STEREO_DFT_OVL_12k8] = { + 1261002, 6551972, 14094794, 23341214, 34014852, 45938972, 58986220, 73058896, 88077968, 103977504, 120700824, 138198304, 156425504, 175342256, 194911840, + 215100336, 235876160, 257209056, 279070880, 301434752, 324274976, 347566784, 371285952, 395409728, 419915296, 444781024, 469985376, 495507360, 521326560, + 547422976, 573776896, 600368576, 627179264, 654189888, 681381760, 708736576, 736236224, 763862528, 791598144, 819425216, 847326400, 875284480, 903282496, + 931303744, 959331200, 987348544, 1015339520, 1043287744, 1071177088, 1098992128, 1126716544, 1154335360, 1181832832, 1209193984, 1236403584, 1263446912, + 1290308864, 1316975488, 1343432064, 1369664384, 1395658880, 1421401344, 1446878080, 1472076032, 1496981888, 1521582336, 1545864832, 1569816832, 1593425536, + 1616678912, 1639565312, 1662072704, 1684189440, 1705904512, 1727206528, 1748084992, 1768529024, 1788528384, 1808072832, 1827152512, 1845758080, 1863880064, + 1881509248, 1898636672, 1915253888, 1931352704, 1946925184, 1961963136, 1976459392, 1990406656, 2003797632, 2016626304, 2028886016, 2040570752, 2051674496, + 2062192000, 2072117888, 2081447424, 2090175872, 2098299008, 2105812608, 2112713344, 2118997504, 2124662144, 2129704192, 2134121728, 2137912064, 2141073664, + 2143604608, 2145504128, 2146770944, 2147404416 +}; + +const Word32 win_syn_16k_fx[STEREO_DFT_OVL_16k] = { + 902372, 4688386, 10086516, 16705275, 24347740, 32888712, 42238640, 52328808, 63104236, 74519400, 86535432, 99118824, 112239520, 125870888, 139988880, 154570928, + 169597088, 185047600, 200904832, 217152048, 233772928, 250752224, 268075536, 285728512, 303697792, 321970304, 340533344, 359374528, 378481760, 397843456, + 417448288, 437284800, 457342080, 477609376, 498076192, 518731776, 539566208, 560569024, 581730368, 603040256, 624488896, 646066816, 667764352, 689571840, + 711480256, 733480128, 755562496, 777717888, 799937472, 822212224, 844533376, 866892096, 889279616, 911687104, 934106432, 956528704, 978945472, 1001348416, + 1023729088, 1046079424, 1068391360, 1090656256, 1112866560, 1135014016, 1157090816, 1179089024, 1201000832, 1222818688, 1244534656, 1266141312, 1287631232, + 1308996992, 1330230784, 1351325952, 1372274944, 1393070464, 1413705856, 1434173824, 1454467456, 1474579968, 1494504704, 1514235008, 1533764224, 1553085696, + 1572193152, 1591080320, 1609741056, 1628168832, 1646357760, 1664302208, 1681995776, 1699432832, 1716607744, 1733515136, 1750149120, 1766504320, 1782575744, + 1798358016, 1813846016, 1829034624, 1843919232, 1858494848, 1872756736, 1886700544, 1900321536, 1913615360, 1926578048, 1939205248, 1951492864, 1963437184, + 1975034240, 1986280448, 1997172096, 2007705600, 2017878016, 2027685888, 2037126016, 2046195456, 2054891392, 2063211264, 2071152000, 2078711296, 2085886976, + 2092676480, 2099077632, 2105088640, 2110707584, 2115932544, 2120762112, 2125194240, 2129228160, 2132862336, 2136095360, 2138926592, 2141355136, 2143379968, + 2145000704, 2146216576, 2147027584, 2147432960 +}; + +const Word32 win_syn_32k_fx[STEREO_DFT_OVL_32k] = { + 319116, 1657642, 3566755, 5907942, 8612268, 11636355, 14948419, 18525698, 22348862, 26402882, 30674656, 35153448, 39829380, 44694072, 49740016, 54960336, 60348800, + 65899616, 71607840, 77468328, 83476984, 89629312, 95921440, 102349712, 108910496, 115600336, 122416448, 129355608, 136415040, 143591712, 150883056, 158286720, + 165799904, 173420464, 181146048, 188974480, 196903424, 204930720, 213054640, 221272848, 229583616, 237984784, 246474640, 255051472, 263713360, 272458336, + 281285152, 290191840, 299176672, 308237984, 317374464, 326584384, 335866016, 345217888, 354638656, 364126688, 373680608, 383298784, 392979840, 402722336, + 412524960, 422385984, 432304576, 442278752, 452307744, 462389728, 472523488, 482707936, 492941344, 503222848, 513550752, 523924160, 534341376, 544801600, + 555302976, 565844736, 576425600, 587044288, 597699264, 608389632, 619114176, 629871552, 640660736, 651480192, 662329280, 673206272, 684110144, 695039936, + 705994240, 716971968, 727972032, 738993344, 750034624, 761094848, 772172608, 783266944, 794376960, 805501376, 816638848, 827788608, 838949248, 850119872, + 861299456, 872486528, 883680512, 894879872, 906083904, 917291200, 928501056, 939712000, 950923136, 962133632, 973342208, 984547840, 995749312, 1006945856, + 1018136384, 1029319808, 1040495360, 1051661376, 1062817344, 1073962368, 1085094912, 1096214400, 1107319680, 1118409728, 1129483648, 1140540160, 1151578624, + 1162598016, 1173597184, 1184575360, 1195531392, 1206464512, 1217373440, 1228257536, 1239115648, 1249946880, 1260750336, 1271525120, 1282270208, 1292984704, + 1303667584, 1314317952, 1324935168, 1335517952, 1346065792, 1356577280, 1367051776, 1377488512, 1387886464, 1398244608, 1408562432, 1418838784, 1429072896, + 1439263744, 1449410816, 1459512832, 1469569280, 1479579136, 1489541504, 1499455744, 1509321088, 1519136384, 1528900992, 1538614272, 1548275200, 1557883008, + 1567436672, 1576935936, 1586379648, 1595766912, 1605097344, 1614369920, 1623584000, 1632738688, 1641833344, 1650867072, 1659839232, 1668749184, 1677596160, + 1686379136, 1695097984, 1703751424, 1712339072, 1720860032, 1729313664, 1737699328, 1746016512, 1754264192, 1762441984, 1770549120, 1778584832, 1786548608, + 1794439936, 1802257792, 1810001920, 1817671424, 1825265792, 1832784512, 1840226816, 1847592320, 1854880256, 1862089984, 1869220864, 1876272768, 1883244544, + 1890136064, 1896946816, 1903675776, 1910322816, 1916887296, 1923368832, 1929766656, 1936080256, 1942309248, 1948453120, 1954511360, 1960483584, 1966369152, + 1972167808, 1977878784, 1983501952, 1989036672, 1994482560, 1999839232, 2005106176, 2010282880, 2015368960, 2020364160, 2025268224, 2030080512, 2034800640, + 2039428224, 2043963136, 2048404736, 2052752768, 2057006720, 2061166848, 2065232000, 2069202560, 2073077632, 2076857472, 2080541440, 2084129280, 2087620608, + 2091015296, 2094313216, 2097513856, 2100617216, 2103622784, 2106530304, 2109339776, 2112050816, 2114663424, 2117177088, 2119591936, 2121907328, 2124123520, + 2126240128, 2128257280, 2130174336, 2131991296, 2133708160, 2135324800, 2136840960, 2138256512, 2139571712, 2140785920, 2141899136, 2142911616, 2143823104, + 2144633472, 2145342592, 2145950592, 2146457344, 2146862848, 2147166848, 2147369600, 2147470976 +}; + +const Word32 win_syn_48k_fx[STEREO_DFT_OVL_MAX] = { + 173731, 902372, 1941540, 3216071, 4688386, 6334862, 8138533, 10086516, 12168931, 14377618, 16705275, 19146106, 21695168, 24347740, 27099956, 29947948, 32888712, + 35919240, 39036744, 42238640, 45522788, 48886820, 52328808, 55846816, 59439128, 63104236, 66840212, 70645768, 74519400, 78459600, 82465520, 86535432, 90668480, + 94863160, 99118824, 103433976, 107807976, 112239520, 116727760, 121271840, 125870888, 130524056, 135230272, 139988880, 144799024, 149660064, 154570928, 159531408, + 164540192, 169597088, 174701008, 179851328, 185047600, 190288960, 195574992, 200904832, 206278048, 211694000, 217152048, 222651536, 228192048, 233772928, + 239393536, 245053648, 250752224, 256489216, 262263808, 268075536, 273924000, 279808320, 285728512, 291683904, 297673664, 303697792, 309755616, 315846528, + 321970304, 328126272, 334314016, 340533344, 346783392, 353063936, 359374528, 365714528, 372083744, 378481760, 384907872, 391361920, 397843456, 404352064, + 410887072, 417448288, 424035264, 430647552, 437284800, 443946496, 450632480, 457342080, 464075072, 470831072, 477609376, 484410048, 491232384, 498076192, + 504940832, 511826304, 518731776, 525657184, 532602144, 539566208, 546548992, 553550016, 560569024, 567605696, 574659520, 581730368, 588817472, 595920896, + 603040256, 610174848, 617324480, 624488896, 631667712, 638860288, 646066816, 653286400, 660518912, 667764352, 675021760, 682291008, 689571840, 696864000, + 704166784, 711480256, 718803776, 726137216, 733480128, 740832256, 748192960, 755562496, 762939968, 770325120, 777717888, 785117632, 792524352, 799937472, + 807356544, 814781696, 822212224, 829647872, 837088512, 844533376, 851982592, 859435648, 866892096, 874351808, 881814336, 889279616, 896747072, 904216256, + 911687104, 919159488, 926632512, 934106432, 941580544, 949054848, 956528704, 964001984, 971474368, 978945472, 986415040, 993882688, 1001348416, 1008811584, + 1016271936, 1023729088, 1031182976, 1038633280, 1046079424, 1053521536, 1060958912, 1068391360, 1075818624, 1083240320, 1090656256, 1098066176, 1105469824, + 1112866560, 1120256512, 1127639168, 1135014016, 1142381184, 1149740160, 1157090816, 1164432640, 1171765376, 1179089024, 1186402944, 1193706880, 1201000832, + 1208284288, 1215556864, 1222818688, 1230068992, 1237307648, 1244534656, 1251749504, 1258951808, 1266141312, 1273318016, 1280481408, 1287631232, 1294767232, + 1301889408, 1308996992, 1316089856, 1323168000, 1330230784, 1337278464, 1344310144, 1351325952, 1358325504, 1365308672, 1372274944, 1379224192, 1386156032, + 1393070464, 1399967104, 1406845696, 1413705856, 1420547328, 1427370112, 1434173824, 1440958080, 1447722624, 1454467456, 1461192064, 1467896320, 1474579968, + 1481242752, 1487884416, 1494504704, 1501103488, 1507680256, 1514235008, 1520767360, 1527277312, 1533764224, 1540228096, 1546668672, 1553085696, 1559479040, + 1565848192, 1572193152, 1578513664, 1584809600, 1591080320, 1597326080, 1603546496, 1609741056, 1615909760, 1622052352, 1628168832, 1634258688, 1640321664, + 1646357760, 1652366720, 1658348288, 1664302208, 1670228224, 1676126080, 1681995776, 1687836928, 1693649280, 1699432832, 1705187328, 1710912256, 1716607744, + 1722273536, 1727909376, 1733515136, 1739090432, 1744635008, 1750149120, 1755632128, 1761083904, 1766504320, 1771893248, 1777250560, 1782575744, 1787868800, + 1793129728, 1798358016, 1803553664, 1808716416, 1813846016, 1818942336, 1824005376, 1829034624, 1834030336, 1838991872, 1843919232, 1848812288, 1853670912, + 1858494848, 1863283968, 1868037888, 1872756736, 1877440128, 1882088192, 1886700544, 1891276800, 1895817216, 1900321536, 1904789376, 1909220736, 1913615360, + 1917973248, 1922294272, 1926578048, 1930824704, 1935033728, 1939205248, 1943339136, 1947435008, 1951492864, 1955512832, 1959494272, 1963437184, 1967341824, + 1971207424, 1975034240, 1978822272, 1982570880, 1986280448, 1989950464, 1993581056, 1997172096, 2000723072, 2004234496, 2007705600, 2011136896, 2014527616, + 2017878016, 2021187968, 2024457344, 2027685888, 2030873600, 2034020224, 2037126016, 2040190464, 2043213696, 2046195456, 2049135744, 2052034432, 2054891392, + 2057706752, 2060480128, 2063211264, 2065900288, 2068547328, 2071152000, 2073714304, 2076234240, 2078711296, 2081145984, 2083537792, 2085886976, 2088193152, + 2090456320, 2092676480, 2094853504, 2096987264, 2099077632, 2101124864, 2103128704, 2105088640, 2107005312, 2108878336, 2110707584, 2112493184, 2114234752, + 2115932544, 2117586432, 2119196288, 2120762112, 2122283520, 2123761024, 2125194240, 2126583296, 2127927808, 2129228160, 2130483968, 2131695360, 2132862336, + 2133984512, 2135062400, 2136095360, 2137083776, 2138027648, 2138926592, 2139780992, 2140590464, 2141355136, 2142075008, 2142749952, 2143379968, 2143965184, + 2144505344, 2145000704, 2145451008, 2145856256, 2146216576, 2146531840, 2146802304, 2147027584, 2147207680, 2147342720, 2147432960, 2147478016 +}; + +const Word32 win_mdct_8k_fx[STEREO_DFT_OVL_8k] = { + 24094122, 72270552, 120410264, 168489632, 216483968, 264369408, 312121728, 359716832, 407130912, 454339904, 501320192, 548047936, 594499712, 640652160, 686482048, + 731966336, 777081984, 821806336, 866117120, 909991488, 953407808, 996343936, 1038778432, 1080689792, 1122057216, 1162859392, 1203076224, 1242687104, 1281672320, + 1320012288, 1357687424, 1394678912, 1430968448, 1466537216, 1501367424, 1535441792, 1568743040, 1601254400, 1632959488, 1663842176, 1693887232, 1723079296, + 1751403648, 1778846208, 1805392896, 1831030912, 1855746688, 1879527936, 1902363008, 1924240000, 1945148160, 1965076992, 1984016128, 2001956352, 2018888704, + 2034804352, 2049695232, 2063554176, 2076374016, 2088148480, 2098871552, 2108537472, 2117141888, 2124680192, 2131148800, 2136544128, 2140863616, 2144105216, + 2146267264, 2147348608 +}; /*----------------------------------------------------------------------------------* * ECLVQ Stereo ROM tables diff --git a/lib_enc/ivas_rom_enc.h b/lib_enc/ivas_rom_enc.h index 9517e133fa506d77af616dd8b8b35b123bbabd6f..3c87e361e888e7798669680730140faa68091f7d 100644 --- a/lib_enc/ivas_rom_enc.h +++ b/lib_enc/ivas_rom_enc.h @@ -95,6 +95,20 @@ extern const float win_syn_48k[STEREO_DFT_OVL_MAX]; extern const float win_mdct_8k[STEREO_DFT_OVL_8k]; +extern const Word32 win_ana_8k_fx[STEREO_DFT_OVL_8k]; +extern const Word32 win_ana_12k8_fx[STEREO_DFT_OVL_12k8]; +extern const Word32 win_ana_16k_fx[STEREO_DFT_OVL_16k]; +extern const Word32 win_ana_32k_fx[STEREO_DFT_OVL_32k]; +extern const Word32 win_ana_48k_fx[STEREO_DFT_OVL_MAX]; + +extern const Word32 win_syn_8k_fx[STEREO_DFT_OVL_8k]; +extern const Word32 win_syn_12k8_fx[STEREO_DFT_OVL_12k8]; +extern const Word32 win_syn_16k_fx[STEREO_DFT_OVL_16k]; +extern const Word32 win_syn_32k_fx[STEREO_DFT_OVL_32k]; +extern const Word32 win_syn_48k_fx[STEREO_DFT_OVL_MAX]; + +extern const Word32 win_mdct_8k_fx[STEREO_DFT_OVL_8k]; + /*----------------------------------------------------------------------------------* * Range Coder ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 3c66fe56c918dd5b32e147f5219e8a5d9dc42313..ea6320eb82f5b2080ce7cdf20115fa873ab68e7d 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -363,6 +363,83 @@ ivas_error create_sce_enc( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error create_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ +) +{ + SCE_ENC_HANDLE hSCE; + Encoder_State *st; + + ivas_error error; + + error = IVAS_ERR_OK; + + /*-----------------------------------------------------------------* + * Allocate SCE handle + *-----------------------------------------------------------------*/ + + IF ( ( hSCE = (SCE_ENC_HANDLE) malloc( sizeof( SCE_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SCE\n" ) ); + } + + /*-----------------------------------------------------------------* + * Initialization - general parameters + *-----------------------------------------------------------------*/ + + hSCE->sce_id = sce_id; + hSCE->element_brate = element_brate; + hSCE->last_element_brate = hSCE->element_brate; + + /*-----------------------------------------------------------------* + * Metadata: allocate and initialize + *-----------------------------------------------------------------*/ + + IF ( NE_16(st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT) && EQ_16(sce_id, sub( st_ivas->nSCE, 1 ) )) + { + IF ( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE + { + hSCE->hMetaData = NULL; + } + + /*-----------------------------------------------------------------* + * Core Coder, 1 instance: allocate and initialize + *-----------------------------------------------------------------*/ + + IF ( ( st = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); + } + + copy_encoder_config_fx( st_ivas, st, 1 ); + + IF ( EQ_16(st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT) && ( EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ) || EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ) || EQ_16(st_ivas->ism_mode, ISM_MASA_MODE_DISC )) ) + { + st->element_mode = IVAS_SCE; + } + + st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + + IF ( ( error = init_encoder_ivas_fx( st, st_ivas, 0, st_ivas->hEncoderConfig->var_SID_rate_flag, st_ivas->hEncoderConfig->interval_SID, 0, st_ivas->ism_mode, hSCE->element_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + hSCE->hCoreCoder[0] = st; + + st_ivas->hSCE[sce_id] = hSCE; + + return error; +} +#endif #ifndef EVS_FLOAT_ENC /*------------------------------------------------------------------------- * create_evs_sce_enc() diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 9f3391d7b666084df18ae7733be409560dd5b0a6..9f5370d1702f95e7e4646ad35d6936f4016a56c6 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -42,6 +42,7 @@ #include "math.h" #include #include "wmc_auto.h" +#include "prot_fx_enc.h" /*-------------------------------------------------------------------* @@ -239,8 +240,190 @@ ivas_error ivas_spar_enc_open( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_spar_enc_open_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +) +{ + SPAR_ENC_HANDLE hSpar; + ENCODER_CONFIG_HANDLE hEncoderConfig; + IVAS_FB_CFG *fb_cfg; + Word16 nchan_inp, nchan_transport, sba_order_internal; + Word16 nchan_fb_in; + Word16 table_idx, active_w_mixing; + Word32 input_Fs, ivas_total_brate; + ivas_error error; + + hEncoderConfig = st_ivas->hEncoderConfig; + error = IVAS_ERR_OK; + hSpar = st_ivas->hSpar; + + IF (!spar_reconfig_flag) + { + /* SPAR encoder handle */ + IF ((hSpar = (SPAR_ENC_HANDLE)malloc(sizeof(SPAR_ENC_DATA))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder"); + } + } + + hSpar->spar_reconfig_flag = 0; + input_Fs = hEncoderConfig->input_Fs; + sba_order_internal = L_min(st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER); + nchan_inp = ivas_sba_get_nchan_metadata(sba_order_internal, hEncoderConfig->ivas_total_brate); + assert(nchan_inp <= hEncoderConfig->nchan_inp); + ivas_total_brate = hEncoderConfig->ivas_total_brate; + + nchan_fb_in = 0; + IF (EQ_16(st_ivas->sba_analysis_order, 1)) + { + nchan_fb_in = FOA_CHANNELS; + } + ELSE IF (EQ_16(st_ivas->sba_analysis_order, 2)) + { + nchan_fb_in = 9; + } + ELSE IF (EQ_16(st_ivas->sba_analysis_order, 3)) + { + nchan_fb_in = 11; + } + ELSE + { + assert(0 && "sba_order must be 1,2, or 3!"); + } + + nchan_transport = ivas_get_sba_num_TCs_fx(hEncoderConfig->ivas_total_brate, sba_order_internal); + + table_idx = ivas_get_spar_table_idx_fx(ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL); + + /* MD handle */ + IF ((error = ivas_spar_md_enc_open_fx(&(hSpar->hMdEnc), hEncoderConfig, sba_order_internal)) != IVAS_ERR_OK) + { + return error; + } + + /* set FB config. */ + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + IF ((error = ivas_fb_set_cfg(&fb_cfg, SBA_FORMAT, nchan_inp, nchan_transport, active_w_mixing, input_Fs, nchan_fb_in)) != IVAS_ERR_OK) + { + return error; + } + fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + IF ((error = ivas_FB_mixer_open(&(hSpar->hFbMixer), input_Fs, fb_cfg, spar_reconfig_flag)) != IVAS_ERR_OK) + { + return error; + } + + /* Covariance handle */ + IF ((error = ivas_spar_covar_enc_open(&(hSpar->hCovEnc), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate)) != IVAS_ERR_OK) + { + return error; + } + + IF (!spar_reconfig_flag) + { + /* Transient Detector handle */ + IF ((error = ivas_transient_det_open(&(hSpar->hTranDet), input_Fs)) != IVAS_ERR_OK) + { + return error; + } + } + + /* initialization */ + hSpar->hMdEnc->table_idx = -1; + + /* AGC handle */ + hSpar->AGC_Enable = ivas_agc_enc_get_flag(nchan_transport); + + hSpar->hAgcEnc = NULL; + IF (hSpar->AGC_Enable) + { + IF ((error = ivas_spar_agc_enc_open(&hSpar->hAgcEnc, input_Fs, nchan_inp)) != IVAS_ERR_OK) + { + return error; + } + } + + /* PCA handle */ + hSpar->hPCA = NULL; + IF (hEncoderConfig->Opt_PCA_ON) + { + IF ((hSpar->hPCA = (PCA_ENC_STATE *)malloc(sizeof(PCA_ENC_STATE))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder"); + } + ivas_pca_enc_init(hSpar->hPCA); + } + + /* initialization */ + hSpar->hMdEnc->table_idx = -1; + + /*-----------------------------------------------------------------* + * Configuration - set SPAR high-level parameters + *-----------------------------------------------------------------*/ + + ivas_spar_config(hEncoderConfig->ivas_total_brate, min(st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1); + + IF (EQ_16(st_ivas->nchan_transport, 1)) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + ELSE + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + + /*-----------------------------------------------------------------* + * Allocate and initialize Front-VAD handle + *-----------------------------------------------------------------*/ + + IF (!spar_reconfig_flag) + { + hSpar->front_vad_flag = 0; + hSpar->front_vad_dtx_flag = 0; + hSpar->force_front_vad = 0; + + IF (hEncoderConfig->Opt_DTX_ON) + { + IF ((error = front_vad_create_fx(&(hSpar->hFrontVad), hEncoderConfig)) != IVAS_ERR_OK) + { + return error; + } + + IF ((hSpar->hCoreCoderVAD = (ENC_CORE_HANDLE)malloc(sizeof(Encoder_State))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n")); + } + + copy_encoder_config_fx(st_ivas, hSpar->hCoreCoderVAD, 1); + hSpar->hCoreCoderVAD->total_brate = hEncoderConfig->ivas_total_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + hSpar->hCoreCoderVAD->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + IF ((error = init_encoder_ivas_fx(hSpar->hCoreCoderVAD, st_ivas, 0, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 1, st_ivas->ism_mode, hSpar->hCoreCoderVAD->total_brate)) != IVAS_ERR_OK) + { + return error; + } + } + ELSE + { + hSpar->hCoreCoderVAD = NULL; + hSpar->hFrontVad = NULL; + } + } + + /*-----------------------------------------------------------------* + * Final assignment + *-----------------------------------------------------------------*/ + + st_ivas->hSpar = hSpar; + + return error; +} +#endif /*------------------------------------------------------------------------- * ivas_spar_enc_close() * diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index f8cecc141fd98634a8bd998332db014a175ab0d9..b633a1f3be0c521f513f9df82ea445d6e3d59448 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -34,6 +34,7 @@ #include "options.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "math.h" #include "ivas_rom_com.h" #include @@ -70,6 +71,7 @@ static int16_t ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR static int16_t ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t strat, const int32_t ivas_total_brate ); static void ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *hMdEnc, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); +static void ivas_spar_set_enc_config_fx( ivas_spar_md_enc_state_t *hMdEnc, Word16 *max_freq_per_chan, const Word16 nchan_transport, Word32 *pFC, const Word16 nchan_inp ); static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const int16_t dmx_switch, const int16_t dtx_vad ); @@ -165,8 +167,73 @@ ivas_error ivas_spar_md_enc_open( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_spar_md_enc_open_fx( + ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +) +{ + ivas_spar_md_enc_state_t *hMdEnc; + ivas_error error; + Word16 num_channels, i, j; + error = IVAS_ERR_OK; + + IF ((hMdEnc = (ivas_spar_md_enc_state_t *)malloc(sizeof(ivas_spar_md_enc_state_t))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder"); + } + num_channels = ivas_sba_get_nchan_metadata(sba_order, hEncoderConfig->ivas_total_brate); + IF((hMdEnc->mixer_mat_local_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + } + FOR(i = 0; i < num_channels; i++) + { + IF((hMdEnc->mixer_mat_local_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + } + FOR(j = 0; j < num_channels; j++) + { + IF((hMdEnc->mixer_mat_local_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + } + } + } + + IF((hMdEnc->mixer_mat_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + } + FOR(i = 0; i < num_channels; i++) + { + IF((hMdEnc->mixer_mat_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + } + FOR(j = 0; j < num_channels; j++) + { + IF((hMdEnc->mixer_mat_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + } + } + } + + IF ((error = ivas_spar_md_enc_init_fx(hMdEnc, hEncoderConfig, sba_order)) != IVAS_ERR_OK) + { + return error; + } + + *hMdEnc_in = hMdEnc; + + return error; +} +#endif /*------------------------------------------------------------------------- * ivas_spar_md_enc_close() * @@ -299,8 +366,75 @@ ivas_error ivas_spar_md_enc_init( return IVAS_ERR_OK; } - - +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_spar_md_enc_init_fx( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +) +{ + Word32 pFC[IVAS_MAX_NUM_BANDS]; + Word16 table_idx; + Word32 PR_minmax_fx[2]; + Word16 num_channels, i, j, k; + + ivas_sba_get_spar_hoa_md_flag(sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag); + num_channels = ivas_sba_get_nchan_metadata(sba_order, hEncoderConfig->ivas_total_brate); + ivas_sba_get_spar_hoa_ch_ind(num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind); + table_idx = ivas_get_spar_table_idx_fx(hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL); + + hMdEnc->spar_md.prior_dyn_active_w_flag = 0; + + ivas_spar_set_bitrate_config_fx(&hMdEnc->spar_md_cfg, table_idx, (hMdEnc->spar_hoa_md_flag) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, + hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, ivas_agc_enc_get_flag(ivas_spar_br_table_consts[table_idx].nchan_transport));//TODO: some log operations pending. + + /* get FB coefficients */ + FOR (i = 0; i < IVAS_MAX_NUM_BANDS; i++) + { + pFC[i] = L_shr(Mpy_32_32(ivas_fb_fcs_12band_1ms_fx[i], hEncoderConfig->input_Fs), 1); //Q0 + } + + ivas_spar_set_enc_config_fx(hMdEnc, hMdEnc->spar_md_cfg.max_freq_per_chan, hMdEnc->spar_md_cfg.nchan_transport, pFC, num_channels); + + IF (NE_16(hMdEnc->spar_md_cfg.nchan_transport, 2) && (EQ_16(hMdEnc->spar_md_cfg.remix_unmix_order, 1) || EQ_16(hMdEnc->spar_md_cfg.remix_unmix_order, 2))) + { + return IVAS_ERR_INTERNAL; + } + + ivas_spar_arith_coeffs_com_init(&hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC); + ivas_spar_huff_coeffs_com_init(&hMdEnc->huff_coeffs, NULL, table_idx, ENC); +#if 0 //Some issues + IF (EQ_16(hEncoderConfig->Opt_DTX_ON, 1)) + { + /* DTX quant init */ + PR_minmax_fx[0] = hMdEnc->spar_md_cfg.quant_strat[0].PR.min_fx; + PR_minmax_fx[1] = hMdEnc->spar_md_cfg.quant_strat[0].PR.max_fx; + ivas_spar_quant_dtx_init_fx(&hMdEnc->spar_md, PR_minmax_fx); + } +#endif + hMdEnc->spar_md_cfg.prior_strat = START; + hMdEnc->spar_md_cfg.prev_quant_idx = -1; + + FOR (i = 0; i < num_channels; i++) + { + FOR (j = 0; j < num_channels; j++) + { + FOR (k = 0; k < IVAS_MAX_NUM_BANDS; k++) + { + hMdEnc->mixer_mat_fx[i][j][k] = 0; + } + } + } +#if 0 //Some issue + ivas_clear_band_coeffs_fx(hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS); +#endif + ivas_clear_band_coeff_idx(hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS); + ivas_clear_band_coeff_idx(hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS); + ivas_clear_band_coeff_idx(hMdEnc->spar_md_prior.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS); + + return IVAS_ERR_OK; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_set_enc_config() * @@ -349,7 +483,47 @@ static void ivas_spar_set_enc_config( return; } +static void ivas_spar_set_enc_config_fx( + ivas_spar_md_enc_state_t *hMdEnc, + Word16 *max_freq_per_chan, + const Word16 nchan_transport, + Word32 *pFC, //Input Q0 + const Word16 nchan_inp) +{ + Word16 i, j; + Word16 tmp_dmx_ch; + + FOR(i = 0; i < nchan_transport; i++) + { + IF(NE_16(max_freq_per_chan, NULL)) + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = (max_freq_per_chan[i] != 0) ? max_freq_per_chan[i] : max_freq_per_chan[0]; + } + ELSE + { + hMdEnc->spar_md_cfg.max_freq_per_chan[i] = IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN; + } + } + hMdEnc->num_umx_ch = nchan_inp; + hMdEnc->num_decorr = sub(nchan_inp, 1); + + FOR(i = 0; i < IVAS_MAX_NUM_BANDS; i++) + { + tmp_dmx_ch = 0; + FOR(j = 0; j < nchan_transport; j++) + { + IF(LT_32(pFC[i], hMdEnc->spar_md_cfg.max_freq_per_chan[j])) + { + tmp_dmx_ch = add(tmp_dmx_ch, 1); + } + } + hMdEnc->spar_md_cfg.num_dmx_chans_per_band[i] = tmp_dmx_ch; + hMdEnc->spar_md_cfg.num_decorr_per_band[i] = sub(hMdEnc->num_umx_ch, tmp_dmx_ch); + } + + return; +} /*-----------------------------------------------------------------------------------------* * Function ivas_band_limit_dmx_matrix() * diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index a248a787dc77e153431b690801b92bc3dfc698df..96dbacae10fbbd986db84947befebf53e66fe38c 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -71,18 +71,36 @@ typedef struct stereo_itd_data_struct int16_t detected_itd_flag; int16_t itd_tracking; float prev_max; + Word16 prev_max_fx; int16_t prev_index; float prev_avg_max; + Word16 prev_avg_max_fx; float currFlatness; + Word16 currFlatness_fx; /* Xtalk classifier */ float prev_m1; + Word16 prev_m1_fx; float prev_m2; + Word16 prev_m2_fx; int16_t prev_itd1; int16_t prev_itd2; /*flag for hybrid ITD for very large ITDs*/ int16_t hybrid_itd_max; + + Word32 acorr_L_fx[STEREO_DFT_BAND_MAX]; + Word32 acorr_R_fx[STEREO_DFT_BAND_MAX]; + Word16 cohSNR_fx; /*Q11*/ + Word16 itd_thres_fx; + Word32 prev_sum_nrg_L_lb_fx; + Word32 prev_xcorr_lb_fx[STEREO_DFT_XCORR_LB_MAX]; + Word32 E_band_n_fx[STEREO_DFT_ITD_VAD_BAND_NUM];/*Q0*/ + Word32 xcorr_smooth_fx[STEREO_DFT_N_32k_ENC]; + Word32 lp_phat_peak_fx; /* low-pass GCC PHAT peak value */ + Word32 itd_fx[STEREO_DFT_ENC_DFT_NB]; + Word32 deltaItd_fx[STEREO_DFT_ENC_DFT_NB]; + } ITD_DATA, *ITD_DATA_HANDLE; typedef struct dft_ana_struct @@ -98,6 +116,11 @@ typedef struct dft_ana_struct const float *win_ana; /* DFT analysis window */ const float *dft_trigo; const float *dft_trigo_32k; + + const Word32 *win_ana_fx; /* DFT analysis window */ + const Word16 *dft_trigo_fx; + const Word16 *dft_trigo_32k_fx; + int16_t dft_trigo_step; } DFT_ANA, *DFT_ANA_HANDLE; @@ -182,6 +205,7 @@ typedef struct stereo_dft_enc_data_struct /*Side Gain*/ float side_gain[STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX]; + Word32 side_gain_fx[STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX]; int16_t side_gain_flag_1; int16_t side_gain_flag_2; int16_t side_gain_index_ECDiff[STEREO_DFT_BAND_MAX]; @@ -189,16 +213,19 @@ typedef struct stereo_dft_enc_data_struct int16_t side_gain_index_EC[STEREO_DFT_BAND_MAX]; int16_t side_gain_counter; float side_gain_bitdiff_lp; + Word16 side_gain_bitdiff_lp_fx; /* Stereo CNG */ float sidSideGain[STEREO_DFT_ERB4_BANDS]; float win_ana_energy; + Word16 win_ana_energy_fx; //Q15 float xspec_smooth[STEREO_DFT_N_32k_ENC]; float Spd_L_smooth[STEREO_DFT_N_32k_ENC / 2]; float Spd_R_smooth[STEREO_DFT_N_32k_ENC / 2]; float sid_gipd; int16_t coh_fade_counter; float prev_sid_gipd; + Word32 prev_sid_gipd_fx; int16_t prev_sid_no_ipd_flag; /*IPD*/ @@ -224,6 +251,7 @@ typedef struct stereo_dft_enc_data_struct ITD_DATA_HANDLE hItd; float voicing_lt; + Word32 voicing_lt_fx; int16_t currentNumUpdates; @@ -251,7 +279,7 @@ typedef struct stereo_dft_enc_data_struct float diff_l_h_sm; float diff_r_h_sm; float prev_fac2; - + /*Residual coding*/ int16_t res_cod_mode[STEREO_DFT_ENC_DFT_NB]; /* mode from 0 (off) to 3 */ int16_t res_cod_band_max; /* Band max for coding of residual */ @@ -267,6 +295,7 @@ typedef struct stereo_dft_enc_data_struct int16_t hangover_cnt0; /* counter 0 for hangover */ int16_t hangover_cnt1; /* counter 1 for hangover */ float dmx_res_all_prev; /* energy of the previous frame */ + int16_t last_res_cod_mode_modify_flag; /* a flag to indicate whether the res_cod_mode_flag has been modified for the switching frame in which res_cod_mode_flag should be swithced from 1 to 0 */ int16_t res_cod_sw_flag; /* a flag to indicate whether it is a switching frame */ float switch_fade_factor; /* Adaptive fade factor for switch frame */ @@ -275,6 +304,67 @@ typedef struct stereo_dft_enc_data_struct float icbweRefEner; float lbEner; int16_t flip_sign; + Word32 dmx_res_all_prev_fx; /* energy of the previous frame Q31*/ + Word16 switch_fade_factor_fx; /* Adaptive fade factor for switch frame Q15*/ + Word32 res_dmx_ratio_lt_fx; /* long term energy ratio between RES and DMX Q31*/ + Word32 pre_sub_nrg_DMX_fx[STEREO_DFT_BAND_MAX]; + Word32 diff_l_h_sm_fx; + Word32 diff_r_h_sm_fx; + Word32 prev_fac2_fx; //initilizae in Q31 + Word32 res_pred_gain_f_fx[STEREO_DFT_BAND_MAX]; + Word32 nrg_L_fx[2]; + Word32 nrg_R_fx[2]; + Word32 nrg_DMX_fx[2]; + Word32 res_pred_gain_fx[STEREO_DFT_ENC_DFT_NB * STEREO_DFT_BAND_MAX]; /*prediction gain for the residual HFs */ + Word32 gainIPD_sm_fx; /* long-term gain IPD for NIPD detection */////initilizae in Q31 + Word32 sfm_fx; + Word32 sum_dot_prod_real_fx; + Word32 sum_dot_prod_img_fx; + Word32 dot_prod_real_smooth_fx[STEREO_DFT_BAND_MAX]; + Word32 dot_prod_img_smooth_fx[STEREO_DFT_BAND_MAX]; + Word32 ipd_buf_fx[STEREO_DFT_BAND_MAX][STEREO_DFT_IPD_BUF_LEN]; + Word32 prev_gipd_fx; + Word32 xspec_smooth_fx[STEREO_DFT_N_32k_ENC]; + Word32 Spd_L_smooth_fx[STEREO_DFT_N_32k_ENC / 2]; + Word32 Spd_R_smooth_fx[STEREO_DFT_N_32k_ENC / 2]; + Word32 sid_gipd_fx; + const Word32 *win_fx; /* DFT window */ + const Word32 *win_8k_fx; /* DFT window */ + const Word32 *win_12k8_fx; /* DFT window */ + const Word32 *win_16k_fx; /* DFT window */ + const Word32 *win_32k_fx; /* DFT window */ + + const Word32 *win_ana_fx; /* DFT analysis window */ + const Word32 *win_ana_8k_fx; /* DFT analysis window */ + const Word32 *win_ana_12k8_fx; /* DFT analysis window */ + const Word32 *win_ana_16k_fx; /* DFT analysis window */ + const Word32 *win_ana_32k_fx; /* DFT analysis window */ + + const Word32 *win_mdct_8k_fx; /* DFT analysis window */ + + const Word16 *dft_trigo_fx; + const Word16 *dft_trigo_8k_fx; + const Word16 *dft_trigo_12k8_fx; + const Word16 *dft_trigo_16k_fx; + const Word16 *dft_trigo_32k_fx; + + Word32 output_mem_res_8k_fx[STEREO_DFT_OVL_8k]; + + Word32 res_cod_NRG_M_fx[STEREO_DFT_BAND_MAX]; + Word32 res_cod_NRG_S_fx[STEREO_DFT_BAND_MAX]; + Word32 res_cod_SNR_M_fx[STEREO_DFT_BAND_MAX]; + Word32 old_snr_fx; + Word32 past_nrgL_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + Word32 past_nrgR_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + Word32 past_dot_prod_real_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + Word32 past_dot_prod_imag_fx[STEREO_DFT_NRG_PAST_LEN * STEREO_DFT_BAND_MAX]; + Word32 output_mem_dmx_fx[STEREO_DFT_OVL_MAX]; + Word32 output_mem_dmx_12k8_fx[STEREO_DFT_OVL_12k8]; + Word32 output_mem_dmx_16k_fx[STEREO_DFT_OVL_16k]; /*can hold 16, 12.8 or 32kHz signals*/ + Word32 output_mem_dmx_32k_fx[STEREO_DFT_OVL_32k]; /*can hold 16, 12.8 or 32kHz signals*/ + Word32 output_mem_dmx_16k_shb_fx[STEREO_DFT_OVL_16k]; + Word32 input_mem_itd_fx[CPE_CHANNELS][STEREO_DFT_OVL_MAX]; + Word32 gipd_fx[STEREO_DFT_ENC_DFT_NB]; } STEREO_DFT_ENC_DATA, *STEREO_DFT_ENC_DATA_HANDLE; @@ -315,12 +405,11 @@ typedef struct stereo_td_enc_data_structure { BSTR_ENC_DATA tdm_hBstr_tmp; /* temporary bitstream structure holding TD stereo spatial parameters */ Indice tdm_ind_list_tmp[MAX_IND_TDM_TMP]; /* temporary list of indices holding TD stereo spatial parameters */ - int16_t max_ind_tdm_tmp; /* maximum number of indices in the temporary list of indices holding TD stereo spatial parameters */ + Word16 max_ind_tdm_tmp; /* maximum number of indices in the temporary list of indices holding TD stereo spatial parameters */ - int16_t tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */ - int16_t tdm_low_rate_mode; /* secondary channel low rate mode flag */ + Word16 tdm_lp_reuse_flag; /* Flag that indicate if it is possible to reuse the LP coefficient from the primary channel or not */ + Word16 tdm_low_rate_mode; /* secondary channel low rate mode flag */ float tdm_Pri_pitch_buf[NB_SUBFR]; - int16_t tdm_Pitch_reuse_flag; float tdm_lt_corr_RM; /* Long term right-mono correlation */ float tdm_lt_corr_LM; /* Long term left-mono correlation */ @@ -332,15 +421,26 @@ typedef struct stereo_td_enc_data_structure float tdm_last_ener_lt_R; /* Right channel long term energy */ float tdm_last_ener_lt_L; /* Left channel long term energy */ - int16_t tdm_last_ratio_idx; /* last TDM ratio index */ - int16_t tdm_last_SM_flag; /* Flag to signal a SM encoding scheme -> better for some music item */ - int16_t tdm_ratio_transition_mov_flag; /* Flag that indicates that L-R energy is changing */ - int16_t tdm_ratio_transition_cnt; /* Counter */ - int16_t tdm_hyst_cnt; /* Counter */ - int16_t tdm_prev_stable_idx; /* Previous Transmitted ratio index*/ - int16_t tdm_prev_desired_idx; /* Previous Transmitted ratio index*/ + Word16 tdm_Pitch_reuse_flag; + Word32 tdm_lt_corr_RM_fx; /* Long term right-mono correlation */ + Word32 tdm_lt_corr_LM_fx; /* Long term left-mono correlation */ + Word32 tdm_last_diff_lt_corr_fx; /* long term correlation difference mem */ + Word32 tdm_last_ratio_fx; /* Last TDM ratio */ + Word32 tdm_lt_rms_L_fx; /* Left channel long term rms */ + Word32 tdm_lt_rms_R_fx; /* Right channel long term rms */ + Word32 tdm_last_ener_lt_R_fx; /* Right channel long term energy */ + Word32 tdm_last_ener_lt_L_fx; /* Left channel long term energy */ + + Word16 tdm_last_ratio_idx; /* last TDM ratio index */ + Word16 tdm_last_SM_flag; /* Flag to signal a SM encoding scheme -> better for some music item */ + Word16 tdm_ratio_transition_mov_flag; /* Flag that indicates that L-R energy is changing */ + Word16 tdm_ratio_transition_cnt; /* Counter */ + Word16 tdm_hyst_cnt; /* Counter */ + Word16 tdm_prev_stable_idx; /* Previous Transmitted ratio index*/ + Word16 tdm_prev_desired_idx; /* Previous Transmitted ratio index*/ float tdm_LT_es_em; /* Long term evoluation of the side to mono energy ratio */ - int16_t tdm_use_IAWB_Ave_lpc; /* Flag to indicate the usage of mean inactive LP coefficients */ + Word32 tdm_LT_es_em_fx; /* Long term evoluation of the side to mono energy ratio */ + Word16 tdm_use_IAWB_Ave_lpc; /* Flag to indicate the usage of mean inactive LP coefficients */ /* NOOP parameters */ float tdm_lt_corr_RM_SM; /* Long term right-mono correlation in SM mode*/ @@ -353,32 +453,42 @@ typedef struct stereo_td_enc_data_structure float tdm_last_ener_lt_R_SM; /* Right channel long term energy in SM mode*/ float tdm_last_ener_lt_L_SM; /* Left channel long term energy in SM mode*/ - int16_t tdm_last_ratio_idx_SM; /* last TDM ratio index in SM mode*/ - int16_t tdm_last_SM_flag_noop; /* Flag to signal a SM encoding scheme -> better for some music item in SM mode*/ - int16_t tdm_noop_mov_flag; /* Flag that indicates that L-R energy is changing in SM mode*/ - int16_t tdm_noop_cnt; /* Counter in SM mode*/ - int16_t tdm_hyst_cnt_SM; /* Counter in SM mode*/ - int16_t tdm_prev_stable_idx_SM; /* Previous Transmitted ratio index in SM mode*/ - int16_t tdm_prev_desired_idx_SM; /* Previous Transmitted ratio index in SM mode*/ + Word32 tdm_lt_corr_RM_SM_fx; /* Long term right-mono correlation in SM mode*/ + Word32 tdm_lt_corr_LM_SM_fx; /* Long term left-mono correlation in SM mode*/ + Word32 tdm_last_diff_lt_corr_SM_fx; /* long term correlation difference mem in SM mode*/ + Word32 tdm_last_ratio_SM_fx; /* Last TDM ratio in SM mode*/ + Word32 tdm_lt_rms_L_SM_fx; /* Left channel long term rms in SM mode*/ + Word32 tdm_lt_rms_R_SM_fx; /* Right channel long term rms in SM mode*/ + Word32 tdm_last_ener_lt_R_SM_fx; /* Right channel long term energy in SM mode*/ + Word32 tdm_last_ener_lt_L_SM_fx; /* Left channel long term energy in SM mode*/ + + Word16 tdm_last_ratio_idx_SM; /* last TDM ratio index in SM mode*/ + Word16 tdm_last_SM_flag_noop; /* Flag to signal a SM encoding scheme -> better for some music item in SM mode*/ + Word16 tdm_noop_mov_flag; /* Flag that indicates that L-R energy is changing in SM mode*/ + Word16 tdm_noop_cnt; /* Counter in SM mode*/ + Word16 tdm_hyst_cnt_SM; /* Counter in SM mode*/ + Word16 tdm_prev_stable_idx_SM; /* Previous Transmitted ratio index in SM mode*/ + Word16 tdm_prev_desired_idx_SM; /* Previous Transmitted ratio index in SM mode*/ float tdm_LT_es_em_SM; /* Long term evoluation of the side to mono energy ratio in SM mode*/ - int16_t tdm_NOOP_cnt; /* Counter for channel combination scheme */ - int16_t tdm_SM_flag; /* Flag for channel combination scheme */ - int16_t tdm_SM_last2_clas[2]; /* Class of the frame immediately prior to the previous frame */ - int16_t tdm_SM_last_clas[2]; /* Class of the previous frame */ - int16_t tdm_SM_modi_flag; /* Flag that indicates to modify ratio */ - int16_t tdm_SM_reset_flag; /* Flag that indicates to reset the parameters for SM mode */ - - int16_t tdm_FD2LRTD_SW_cnt; /* Count the number of frames following a FD to LRTD switching */ - int16_t tdm_LRTD_flag; /* LRTD stereo mode flag */ - int16_t prev_fr_LRTD_TD_dec; /* At the beginning of a frame, contains the previous LRTD decision that might have been modified during last frame */ - int16_t tdm_inst_ratio_idx; /* Instantaneous correlation ratio index */ - int16_t tdm_last_inst_ratio_idx; /* previous frame instantaneous correlation ratio index */ - int16_t tdm_vad_hangover_cnt; /* Count the number of frames where hangover_cnt >= 5 in both primary and secondary channel */ - int16_t tdm_ini_frame_cnt; /* Count the number of frame to decide how to evaluate the local VAD of primary and secondary channel */ - int16_t tdm_last_LRTD_frame_cnt; /* Count the number of frame since the last LRTD frame */ - int16_t tdm_last_LRTD_PriCh_cnt; /* Count the number of frame since the primary channel changed */ - int16_t flag_skip_DMX; /* flag that indicates whether the TD downmixing is skipped */ - + Word32 tdm_LT_es_em_SM_fx; /* Long term evoluation of the side to mono energy ratio in SM mode*/ + Word16 tdm_NOOP_cnt; /* Counter for channel combination scheme */ + Word16 tdm_SM_flag; /* Flag for channel combination scheme */ + Word16 tdm_SM_last2_clas[2]; /* Class of the frame immediately prior to the previous frame */ + Word16 tdm_SM_last_clas[2]; /* Class of the previous frame */ + Word16 tdm_SM_modi_flag; /* Flag that indicates to modify ratio */ + Word16 tdm_SM_reset_flag; /* Flag that indicates to reset the parameters for SM mode */ + + Word16 tdm_FD2LRTD_SW_cnt; /* Count the number of frames following a FD to LRTD switching */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ + Word16 prev_fr_LRTD_TD_dec; /* At the beginning of a frame, contains the previous LRTD decision that might have been modified during last frame */ + Word16 tdm_inst_ratio_idx; /* Instantaneous correlation ratio index */ + Word16 tdm_last_inst_ratio_idx; /* previous frame instantaneous correlation ratio index */ + Word16 tdm_vad_hangover_cnt; /* Count the number of frames where hangover_cnt >= 5 in both primary and secondary channel */ + Word16 tdm_ini_frame_cnt; /* Count the number of frame to decide how to evaluate the local VAD of primary and secondary channel */ + Word16 tdm_last_LRTD_frame_cnt; /* Count the number of frame since the last LRTD frame */ + Word16 tdm_last_LRTD_PriCh_cnt; /* Count the number of frame since the primary channel changed */ + Word16 flag_skip_DMX; /* flag that indicates whether the TD downmixing is skipped */ + Word32 tdm_Pri_pitch_buf_fx[NB_SUBFR]; } STEREO_TD_ENC_DATA, *STEREO_TD_ENC_DATA_HANDLE; @@ -388,21 +498,26 @@ typedef struct stereo_td_enc_data_structure typedef struct stereo_tca_enc_data_structure { - int16_t refChanIndx; /* reference channel index in current frame */ - int16_t prevRefChanIndx; /* reference channel index in previous frame */ - int16_t indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ - int16_t indx_ica_gD; /* ICA target gain */ + Word16 refChanIndx; /* reference channel index in current frame */ + Word16 prevRefChanIndx; /* reference channel index in previous frame */ + Word16 indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ + Word16 indx_ica_gD; /* ICA target gain */ float targetGain; /* gain norm applied on target (or right) channel in current frame */ float instTargetGain; /* instantaneous gain norm applied on target (or right) channel in current frame */ float prevTargetGain; /* gain norm applied on target (or right) channel in previous frame */ float corrStatsSmoothFac; /* gD/corrStats smoothing based on corrStats */ - int16_t lMemRecalc; - int16_t lMemRecalc_12k8; - int16_t lMemRecalc_16k; + Word16 targetGain_fx; /* gain norm applied on target (or right) channel in current frame //Q15*/ + Word16 instTargetGain_fx; /* instantaneous gain norm applied on target (or right) channel in current frame //Q15*/ + Word16 prevTargetGain_fx; /* gain norm applied on target (or right) channel in previous frame //Q15*/ + Word16 corrStatsSmoothFac_fx; /* gD/corrStats smoothing based on corrStats //Q15*/ + + Word16 lMemRecalc; + Word16 lMemRecalc_12k8; + Word16 lMemRecalc_16k; - int16_t corrLagStats[3]; /* corr lag stats in current frame */ - int16_t prevCorrLagStats[3]; /* corr lag stats in previous frame */ + Word16 corrLagStats[3]; /* corr lag stats in current frame */ + Word16 prevCorrLagStats[3]; /* corr lag stats in previous frame */ float memChanL[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* left channel input to correct at the cross-over */ float memChanR[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* right channel input to correct at the cross-over */ @@ -419,7 +534,24 @@ typedef struct stereo_tca_enc_data_structure float E1_mem, E2_mem; float delay_0_mem[MAX_DELAYREGLEN]; float smooth_dist_reg_prv_corr; - int16_t LRTD_G_ATT_cnt; + + Word32 memChanL_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* left channel input to correct at the cross-over */ + Word32 memChanR_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* right channel input to correct at the cross-over */ + + Word32 memChanL_DS_fx[ADDED_MEM_DS]; /* left channel input speech memory for downmix */ + Word32 memChanR_DS_fx[ADDED_MEM_DS]; /* right channel input speech memory for downmix */ + Word32 mem_tempF_fx; + Word32 memdecim_fx[12]; /* memory for pre-rmphasis filter for resampling */ + Word32 corrEstPrev_fx[3][2 * L_NCSHIFT_DS + 1]; /* Prev correlation vector */ + Word32 corrEstLT_fx[2 * L_NCSHIFT_DS + 1]; /* Long term correlation vector smoothed */ + + Word16 ica_envVarLT_fx; //Q20 + Word32 C_mem_fx[2 * L_NCSHIFT_DS + 1]; + Word32 E1_mem_fx, E2_mem_fx; + Word32 delay_0_mem_fx[MAX_DELAYREGLEN]; + Word16 smooth_dist_reg_prv_corr_fx; + + Word16 LRTD_G_ATT_cnt; } STEREO_TCA_ENC_DATA, *STEREO_TCA_ENC_HANDLE; @@ -471,7 +603,34 @@ typedef struct stereo_icbwe_enc_data_structure float mixExc16k[L_FRAME16k]; float lpSHBRef[LPC_SHB_ORDER + 1]; - int16_t MSFlag; + Word32 memHPF_fx[8]; + Word32 mem_decim_shb_ch0_fx[2 * L_FILT_MAX]; + Word32 mem_shb_speech_ref_fx[L_LOOK_16k]; + Word32 mem_shb_speech_nonref_fx[L_LOOK_16k]; + Word32 mem_lpc_shbsynth_nonref_fx[LPC_SHB_ORDER]; + Word32 prevSpecMapping_fx; + Word32 memShbSpecMapping_fx; + Word32 memShbSpecXcorr_fx[6]; + Word32 prevgsMapping_fx; + Word32 prevRefEner_fx; //Q31 + Word32 prevNonRefEner_fx; //Q31 + Word32 memGsEnerMap_fx[2]; //Q31 + Word32 dec_2over3_mem_fx[L_FILT_2OVER3]; + Word32 dec_2over3_mem_lp_fx[L_FILT_2OVER3_LP]; + Word32 icbwe_inp_mem_fx[CPE_CHANNELS][NS2SA(48000, L_MEM_RECALC_TBE_NS)]; + Word32 *dataChan_fx[CPE_CHANNELS]; + Word32 memModifyFs_icbwe_fx[CPE_CHANNELS][2 * L_FILT32k]; + Word32 mem_nrg_L_fx[CPE_CHANNELS]; + Word32 mem_nrg_R_fx[CPE_CHANNELS]; + Word32 mem_nrg_DMX_fx[CPE_CHANNELS]; + Word32 gDes_pastFrame_fx; //Q31 + Word32 icbweRefEner_fx; + Word32 shbSynthRef_fx[L_FRAME16k]; + Word32 nlExc16k_fx[L_FRAME16k]; + Word32 mixExc16k_fx[L_FRAME16k]; + Word32 lpSHBRef_fx[LPC_SHB_ORDER + 1]; + + Word16 MSFlag; } STEREO_ICBWE_ENC_DATA, *STEREO_ICBWE_ENC_HANDLE; @@ -483,8 +642,8 @@ typedef struct stereo_icbwe_enc_data_structure typedef struct ivas_stereo_classifier_data_structure { /* features for xtalk classifier and UNCLR classifier */ - int16_t clas_ch1; - int16_t pitch_ch1[3]; + Word16 clas_ch1; + Word16 pitch_ch1[3]; float voicing_ch1[3]; float cor_map_sum_ch1; float lsf_ch1[M]; @@ -499,10 +658,10 @@ typedef struct ivas_stereo_classifier_data_structure float prev_IPD; float prev_ratio_m1_m2; float ratio_L; - int16_t vad_flag_glob; - int16_t vad_relE; + Word16 vad_flag_glob; + Word16 vad_relE; - int16_t aEn_raw[CPE_CHANNELS]; /* raw aEn for local relative energy estimation */ + Word16 aEn_raw[CPE_CHANNELS]; /* raw aEn for local relative energy estimation */ float ave_ener_L; /* average energy of the L channel */ float ave_ener_R; /* average energy of the R channel */ float Etot_dn; /* average energy in dB - lower bound */ @@ -512,26 +671,60 @@ typedef struct ivas_stereo_classifier_data_structure float relE_0_1; /* relative energy in the current frame normalized to (0,1) */ float relE_0_1_LT; - int16_t unclr_sw_enable_cnt[CPE_CHANNELS]; /* UNCLR classifier - counter of frames suitable for UNCLR switching */ + Word16 unclr_sw_enable_cnt[CPE_CHANNELS]; /* UNCLR classifier - counter of frames suitable for UNCLR switching */ float unclr_relE_0_1_LT[UNCLR_RC_ORDER]; float unclr_wscore; - int16_t unclr_decision; /* UNCLR stereo classifier decision (0/1) */ + Word16 unclr_decision; /* UNCLR stereo classifier decision (0/1) */ float unclr_fv[SSC_MAX_NFEA]; /* UNCLR - feature vector */ - int16_t unclr_corrLagMax_prev; + Word16 unclr_corrLagMax_prev; float xtalk_score_buf[XTALK_SCORE_BUF_LEN]; - int16_t xtalk_decision; /* xtalk stereo classifier decision (0/1) */ + Word16 xtalk_decision; /* xtalk stereo classifier decision (0/1) */ float xtalk_fv[SSC_MAX_NFEA]; /* xtalk - feature vector */ float xtalk_wscore; float xtalk_score; float xtalk_score_wrelE; - int16_t lrtd_mode; - int16_t prev_lrtd_mode; + Word16 lrtd_mode; + Word16 prev_lrtd_mode; float is_speech; - int16_t silence_flag; + Word16 silence_flag; + + + //Above needs to remove once everything done + Word32 voicing_ch1_fx[3]; + Word32 cor_map_sum_ch1_fx; + Word32 lsf_ch1_fx[M]; + Word32 lepsP_ch1_fx; + Word32 dE1_ch1_fx, dE1_ch2_fx; + Word32 nchar_ch1_fx, nchar_ch2_fx; + Word32 non_sta_ch1_fx; + Word32 sp_div_ch1_fx; + Word32 ps_diff_ch1_fx, ps_diff_ch2_fx; + Word32 ps_sta_ch1_fx, ps_sta_ch2_fx; + Word32 prev_g_IPD_fx; + Word32 prev_IPD_fx; + Word32 prev_ratio_m1_m2_fx; + Word32 ratio_L_fx; + Word32 ave_ener_L_fx; /* average energy of the L channel */ + Word32 ave_ener_R_fx; /* average energy of the R channel */ + Word32 Etot_dn_fx; /* average energy in dB - lower bound */ + Word32 Etot_up_fx; /* average energy in dB - upper bound */ + Word32 relE_buf_fx[UNCLR_L_RELE]; /* running buffer for relative energy */ + Word32 Etot_buf_fx[UNCLR_L_ETOT]; /* running buffer for average energy in dB */ + Word32 relE_0_1_fx; /* relative energy in the current frame normalized to (0,1) */ + Word32 relE_0_1_LT_fx; + Word32 unclr_relE_0_1_LT_fx[UNCLR_RC_ORDER]; + Word32 unclr_wscore_fx; + Word32 unclr_fv_fx[SSC_MAX_NFEA]; /* UNCLR - feature vector */ + Word32 xtalk_score_buf_fx[XTALK_SCORE_BUF_LEN]; + Word32 xtalk_fv_fx[SSC_MAX_NFEA]; /* xtalk - feature vector */ + Word32 xtalk_wscore_fx; + Word32 xtalk_score_fx; + Word32 xtalk_score_wrelE_fx; + Word32 is_speech_fx; } STEREO_CLASSIF_DATA, *STEREO_CLASSIF_HANDLE; @@ -560,16 +753,21 @@ typedef struct front_vad_enc { int16_t ini_frame; /* initialization frames counter */ float lp_speech; /* long term speech average */ + Word16 lp_speech_fx; /* Q9 long term speech average */ float lp_noise; /* long term noise average */ + Word16 lp_noise_fx; /* long term noise average */ float mem_decim[2 * L_FILT_MAX]; /* decimation filter memory */ float buffer_12k8[3 * L_FRAME / 2]; /* 12k8 signal buffer */ float mem_preemph; /* preemph filter memory */ + Word16 mem_preemph_fx; /* preemph filter memory */ NOISE_EST_HANDLE hNoiseEst; /* Noise estimation handle */ VAD_HANDLE hVAD; /* VAD handle */ float *delay_buf; + Word16 *delay_buf_fx; int16_t delay_samples; int16_t rem_dtx_ho; /* Remaining hangover frames */ - + Word32 mem_decim_fx[2 * L_FILT_MAX]; /* decimation filter memory */ + Word32 buffer_12k8_fx[3 * L_FRAME / 2]; /* 12k8 signal buffer */ } FRONT_VAD_ENC, *FRONT_VAD_ENC_HANDLE; @@ -656,18 +854,20 @@ typedef struct ivas_spar_md_enc_state_t { ivas_spar_md_t spar_md; ivas_spar_md_prev_t spar_md_prior; - int16_t num_umx_ch; - int16_t num_decorr; + Word16 num_umx_ch; + Word16 num_decorr; float ***mixer_mat; float ***mixer_mat_local; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; - int16_t table_idx; - int16_t spar_hoa_md_flag; - int16_t spar_hoa_dirac2spar_md_flag; - int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]; + Word16 table_idx; + Word16 spar_hoa_md_flag; + Word16 spar_hoa_dirac2spar_md_flag; + Word16 HOA_md_ind[IVAS_SPAR_MAX_CH]; + Word32 ***mixer_mat_fx; + Word32 ***mixer_mat_local_fx; } ivas_spar_md_enc_state_t; /* PCA structure */ @@ -941,18 +1141,21 @@ typedef struct ivas_osba_enc_data_structure typedef struct stereo_cng_enc { - int16_t prev_sg_average_counter; /* Counter for sidegain averaging */ - int16_t sg_active_cnt; /* Counter for sidegain averaging */ - int16_t sg_average_counter; /* Counter for sidegain averaging */ + Word16 prev_sg_average_counter; /* Counter for sidegain averaging */ + Word16 sg_active_cnt; /* Counter for sidegain averaging */ + Word16 sg_average_counter; /* Counter for sidegain averaging */ float sg_average[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ float prev_sg_average[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ float mem_cohBand[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ float prev_cohBand[2 * ( STEREO_DFT_BAND_MAX / 2 )]; /* Previous coherence */ - int16_t cng_counter; /* Counter for cng period length */ - int16_t td_active; /* TD-stereo indication */ - int16_t first_SID_after_TD; /* Set if first SID frame after TD stereo */ - int16_t first_SID; /* Set if first SID frame since codec start */ - + Word16 cng_counter; /* Counter for cng period length */ + Word16 td_active; /* TD-stereo indication */ + Word16 first_SID_after_TD; /* Set if first SID frame after TD stereo */ + Word16 first_SID; /* Set if first SID frame since codec start */ + Word32 sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Sidegain average */ + Word32 prev_sg_average_fx[STEREO_DFT_ERB4_BANDS]; /* Previous sidegain average */ + Word32 mem_cohBand_fx[STEREO_DFT_BAND_MAX / 2]; /* Coherence memory */ + Word32 prev_cohBand_fx[2 * (STEREO_DFT_BAND_MAX / 2)]; /* Previous coherence */ } STEREO_CNG_ENC, *STEREO_CNG_ENC_HANDLE; @@ -962,9 +1165,9 @@ typedef struct stereo_cng_enc typedef struct sce_enc_data_structure { - int16_t sce_id; /* SCE # identifier */ - int32_t element_brate; /* SCE element total bitrate in bps */ - int32_t last_element_brate; /* last SCE element bitrate in bps */ + Word16 sce_id; /* SCE # identifier */ + Word32 element_brate; /* SCE element total bitrate in bps */ + Word32 last_element_brate; /* last SCE element bitrate in bps */ BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */ @@ -978,12 +1181,12 @@ typedef struct sce_enc_data_structure typedef struct cpe_enc_data_structure { - int16_t cpe_id; /* CPE # identifier */ + Word16 cpe_id; /* CPE # identifier */ - int32_t element_brate; /* CPE element total bitrate in bps */ - int32_t last_element_brate; /* last CPE element total bitrate in bps */ - int16_t element_mode; /* element mode, in CPE it can be IVAS_CPE_DFT, IVAS_CPE_TD or IVAS_CPE_MDCT */ - int16_t last_element_mode; /* last element mode */ + Word32 element_brate; /* CPE element total bitrate in bps */ + Word32 last_element_brate; /* last CPE element total bitrate in bps */ + Word16 element_mode; /* element mode, in CPE it can be IVAS_CPE_DFT, IVAS_CPE_TD or IVAS_CPE_MDCT */ + Word16 last_element_mode; /* last element mode */ BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */ @@ -1001,8 +1204,8 @@ typedef struct cpe_enc_data_structure float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ - int32_t brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ - + Word32 brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ + Word32 *input_mem_fx[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ } CPE_ENC_DATA, *CPE_ENC_HANDLE; @@ -1141,37 +1344,37 @@ typedef struct ivas_lfe_enc_data_structure typedef struct encoder_config_structure { - int32_t ivas_total_brate; /* IVAS total bitrate in bps */ - int32_t last_ivas_total_brate; /* IVAS last total bitrate in bps */ - int32_t input_Fs; /* input signal sampling frequency in Hz */ - int16_t nchan_inp; /* number of input audio channels */ - int16_t max_bwidth; /* maximum encoded bandwidth */ + Word32 ivas_total_brate; /* IVAS total bitrate in bps */ + Word32 last_ivas_total_brate; /* IVAS last total bitrate in bps */ + Word32 input_Fs; /* input signal sampling frequency in Hz */ + Word16 nchan_inp; /* number of input audio channels */ + Word16 max_bwidth; /* maximum encoded bandwidth */ IVAS_FORMAT ivas_format; /* IVAS format */ - int16_t is_binaural; /* flag indicating if input is binaural audio */ + Word16 is_binaural; /* flag indicating if input is binaural audio */ - int16_t element_mode_init; /* element mode used at initialization */ - int16_t stereo_dmx_evs; /* flag to indicate that stereo downmix for EVS encoder */ - int16_t nchan_ism; /* number of ISM channels */ - int16_t sba_order; /* Ambisonic (SBA) order */ - int16_t sba_planar; /* Ambisonic (SBA) planar flag */ + Word16 element_mode_init; /* element mode used at initialization */ + Word16 stereo_dmx_evs; /* flag to indicate that stereo downmix for EVS encoder */ + Word16 nchan_ism; /* number of ISM channels */ + Word16 sba_order; /* Ambisonic (SBA) order */ + Word16 sba_planar; /* Ambisonic (SBA) planar flag */ MC_LS_SETUP mc_input_setup; /* multichannel input ls setup */ - int16_t ism_extended_metadata_flag; /* flag indicating extended metadata encoding, including radius and orientation (yaw, pitch) in ISM format */ + Word16 ism_extended_metadata_flag; /* flag indicating extended metadata encoding, including radius and orientation (yaw, pitch) in ISM format */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_DTX_ON; /* flag indicating DTX operation */ - int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ - int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + Word16 Opt_DTX_ON; /* flag indicating DTX operation */ + Word16 interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + Word16 var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ - int16_t Opt_RF_ON; /* flag indicating RF (channel-aware) mode */ - int16_t rf_fec_offset; /* RF FEC offset */ - int16_t rf_fec_indicator; /* RF FEC indicator */ + Word16 Opt_RF_ON; /* flag indicating RF (channel-aware) mode */ + Word16 rf_fec_offset; /* RF FEC offset */ + Word16 rf_fec_indicator; /* RF FEC indicator */ - int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ - int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ + Word16 Opt_SC_VBR; /* flag indicating SC-VBR mode */ + Word16 last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ /* temp. development parameters */ - int16_t Opt_PCA_ON; /* flag indicating PCA operation in SBA */ + Word16 Opt_PCA_ON; /* flag indicating PCA operation in SBA */ } ENCODER_CONFIG, *ENCODER_CONFIG_HANDLE; @@ -1190,20 +1393,20 @@ typedef struct float *p_data_f[MAX_INPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point input audio buffers */ Indice *ind_list; /* List of indices */ - int16_t ivas_max_num_indices; /* Maximum allowed number of indices in the list */ + Word16 ivas_max_num_indices; /* Maximum allowed number of indices in the list */ Indice *ind_list_metadata; /* List of indices for metadata */ - int16_t ivas_max_num_indices_metadata; /* Maximum allowed number of indices in the list of metadata */ + Word16 ivas_max_num_indices_metadata; /* Maximum allowed number of indices in the list of metadata */ /* high-level encoder parameters */ - int16_t nchan_transport; /* number of transport channels */ - int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ - int16_t codec_mode; /* Mode1 or Mode2 of core codec */ - int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ + Word16 nchan_transport; /* number of transport channels */ + Word16 sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ + Word16 codec_mode; /* Mode1 or Mode2 of core codec */ + Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ float **mem_hp20_in; /* input signals HP filter memories */ /* core-encoder modules */ - int16_t nSCE; /* number of total SCEs */ - int16_t nCPE; /* number of total CPEs */ + Word16 nSCE; /* number of total SCEs */ + Word16 nCPE; /* number of total CPEs */ SCE_ENC_HANDLE hSCE[MAX_SCE]; /* SCE handles */ CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS]; /* CPE handles */ diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 58a63189109bf2d00ec455531856f4df6131473a..b0cf30923bd46f45040ea54779351b7f92e1f271 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -41,6 +41,7 @@ #include "ivas_rom_enc.h" #include "ivas_cnst.h" #include "wmc_auto.h" +#include "prot_fx1.h" /*-------------------------------------------------------------------* @@ -280,8 +281,72 @@ void stereo_classifier_init( return; } - - +#ifdef IVAS_FLOAT_FIXED +void stereo_classifier_init_fx( + STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ +) +{ + /* initialization of features for xtalk classifier and UNCLR classifier */ + hStereoClassif->clas_ch1 = 0; + set_zero_fx(hStereoClassif->pitch_ch1, 3); + set_zero_fx(hStereoClassif->voicing_ch1_fx, 3); + hStereoClassif->cor_map_sum_ch1_fx = 0; + set_zero_fx(hStereoClassif->lsf_ch1_fx, M); + hStereoClassif->lepsP_ch1_fx = 0; + hStereoClassif->dE1_ch1_fx = 0; + hStereoClassif->dE1_ch2_fx = 0; + hStereoClassif->nchar_ch1_fx = 0; + hStereoClassif->nchar_ch2_fx = 0; + hStereoClassif->non_sta_ch1_fx = 0; + hStereoClassif->sp_div_ch1_fx = 0; + hStereoClassif->ps_diff_ch1_fx = 0; + hStereoClassif->ps_diff_ch2_fx = 0; + hStereoClassif->ps_sta_ch1_fx = 0; + hStereoClassif->ps_sta_ch2_fx = 0; + hStereoClassif->prev_g_IPD_fx = 1073741824; //Q31 + hStereoClassif->prev_IPD_fx = 0; + hStereoClassif->prev_ratio_m1_m2_fx = 0; + set_zero_fx(hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN); + hStereoClassif->ratio_L_fx = 1073741824; //Q31 + hStereoClassif->vad_flag_glob = 0; //Q31 + hStereoClassif->vad_relE = 0; //Q31 + hStereoClassif->is_speech_fx = 0; //Q31 + + set_zero_fx(hStereoClassif->aEn_raw, CPE_CHANNELS); + + hStereoClassif->Etot_dn_fx = 0; + hStereoClassif->Etot_up_fx = 0; + + set_zero_fx(hStereoClassif->relE_buf_fx, UNCLR_L_RELE); + set_zero_fx(hStereoClassif->Etot_buf_fx, UNCLR_L_ETOT); + set_zero_fx(hStereoClassif->unclr_relE_0_1_LT_fx, UNCLR_RC_ORDER); + + hStereoClassif->unclr_sw_enable_cnt[0] = 0; + hStereoClassif->unclr_sw_enable_cnt[1] = 0; + + hStereoClassif->unclr_decision = 0; + hStereoClassif->unclr_wscore_fx = 0; + + set32_fx(hStereoClassif->unclr_fv_fx, -2147483648, SSC_MAX_NFEA);//Q31 + hStereoClassif->unclr_corrLagMax_prev = 0; + hStereoClassif->ave_ener_L = 0; + hStereoClassif->ave_ener_R = 0; + hStereoClassif->relE_0_1_fx = 21474836; //Q31 + hStereoClassif->relE_0_1_LT_fx = 21474836; //Q31 + + set32_fx(hStereoClassif->xtalk_fv_fx, -2147483648, SSC_MAX_NFEA);//Q31 + hStereoClassif->xtalk_wscore_fx = 0; + hStereoClassif->xtalk_decision = 0; + hStereoClassif->xtalk_score_wrelE_fx = 0; + + hStereoClassif->lrtd_mode = 0; + hStereoClassif->prev_lrtd_mode = 0; + + hStereoClassif->silence_flag = 0; + + return; +} +#endif /*-----------------------------------------------------------------* * stereo_classifier_features() * diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 3f1fdfec7643b3b77a50d8940a3dad47aa672b5a..33c087e77354549f31a4a4f576ead7ae849e1288 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -41,6 +41,7 @@ #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#include "prot_fx1.h" /*------------------------------------------------------------------- @@ -461,12 +462,22 @@ void stereo_enc_cng_init( { hStereoCng->sg_average_counter = 0; set_zero( hStereoCng->sg_average, STEREO_DFT_BAND_MAX ); +#ifdef IVAS_FLOAT_FIXED + set32_fx(hStereoCng->sg_average_fx, 0, STEREO_DFT_BAND_MAX); +#endif hStereoCng->prev_sg_average_counter = 0; set_zero( hStereoCng->prev_sg_average, STEREO_DFT_BAND_MAX ); +#ifdef IVAS_FLOAT_FIXED + set32_fx(hStereoCng->prev_sg_average_fx, 0, STEREO_DFT_BAND_MAX); +#endif hStereoCng->sg_active_cnt = 0; hStereoCng->first_SID = 1; - set_f( hStereoCng->mem_cohBand, 0.5f, STEREO_DFT_BAND_MAX / 2 ); + set_f( hStereoCng->mem_cohBand, 0.5f, STEREO_DFT_BAND_MAX / 2 ); /*Q31*/ set_zero( hStereoCng->prev_cohBand, 2 * ( STEREO_DFT_BAND_MAX / 2 ) ); +#ifdef IVAS_FLOAT_FIXED + set32_fx(hStereoCng->mem_cohBand_fx, ONE_IN_Q30, STEREO_DFT_BAND_MAX / 2); + set32_fx(hStereoCng->prev_cohBand_fx, 0, 2 * (STEREO_DFT_BAND_MAX / 2)); +#endif hStereoCng->td_active = 0; hStereoCng->first_SID_after_TD = 1; hStereoCng->cng_counter = 0; diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 18be391aa67f470f6b080fd9f3920154ada38497..5d8dea5ff755a97e170bde9743f1f43f408a91ee 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -39,8 +39,11 @@ #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" +#include "prot_fx2.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" @@ -61,6 +64,7 @@ *------------------------------------------------------------------------*/ static void stereo_dft_enc_open( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, const int32_t input_Fs, const int16_t max_bwidth ); +static void stereo_dft_enc_open_fx( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, const Word32 input_Fs, const Word16 max_bwidth ); static void stereo_dft_enc_compute_prm( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, float *DFT_L, float *DFT_R, int16_t k_offset, int16_t flag_quant, const int16_t sp_aud_decision0, const int16_t vad_flag, float *bin_nrgL, float *bin_nrgR, float *dot_prod_nrg_ratio ); @@ -286,8 +290,50 @@ ivas_error stereo_dft_enc_create( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +ivas_error stereo_dft_enc_create_fx( + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* i/o: encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +) +{ + STEREO_DFT_ENC_DATA_HANDLE hStereoDft_loc; + Word16 tmpS; + + IF (*hStereoDft != NULL) + { + return IVAS_ERROR(IVAS_ERR_INTERNAL_FATAL, "Error: DFT Stereo memory already allocated\n"); + } + + IF ((hStereoDft_loc = (STEREO_DFT_ENC_DATA_HANDLE)malloc(sizeof(STEREO_DFT_ENC_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo\n")); + } + + IF ((hStereoDft_loc->hConfig = (STEREO_DFT_CONFIG_DATA_HANDLE)malloc(sizeof(STEREO_DFT_CONFIG_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT Stereo Config\n")); + } + + IF ((hStereoDft_loc->hItd = (ITD_DATA_HANDLE)malloc(sizeof(ITD_DATA))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n")); + } + + hStereoDft_loc->hConfig->force_mono_transmission = 0; + stereo_dft_config_fx(hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS); + stereo_dft_enc_open_fx(hStereoDft_loc, input_Fs, max_bwidth); + + stereo_dft_hybrid_ITD_flag(hStereoDft_loc->hConfig, input_Fs, + hStereoDft_loc->hItd->hybrid_itd_max); + + *hStereoDft = hStereoDft_loc; + + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------- * stereo_dft_enc_open() * @@ -389,7 +435,121 @@ static void stereo_dft_enc_open( return; } - +#ifdef IVAS_FLOAT_FIXED +static void stereo_dft_enc_open_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +) +{ + Word16 NFFT_inner; + PWord16 win_p[STEREO_DFT_OVL_MAX]; + Word16 win[STEREO_DFT_OVL_MAX]; + + /*Sizes*/ + Word16 div_e; + Word16 input_Fs_48k = BASOP_Util_Divide3232_Scale(input_Fs, 48000, &div_e); + + //input_Fs_48k = shr(input_Fs_48k, sub(15, div_e)); + + hStereoDft->N = i_mult(STEREO_DFT_HOP_MAX_ENC, input_Fs_48k);//e = div_e + assert(((input_Fs / FRAMES_PER_SEC) / hStereoDft->N) == 1); + + /*Init. DFT sizes*/ + hStereoDft->NFFT = i_mult(STEREO_DFT_N_MAX_ENC, input_Fs_48k);//e = div_e + hStereoDft->dft_ovl = i_mult(STEREO_DFT_OVL_MAX, input_Fs_48k);//e = div_e + mdct_window_sine_IVAS_updated(win_p, input_Fs, hStereoDft->dft_ovl, FULL_OVERLAP, IVAS_CPE_DFT);//win_e = 15 + FOR (Word16 i = 0; i < shr(STEREO_DFT_OVL_MAX, 1); i++) + { + win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; + win[i] = win_p[i].v.im; + } + hStereoDft->win_ana_energy_fx = sub(hStereoDft->N, hStereoDft->dft_ovl); //e = div_e + hStereoDft->win_ana_energy_fx = shr(hStereoDft->win_ana_energy_fx, sub(15, div_e));//Q = 15 + + hStereoDft->win_ana_energy_fx = add(hStereoDft->win_ana_energy_fx, shl(sum_s(win, hStereoDft->dft_ovl), 1));//Q = 15 + hStereoDft->win_ana_energy_fx = shr(hStereoDft->win_ana_energy_fx, 15); + hStereoDft->win_ana_energy_fx = div_s(hStereoDft->win_ana_energy_fx, hStereoDft->NFFT);//Q = 15 + + set32_fx(hStereoDft->output_mem_dmx_32k_fx, 0, STEREO_DFT_OVL_32k); + + hStereoDft->dft_zp = (int16_t)(STEREO_DFT_ZP_MAX_ENC * input_Fs / 48000); + + hStereoDft->dft_trigo_8k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_12k8_fx = dft_trigo_12k8_fx; + hStereoDft->dft_trigo_16k_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_32k_fx = dft_trigo_32k_fx; + + hStereoDft->win_ana_8k_fx = win_ana_8k_fx; + hStereoDft->win_ana_12k8_fx = win_ana_12k8_fx; + hStereoDft->win_ana_16k_fx = win_ana_16k_fx; + hStereoDft->win_ana_32k_fx = win_ana_32k_fx; + + hStereoDft->win_8k_fx = win_syn_8k_fx; + hStereoDft->win_12k8_fx = win_syn_12k8_fx; + hStereoDft->win_16k_fx = win_syn_16k_fx; + hStereoDft->win_32k_fx = win_syn_32k_fx; + + IF (EQ_32(input_Fs, 16000)) + { + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hStereoDft->win_ana_fx = win_ana_16k_fx; + hStereoDft->win_fx = win_syn_16k_fx; + } + ELSE IF (EQ_32(input_Fs, 32000)) + { + hStereoDft->dft_trigo_fx = dft_trigo_32k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hStereoDft->win_ana_fx = win_ana_32k_fx; + hStereoDft->win_fx = win_syn_32k_fx; + } + ELSE + { + assert(EQ_32(input_Fs, 48000)); + hStereoDft->dft_trigo_fx = dft_trigo_48k_fx; + hStereoDft->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hStereoDft->win_ana_fx = win_ana_48k_fx; + hStereoDft->win_fx = win_syn_48k_fx; + } + + hStereoDft->win_mdct_8k_fx = win_mdct_8k_fx; + + /*I/O Buffers*/ + set_zero_fx(hStereoDft->output_mem_dmx_fx, STEREO_DFT_OVL_MAX); + set_zero_fx(hStereoDft->output_mem_dmx_12k8_fx, STEREO_DFT_OVL_12k8); + set_zero_fx(hStereoDft->output_mem_dmx_16k_fx, STEREO_DFT_OVL_16k); + set_zero_fx(hStereoDft->output_mem_dmx_16k_shb_fx, STEREO_DFT_OVL_16k); + set_zero_fx(hStereoDft->output_mem_res_8k_fx, STEREO_DFT_OVL_8k); + + /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ + + Word16 inner_frame_tbl_L_frame = BASOP_Util_Divide1616_Scale(inner_frame_tbl[max_bwidth], L_FRAME48k, &div_e); + inner_frame_tbl_L_frame = shr(inner_frame_tbl_L_frame, sub(15, div_e)); + + NFFT_inner = i_mult(STEREO_DFT_N_MAX_ENC, inner_frame_tbl_L_frame); + hStereoDft->nbands = stereo_dft_band_config_fx(hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC); + hStereoDft->nbands_dmx = stereo_dft_band_config_fx(hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC); + + /*Set configuration*/ + set16_fx(hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB); + IF (hStereoDft->hConfig->ada_wb_res_cod_mode && EQ_16(hStereoDft->NFFT, STEREO_DFT_N_16k_ENC)) + { + /* residual coding is only applied for 16 kHz sampling rate */ + set16_fx(hStereoDft->res_cod_mode, hStereoDft->hConfig->ada_wb_res_cod_mode, STEREO_DFT_ENC_DFT_NB); + } + ELSE + { + set16_fx(hStereoDft->res_cod_mode, hStereoDft->hConfig->res_cod_mode, STEREO_DFT_ENC_DFT_NB); + } + set16_fx(hStereoDft->res_pred_mode, hStereoDft->hConfig->res_pred_mode, STEREO_DFT_ENC_DFT_NB); + + /* reset DFT stereo memories */ + stereo_dft_enc_reset_fx(hStereoDft); + + return; +} +#endif /*------------------------------------------------------------------------- * stereo_dft_enc_reset() * @@ -497,8 +657,109 @@ void stereo_dft_enc_reset( return; } - - +#ifdef IVAS_FLOAT_FIXED +void stereo_dft_enc_reset_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ +) +{ + Word16 i; + /*reset parameters*/ + set_zero_fx(hStereoDft->side_gain_fx, i_mult(STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX)); + set16_fx(hStereoDft->side_gain_index_EC, 15, STEREO_DFT_BAND_MAX); + set16_fx(hStereoDft->side_gain_index_ECDiff, 0, STEREO_DFT_BAND_MAX); + set16_fx(hStereoDft->side_gain_index_ECprevious, 15, STEREO_DFT_BAND_MAX); + hStereoDft->side_gain_counter = 0; + hStereoDft->side_gain_bitdiff_lp_fx = STEREO_DFT_BITDIFF_INIT_FX; + set_zero_fx(hStereoDft->gipd_fx, STEREO_DFT_ENC_DFT_NB); + set_zero_fx(hStereoDft->dot_prod_real_smooth_fx, STEREO_DFT_BAND_MAX); + set_zero_fx(hStereoDft->dot_prod_img_smooth_fx, STEREO_DFT_BAND_MAX); + for (i = 0; i < STEREO_DFT_BAND_MAX; i++) + { + set_zero_fx(hStereoDft->ipd_buf_fx[i], STEREO_DFT_IPD_BUF_LEN); + } + hStereoDft->prev_gipd_fx = 0; + hStereoDft->gipd_index = 0; + set_zero_fx(hStereoDft->res_pred_gain_fx, i_mult(STEREO_DFT_ENC_DFT_NB, STEREO_DFT_BAND_MAX)); + set16_fx(hStereoDft->res_pred_index_EC, 0, STEREO_DFT_BAND_MAX); + set16_fx(hStereoDft->res_pred_index_ECDiff, 0, STEREO_DFT_BAND_MAX); + set16_fx(hStereoDft->res_pred_index_ECprevious, 0, STEREO_DFT_BAND_MAX); + hStereoDft->res_pred_counter = 0; + set_zero_fx(hStereoDft->past_nrgL_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); + set_zero_fx(hStereoDft->past_nrgR_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); + set_zero_fx(hStereoDft->past_dot_prod_real_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); + set_zero_fx(hStereoDft->past_dot_prod_imag_fx, i_mult(STEREO_DFT_NRG_PAST_LEN, STEREO_DFT_BAND_MAX)); + hStereoDft->nrg_past_pos = 0; + + hStereoDft->res_dmx_ratio_lt_fx = MAX_32; + hStereoDft->hangover_cnt0 = 0; + hStereoDft->hangover_cnt1 = 0; + hStereoDft->dmx_res_all_prev_fx = 1; + hStereoDft->last_res_cod_mode_modify_flag = 0; + hStereoDft->res_cod_sw_flag = 0; + hStereoDft->switch_fade_factor_fx = ONE_IN_Q14; //Q15/2 + hStereoDft->res_cod_mode[STEREO_DFT_OFFSET - 1] = STEREO_DFT_RES_COD_1kHz; + FOR (i = 0; i < STEREO_DFT_BAND_MAX; i++) + { + hStereoDft->res_cod_NRG_M_fx[i] = 0; + hStereoDft->res_cod_NRG_S_fx[i] = 0; + } + hStereoDft->old_snr_fx = 0; + + + hStereoDft->reverb_flag = 0; + set_zero_fx(hStereoDft->pre_sub_nrg_DMX_fx, STEREO_DFT_BAND_MAX); + hStereoDft->diff_l_h_sm_fx = 0; + hStereoDft->diff_r_h_sm_fx = 0; + hStereoDft->prev_fac2_fx = MAX_32; + + set_zero_fx(hStereoDft->res_pred_gain_f_fx, STEREO_DFT_BAND_MAX); + + /*misc*/ + hStereoDft->no_ipd_flag = 1; /* Initialization of the no IPD variables */ + hStereoDft->prev_no_ipd_flag = 1; + hStereoDft->no_ipd_cnt = 0; + hStereoDft->no_ipd_cnt1 = 0; + hStereoDft->attackPresent = 0; + hStereoDft->wasTransient = 0; + hStereoDft->gainIPD_sm_fx = MAX_32; + + + hStereoDft->voicing_lt_fx = 0; + + hStereoDft->flip_sign = 1; + + hStereoDft->sfm_fx = 0; + hStereoDft->sum_dot_prod_real_fx = 0; + hStereoDft->sum_dot_prod_img_fx = 0; + + /*Coherence*/ + set32_fx(hStereoDft->xspec_smooth_fx, MAX_32, STEREO_DFT_N_32k_ENC); + set32_fx(hStereoDft->Spd_L_smooth_fx, MAX_32, shr(STEREO_DFT_N_32k_ENC, 1)); + set32_fx(hStereoDft->Spd_R_smooth_fx, MAX_32, shr(STEREO_DFT_N_32k_ENC, 1)); + + hStereoDft->currentNumUpdates = 0; + hStereoDft->expectedNumUpdates = FIXED_SID_RATE; + hStereoDft->resetFrames = 0; + hStereoDft->sid_gipd_fx = 0; + hStereoDft->prev_sid_gipd_fx = 0; + hStereoDft->prev_sid_no_ipd_flag = 1; + + hStereoDft->coh_fade_counter = 0; + + /* Xtalk classifier */ + hStereoDft->hItd->prev_m1_fx = 0; + hStereoDft->hItd->prev_m2_fx = 0; + hStereoDft->hItd->prev_itd1 = 0; + hStereoDft->hItd->prev_itd2 = 0; + + hStereoDft->first_frm_flag = 1; + + + stereo_enc_itd_init_fx(hStereoDft->hItd); + + return; +} +#endif /*------------------------------------------------------------------------- * stereo_enc_itd_init() * @@ -548,6 +809,48 @@ void stereo_enc_itd_init( return; } +void stereo_enc_itd_init_fx( + ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ +) +{ + hItd->prev_itd = 0; + set32_fx(hItd->itd_fx, 0, STEREO_DFT_ENC_DFT_NB); + set32_fx(hItd->deltaItd_fx, 0,STEREO_DFT_ENC_DFT_NB); + set16_fx(hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB); + set16_fx(hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB); + set16_fx(hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB); + set32_fx(hItd->xcorr_smooth_fx, 0, STEREO_DFT_N_32k_ENC); + hItd->lp_phat_peak_fx = 0; + hItd->itd_hangover = 0; + hItd->itd_cnt = 0; + hItd->prev_sum_nrg_L_lb_fx = 0; + set32_fx(hItd->prev_xcorr_lb_fx, 0, STEREO_DFT_XCORR_LB_MAX); + set32_fx(hItd->E_band_n_fx, ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM); + hItd->vad_frm_cnt = 0; + hItd->pre_vad = 0; + hItd->itd_nonzero_cnt = 0; + set32_fx(hItd->acorr_L_fx, 0, STEREO_DFT_BAND_MAX); + set32_fx(hItd->acorr_R_fx, 0, STEREO_DFT_BAND_MAX); + hItd->cohSNR_fx = 30720; /*Q11*/ + hItd->itd_thres_fx = 0; + hItd->valid_itd_cnt = 0; + + hItd->detected_itd_flag = 0; + hItd->itd_tracking = 0; + hItd->prev_max_fx = 0; + hItd->prev_index = 0; + hItd->prev_avg_max_fx = 0; + hItd->currFlatness_fx = 0; + + /* Xtalk classifier */ + hItd->prev_m1_fx = 0; + hItd->prev_m2_fx = 0; + hItd->prev_itd1 = 0; + hItd->prev_itd2 = 0; + + hItd->hybrid_itd_max = 0; + return; +} /*-------------------------------------------------------------------------- * stereo_dft_enc_update() @@ -631,13 +934,13 @@ void stereo_dft_enc_destroy( STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle */ ) { - if ( ( *hStereoDft )->hConfig != NULL ) + IF ( ( *hStereoDft )->hConfig != NULL ) { free( ( *hStereoDft )->hConfig ); ( *hStereoDft )->hConfig = NULL; } - if ( ( *hStereoDft )->hItd != NULL ) + IF ( ( *hStereoDft )->hItd != NULL ) { free( ( *hStereoDft )->hItd ); ( *hStereoDft )->hItd = NULL; diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index b1bc5ec02baecd7a7b80effce4200700ab42b0d0..77b46951ebd6351dd2254de4b0eac75600f8fded 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -111,22 +111,22 @@ static void set_band_limits( void stereo_dft_hybrid_ITD_flag( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ - const int32_t input_Fs, /* i : CPE element sampling rate */ - const int16_t hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ + const Word32 input_Fs, /* i : CPE element sampling rate */ + const Word16 hybrid_itd_max /* i : flag for hybrid ITD for very large ITDs */ ) { - if ( hConfig != NULL ) + IF ( hConfig != NULL ) { - if ( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && input_Fs == 16000 ) || ( hybrid_itd_max == 1 ) ) + IF ( hConfig->res_cod_mode || ( hConfig->ada_wb_res_cod_mode && EQ_32(input_Fs, 16000) ) || EQ_16( hybrid_itd_max, 1 ) ) { hConfig->hybrid_itd_flag = 1; } - else + ELSE { hConfig->hybrid_itd_flag = 0; } } - else + ELSE { assert( 0 && "Stereo Dft Config Data Handle is uninitialized" ); } diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 48e121b94462301ccb24d74888e2307b48e58253..85dc65140b287bac0791b2b8227019130a343720 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -41,7 +41,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" - +#include "prot_fx1.h" /*--------------------------------------------------------------- * Local function prototypes @@ -1281,7 +1281,53 @@ void stereo_tca_init_enc( return; } - +void stereo_tca_init_enc_fx( + STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ + const Word32 input_Fs /* i : input sampling frequency */ +) +{ + Word16 div1; + Word16 div_e; + hStereoTCA->lMemRecalc = NS2SA(input_Fs, L_MEM_RECALC_NS); + div1 = BASOP_Util_Divide3232_Scale(L_mult(hStereoTCA->lMemRecalc, INT_FS_12k8), input_Fs, &div_e); + hStereoTCA->lMemRecalc_12k8 = shr(div1, sub(15, div_e)); + + div1 = BASOP_Util_Divide3232_Scale(L_mult(hStereoTCA->lMemRecalc, INT_FS_16k), input_Fs, &div_e); + hStereoTCA->lMemRecalc_16k = shr(div1, sub(15, div_e)); + + hStereoTCA->refChanIndx = L_CH_INDX; + hStereoTCA->prevRefChanIndx = L_CH_INDX; + + hStereoTCA->targetGain = MAX16B; //Q15 + hStereoTCA->prevTargetGain_fx = MAX16B;//Q15 + hStereoTCA->instTargetGain_fx = MAX16B;//Q15 + hStereoTCA->corrStatsSmoothFac_fx = 22937;//Q15 + + set16_fx(hStereoTCA->corrLagStats, 0, 3); + set16_fx(hStereoTCA->prevCorrLagStats, 0, 3); + + set32_fx(hStereoTCA->memChanL_fx, 0, add(L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH)); + set32_fx(hStereoTCA->memChanR_fx, 0, add(L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH)); + set32_fx(hStereoTCA->memChanL_DS_fx, 0, ADDED_MEM_DS); + set32_fx(hStereoTCA->memChanR_DS_fx, 0, ADDED_MEM_DS); + hStereoTCA->mem_tempF_fx = 0.; + set32_fx(hStereoTCA->corrEstPrev_fx[0], 0, add(shl(L_NCSHIFT_DS, 1), 1)); + set32_fx(hStereoTCA->corrEstPrev_fx[1], 0, add(shl(L_NCSHIFT_DS, 1), 1)); + set32_fx(hStereoTCA->corrEstPrev_fx[2], 0, add(shl(L_NCSHIFT_DS, 1), 1)); + + set32_fx(hStereoTCA->corrEstLT_fx, 0, add(shl(L_NCSHIFT_DS, 1), 1)); + set32_fx(hStereoTCA->memdecim_fx, 0, 12); + hStereoTCA->ica_envVarLT_fx = 2097152000; //2000 in Q20 + + set32_fx(hStereoTCA->C_mem_fx, 0, add(shl(L_NCSHIFT_DS, 1), 1)); + hStereoTCA->E1_mem_fx = 0; + hStereoTCA->E2_mem_fx = 0; + set32_fx(hStereoTCA->delay_0_mem_fx, 0, MAX_DELAYREGLEN); + hStereoTCA->smooth_dist_reg_prv_corr_fx = MAX16B; //Q15 + hStereoTCA->LRTD_G_ATT_cnt = 1; + + return; +} /*-------------------------------------------------------------------* * Function unclr_calc_corr_features() * diff --git a/lib_enc/ivas_stereo_icbwe_enc.c b/lib_enc/ivas_stereo_icbwe_enc.c index 593bef2a937147a1695744da4a54264b68096cce..5563c3765ed85d1e088d08dafa4e3eaff3c3cedf 100644 --- a/lib_enc/ivas_stereo_icbwe_enc.c +++ b/lib_enc/ivas_stereo_icbwe_enc.c @@ -40,6 +40,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" +#include "prot_fx1.h" /*-------------------------------------------------------------------* * ic_bwe_enc_reset() @@ -620,7 +621,54 @@ void stereo_icBWE_init_enc( return; } +void stereo_icBWE_init_enc_fx( + STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ +) +{ + /* SHB speech resampler memory */ + set32_fx(hStereoICBWE->mem_decim_shb_ch0_fx, 0, shl(L_FILT_MAX, 1)); + + /* SHB ref channel */ + set32_fx(hStereoICBWE->mem_shb_speech_ref_fx, 0, L_LOOK_16k); + + /* SHB non-ref channel */ + set32_fx(hStereoICBWE->mem_shb_speech_nonref_fx, 0, L_LOOK_16k); + + /* unscaled & scaled SHB synthesis memory */ + set32_fx(hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 0, LPC_SHB_ORDER); + + /* inter-channel BWE spectral shape adj. */ + hStereoICBWE->prevSpecMapping_fx = 0; + hStereoICBWE->prevgsMapping_fx = MAX_32; //Q31 + set32_fx(&(hStereoICBWE->memShbSpecMapping_fx), 0, 1); + set32_fx(hStereoICBWE->memShbSpecXcorr_fx, 0, 6); + + hStereoICBWE->prevNonRefEner_fx = MAX_32; //Q31 + hStereoICBWE->prevRefEner_fx = MAX_32; //Q31 + set32_fx(hStereoICBWE->memGsEnerMap_fx, MAX_32, 2); //Q31 + + set32_fx(hStereoICBWE->dec_2over3_mem_fx, 0, L_FILT_2OVER3); + set32_fx(hStereoICBWE->dec_2over3_mem_lp_fx, 0, L_FILT_2OVER3_LP); + set32_fx(hStereoICBWE->memHPF_fx, 0, 8); + + /* BWE ref channel */ + hStereoICBWE->refChanIndx_bwe = L_CH_INDX; + hStereoICBWE->prev_refChanIndx_bwe = L_CH_INDX; + + set32_fx(hStereoICBWE->memModifyFs_icbwe_fx[0], 0, shl(L_FILT32k, 1)); + set32_fx(hStereoICBWE->memModifyFs_icbwe_fx[1], 0, shl(L_FILT32k, 1)); + + set32_fx(hStereoICBWE->mem_nrg_L_fx, 0, 2); + set32_fx(hStereoICBWE->mem_nrg_R_fx, 0, 2); + set32_fx(hStereoICBWE->mem_nrg_DMX_fx, 0, 2); + hStereoICBWE->gDes_pastFrame_fx = MAX_32; //Q31 + hStereoICBWE->icbweRefEner_fx = 0; + + hStereoICBWE->MSFlag = 0; + + return; +} /*-------------------------------------------------------------------* * findRefChanBWE() * diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 77aed8f3c4c2332a7c9d0ae2ef01c90b0edb62b3..d1196f44507232b2018266a8431498764991ce90 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -36,8 +36,11 @@ #include #include "ivas_cnst.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "prot.h" +#include "prot_fx1.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" #include "stat_enc.h" @@ -106,6 +109,45 @@ static void dft_ana_init( return; } +static void dft_ana_init_fx( + DFT_ANA_HANDLE hDft_ana, /*i : DFT analysis handle */ + const Word32 input_Fs /*i : Input sampling frequency */ +) +{ + Word16 div1; + Word16 div_e; + div1 = BASOP_Util_Divide3232_Scale(input_Fs, 48000, &div_e); + div1 = shr(div1, sub(15, div_e)); + + hDft_ana->N = i_mult(STEREO_DFT_HOP_MAX_ENC, div1); + hDft_ana->NFFT = i_mult(STEREO_DFT_N_MAX_ENC, div1); + hDft_ana->dft_ovl = i_mult(STEREO_DFT_OVL_MAX, div1); + hDft_ana->dft_zp = i_mult(STEREO_DFT_ZP_MAX_ENC, div1); + + hDft_ana->dft_trigo_32k_fx = dft_trigo_32k_fx; + + IF (EQ_32(input_Fs, 16000)) + { + hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP; + hDft_ana->win_ana_fx = win_ana_16k_fx; + } + ELSE IF (EQ_32(input_Fs, 32000)) + { + hDft_ana->dft_trigo_fx = dft_trigo_32k_fx; + hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_32k_STEP; + hDft_ana->win_ana_fx = win_ana_32k_fx; + } + ELSE + { + assert(EQ_32(input_Fs, 48000)); + hDft_ana->dft_trigo_fx = dft_trigo_48k_fx; + hDft_ana->dft_trigo_step = STEREO_DFT_TRIGO_SRATE_48k_STEP; + hDft_ana->win_ana_fx = win_ana_48k_fx; + } + + return; +} /*-------------------------------------------------------------------* * write_itd_data() @@ -1049,7 +1091,66 @@ void initMdctStereoEncData( return; } +#ifdef IVAS_FLOAT_FIXED +void initMdctStereoEncData_fx( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 element_mode, /* i : element mode */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 bwidth, /* i : bandwidth */ + const Word16 igf, /* i : flag indicating IGF activity */ + const H_IGF_GRID hIgfGrid, /* i : IGF grid setup */ + const Word16 mem_init /* i : initialize memory after malloc */ +) +{ + Word16 tcx_coded_lines; + + tcx_coded_lines = getNumTcxCodedLines(bwidth); + + /*initialize mdct stereo mode*/ + set16_fx(hStereoMdct->mdct_stereo_mode, -1, 2); + + /*Initialize sfb parameteres for TCX20 */ + stereo_mdct_init_bands_fx(tcx_coded_lines, TCX_20_CORE, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_NORM] : NULL, &hStereoMdct->stbParamsTCX20.sfbOffset[0], &hStereoMdct->stbParamsTCX20.sfbCnt); + + /*Initialize sfb parameteres for TCX10 */ + stereo_mdct_init_bands_fx(tcx_coded_lines, TCX_10_CORE, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_SHORT] : NULL, + &hStereoMdct->stbParamsTCX10.sfbOffset[0], &hStereoMdct->stbParamsTCX10.sfbCnt); + + /*Initialize sfb parameteres for transitions */ + stereo_mdct_init_bands_fx(tcx_coded_lines, -1, element_brate, igf, igf ? &hIgfGrid[IGF_GRID_LB_TRAN] : NULL, + &hStereoMdct->stbParamsTCX20afterACELP.sfbOffset[0], &hStereoMdct->stbParamsTCX20afterACELP.sfbCnt); + + set16_fx(hStereoMdct->IGFStereoMode, -1, 2); + + hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; + set16_fx(hStereoMdct->global_ild, shr(SMDCT_ILD_RANGE, 1), 2); + + IF (mem_init) + { + hStereoMdct->hItd = NULL; + hStereoMdct->hDft_ana = NULL; + } + + IF (!(element_mode == IVAS_CPE_MDCT && element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT)) + { + IF (hStereoMdct->hDft_ana != NULL) + { + free(hStereoMdct->hDft_ana); + hStereoMdct->hDft_ana = NULL; + } + + IF (hStereoMdct->hItd != NULL) + { + free(hStereoMdct->hItd); + hStereoMdct->hItd = NULL; + } + } + + return; +} +#endif /*-----------------------------------------------------------------------* * initMdctItdHandling() * @@ -1086,6 +1187,35 @@ ivas_error initMdctItdHandling( return IVAS_ERR_OK; } +ivas_error initMdctItdHandling_fx( + STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + IF ( hStereoMdct->hItd == NULL ) + { + IF ( ( hStereoMdct->hItd = (ITD_DATA_HANDLE) malloc( sizeof( ITD_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n" ) ); + } + } + + IF ( hStereoMdct->hDft_ana == NULL ) + { + IF ( ( hStereoMdct->hDft_ana = (DFT_ANA_HANDLE) malloc( sizeof( DFT_ANA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ITD data\n" ) ); + } + } + + /*Initialize ITD parameters*/ + stereo_enc_itd_init_fx( hStereoMdct->hItd ); + + /*Initialize DFT analysis parameters*/ + dft_ana_init_fx( hStereoMdct->hDft_ana, input_Fs ); + + return IVAS_ERR_OK; +} /*------------------------------------------------------------------------- * stereo_mdct_enc_destroy() * diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index e961eca8d4dda1eee08ebba2fe4f6bb2dfccdd9e..66c8612e5746b4150fb5bb3200ca35ec5a2bef61 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -130,6 +130,88 @@ void stereo_td_init_enc( return; } +void stereo_td_init_enc_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + const Word16 last_element_mode /* i : last element mode */ +) +{ + hStereoTD->tdm_lt_corr_RM_fx = 21474836; //Q31 + hStereoTD->tdm_lt_corr_LM_fx = 21474836; + hStereoTD->tdm_last_ratio_fx = 1073741824; //Q31 + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_lt_rms_L_fx = 671088640; //Q24 + hStereoTD->tdm_lt_rms_R_fx = 671088640; //Q24 + hStereoTD->tdm_last_diff_lt_corr_fx = 0; + hStereoTD->tdm_last_ener_lt_R_fx = 0; + hStereoTD->tdm_last_ener_lt_L_fx = 0; + + hStereoTD->tdm_ratio_transition_mov_flag = 0; + hStereoTD->tdm_ratio_transition_cnt = 0; + hStereoTD->tdm_noop_mov_flag = 0; + hStereoTD->tdm_noop_cnt = 0; + hStereoTD->tdm_last_SM_flag = 0; + + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_stable_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_desired_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_FD2LRTD_SW_cnt = 0; + hStereoTD->tdm_LT_es_em_fx = 214748364; //Q31 + hStereoTD->tdm_hyst_cnt = 0; + /* NOOP parameters */ + hStereoTD->tdm_lt_corr_RM_SM_fx = 21474836; //Q31 + hStereoTD->tdm_lt_corr_LM_SM_fx = 21474836; //Q31 + hStereoTD->tdm_last_ratio_SM_fx = 1073741824; //Q31 + hStereoTD->tdm_last_ratio_idx_SM = 0; + hStereoTD->tdm_lt_rms_L_SM_fx = 671088640; //Q24 + hStereoTD->tdm_lt_rms_R_SM_fx = 671088640; //Q24 + hStereoTD->tdm_last_diff_lt_corr_SM_fx = 0; + hStereoTD->tdm_last_ener_lt_R_SM_fx = 0; + hStereoTD->tdm_last_ener_lt_L_SM_fx = 0; + hStereoTD->tdm_noop_mov_flag = 0; + hStereoTD->tdm_NOOP_cnt = 0; + hStereoTD->tdm_last_SM_flag_noop = 0; + hStereoTD->tdm_last_ratio_idx_SM = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_stable_idx_SM = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_prev_desired_idx_SM = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_LT_es_em_SM_fx = 214748364; //Q31 + hStereoTD->tdm_hyst_cnt_SM = 0; + hStereoTD->tdm_noop_cnt = 0; + hStereoTD->tdm_SM_flag = 0; + hStereoTD->tdm_SM_last_clas[0] = VOICED_CLAS; + hStereoTD->tdm_SM_last_clas[1] = VOICED_CLAS; + hStereoTD->tdm_SM_last2_clas[0] = VOICED_CLAS; + hStereoTD->tdm_SM_last2_clas[1] = VOICED_CLAS; + hStereoTD->tdm_SM_modi_flag = 0; + hStereoTD->tdm_SM_reset_flag = 0; + hStereoTD->prev_fr_LRTD_TD_dec = 0; + hStereoTD->tdm_LRTD_flag = 0; + hStereoTD->tdm_inst_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM; + hStereoTD->tdm_last_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; + hStereoTD->tdm_last_LRTD_frame_cnt = 0; + hStereoTD->tdm_vad_hangover_cnt = 0; + hStereoTD->tdm_ini_frame_cnt = 0; + hStereoTD->tdm_last_LRTD_PriCh_cnt = 0; + + hStereoTD->flag_skip_DMX = 0; + IF (EQ_16(last_element_mode, IVAS_CPE_MDCT)) + { + hStereoTD->flag_skip_DMX = 1; + hStereoTD->prev_fr_LRTD_TD_dec = 1; + hStereoTD->tdm_last_ratio_fx = MAX_32; //Q31 + hStereoTD->tdm_last_ratio_idx = LRTD_STEREO_LEFT_IS_PRIM; + hStereoTD->tdm_prev_stable_idx = LRTD_STEREO_LEFT_IS_PRIM; + hStereoTD->tdm_prev_desired_idx = LRTD_STEREO_LEFT_IS_PRIM; + } + + hStereoTD->tdm_hBstr_tmp.ind_list = hStereoTD->tdm_ind_list_tmp; + hStereoTD->tdm_hBstr_tmp.ivas_ind_list_zero = (Indice **)(&hStereoTD->tdm_hBstr_tmp.ind_list); + hStereoTD->max_ind_tdm_tmp = MAX_IND_TDM_TMP; + hStereoTD->tdm_hBstr_tmp.ivas_max_num_indices = &hStereoTD->max_ind_tdm_tmp; + hStereoTD->tdm_hBstr_tmp.st_ivas = NULL; + reset_indices_enc(&hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP); + + return; +} /*-------------------------------------------------------------------* * stereo_set_tdm() diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 273fecc741ae0d12113d313ebbd37f9225081796..d1605a17e277f99c4e4e15a86e1f4321bfeff4ed 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -32,6 +32,7 @@ #include "lib_enc.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "prot.h" #include "prot_fx2.h" #include "prot_fx_enc.h" @@ -41,7 +42,7 @@ #include #include "wmc_auto.h" #include "options.h" - +#include "ivas_rom_enc.h" /*---------------------------------------------------------------------* * Local struct *---------------------------------------------------------------------*/ @@ -65,14 +66,19 @@ struct IVAS_ENC *---------------------------------------------------------------------*/ static ivas_error configureEncoder( IVAS_ENC_HANDLE hIvasEnc, const int32_t inputFs, const int32_t initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); +static ivas_error configureEncoder_fx( IVAS_ENC_HANDLE hIvasEnc, const Word32 inputFs, const Word32 initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); static ivas_error setBandwidth( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ); +static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ); static ivas_error setBitrate( IVAS_ENC_HANDLE hIvasEnc, const int32_t totalBitrate ); static ivas_error setChannelAwareConfig( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); +static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); +static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); +static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth ); @@ -148,7 +154,68 @@ ivas_error IVAS_ENC_Open( return IVAS_ERR_OK; } +ivas_error IVAS_ENC_Open_fx( + IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to an encoder handle to be opened */ +) +{ + Encoder_Struct *st_ivas; + + IF (phIvasEnc == NULL) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + /*-----------------------------------------------------------------* + * Allocate and initialize IVAS application encoder handle + *-----------------------------------------------------------------*/ + + IF ((*phIvasEnc = (IVAS_ENC_HANDLE)malloc(sizeof(struct IVAS_ENC))) == NULL) + { + return IVAS_ERR_FAILED_ALLOC; + } + + (*phIvasEnc)->hCoreCoder = NULL; + (*phIvasEnc)->isConfigured = false; + (*phIvasEnc)->switchingActive = false; + (*phIvasEnc)->maxBandwidthUser = false; + resetIsmMetadataProvidedFlags(*phIvasEnc); + + /*-----------------------------------------------------------------* + * Allocate IVAS-codec encoder state + *-----------------------------------------------------------------*/ + + IF (((*phIvasEnc)->st_ivas = (Encoder_Struct *)malloc(sizeof(Encoder_Struct))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure"); + } + + IF (((*phIvasEnc)->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE)malloc(sizeof(ENCODER_CONFIG))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure"); + } + + /*-----------------------------------------------------------------* + * Initialize IVAS-codec encoder state + *-----------------------------------------------------------------*/ + + st_ivas = (*phIvasEnc)->st_ivas; + + /* initialize encoder Config. handle */ + init_encoder_config(st_ivas->hEncoderConfig); + /* initialize pointers to handles to NULL */ + ivas_initialize_handles_enc(st_ivas); + + st_ivas->ind_list = NULL; + st_ivas->ind_list_metadata = NULL; + + /* set high-level parameters */ + st_ivas->mc_mode = MC_MODE_NONE; + st_ivas->ism_mode = ISM_MODE_NONE; + st_ivas->sba_analysis_order = 0; + + return IVAS_ERR_OK; +} /*---------------------------------------------------------------------* * IVAS_ENC_Close() * @@ -463,7 +530,48 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ + const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ + const bool Opt_PCA_ON /* i : PCA option flag */ +) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + IF ((error = doCommonConfigureChecks(hIvasEnc)) != IVAS_ERR_OK) + { + return error; + } + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + hEncoderConfig->ivas_format = SBA_FORMAT; + hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ + hEncoderConfig->sba_planar = isPlanar; + hEncoderConfig->sba_order = order; + + /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ + hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx(hEncoderConfig->sba_order, 0); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ + + hEncoderConfig->Opt_PCA_ON = (Word16)Opt_PCA_ON; + + hIvasEnc->maxBandwidthUser = max_bwidth_user; + + error = configureEncoder_fx(hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig()); + + + return error; +} +#endif /*---------------------------------------------------------------------* * IVAS_ENC_ConfigureForSBAObjects() * @@ -944,8 +1052,295 @@ static ivas_error configureEncoder( return error; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error configureEncoder_fx( + IVAS_ENC_HANDLE hIvasEnc, + const Word32 inputFs, + const Word32 initBitrate, + const IVAS_ENC_BANDWIDTH initBandwidth, + const IVAS_ENC_DTX_CONFIG dtxConfig, + const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig) +{ + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + Word32 cpe_brate; + + error = IVAS_ERR_OK; + + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; + + /*-----------------------------------------------------------------* + * Bandwidth limitation + *-----------------------------------------------------------------*/ + + IF ((error = setBandwidth_fx(hIvasEnc, initBandwidth)) != IVAS_ERR_OK) + { + return error; + } + + /*-----------------------------------------------------------------* + * DTX/CNG + *-----------------------------------------------------------------*/ + + IF (dtxConfig.enabled) + { + hEncoderConfig->Opt_DTX_ON = 1; + + IF (dtxConfig.variable_SID_rate) + { + hEncoderConfig->var_SID_rate_flag = 1; + hEncoderConfig->interval_SID = 0; + } + ELSE + { + hEncoderConfig->var_SID_rate_flag = 0; + + IF (GE_16(dtxConfig.SID_interval, 3) && LE_16(dtxConfig.SID_interval, 100)) + { + hEncoderConfig->interval_SID = dtxConfig.SID_interval; + } + ELSE + { + return IVAS_ERR_INVALID_DTX_UPDATE_RATE; + } + } + } + ELSE + { + hEncoderConfig->Opt_DTX_ON = 0; + } + + /*-----------------------------------------------------------------* + * Bitrate + *-----------------------------------------------------------------*/ + + hEncoderConfig->ivas_total_brate = initBitrate; + + /* SC-VBR at 5.90 kbps */ + IF (hEncoderConfig->ivas_total_brate == ACELP_5k90) + { + hEncoderConfig->ivas_total_brate = ACELP_7k20; + hEncoderConfig->Opt_SC_VBR = 1; + hEncoderConfig->last_Opt_SC_VBR = hEncoderConfig->Opt_SC_VBR; + + IF (NE_16(hEncoderConfig->max_bwidth, NB)) + { + hEncoderConfig->max_bwidth = WB; + } + } + + /* check if the entered bitrate is supported */ + IF (NE_16(hEncoderConfig->ivas_format, UNDEFINED_FORMAT) && NE_16(hEncoderConfig->ivas_format, MONO_FORMAT)) /* IVAS */ + { + IF (!is_IVAS_bitrate_fx(hEncoderConfig->ivas_total_brate)) + { + IF (hEncoderConfig->Opt_SC_VBR) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", ACELP_5k90); + } + ELSE + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", hEncoderConfig->ivas_total_brate); + } + } + + IF (hEncoderConfig->ivas_format == STEREO_FORMAT) + { + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + IF (hEncoderConfig->ivas_total_brate >= MIN_BRATE_MDCT_STEREO) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + } + + IF ((EQ_16(hEncoderConfig->element_mode_init, IVAS_CPE_TD) || EQ_32(hEncoderConfig->element_mode_init, IVAS_CPE_DFT)) && GT_32(hEncoderConfig->ivas_total_brate, IVAS_48k)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for TD/DFT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (EQ_16(hEncoderConfig->element_mode_init, IVAS_CPE_MDCT) && LT_32(hEncoderConfig->ivas_total_brate, IVAS_48k)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for MDCT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (LT_32(hEncoderConfig->ivas_total_brate, IVAS_256k)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + } + ELSE IF (EQ_16(hEncoderConfig->ivas_format, ISM_FORMAT)) + { + IF ((error = sanitizeBitrateISM_fx(hEncoderConfig, hIvasEnc->extMetadataApi)) != IVAS_ERR_OK) + { + return error; + } + } + ELSE IF (EQ_16(hEncoderConfig->ivas_format, SBA_FORMAT)) + { + /* nothing */ + } + ELSE IF (EQ_16(hEncoderConfig->ivas_format, MASA_FORMAT)) + { + /* adapt element_mode according to the bitrate */ + IF (EQ_16(hEncoderConfig->nchan_inp, 2) && NE_16(hEncoderConfig->element_mode_init, IVAS_SCE)) + { + IF (GE_32(hEncoderConfig->ivas_total_brate, IVAS_48k)) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + ELSE IF (LT_32(hEncoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE)) + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + } + } + ELSE IF (EQ_32(hEncoderConfig->ivas_format, MASA_ISM_FORMAT)) + { + st_ivas->ism_mode = ivas_omasa_ism_mode_select(st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism); + + cpe_brate = calculate_cpe_brate_MASA_ISM_fx(st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism); + + /*adapt element_mode according to the bit-rate*/ + IF (NE_16(hEncoderConfig->element_mode_init, IVAS_SCE)) + { + IF (GE_32(cpe_brate, IVAS_48k)) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + } + } + ELSE IF (EQ_16(hEncoderConfig->ivas_format, SBA_ISM_FORMAT)) + { + st_ivas->ism_mode = ISM_MODE_NONE; + } + } + ELSE /* EVS mono */ + { + hEncoderConfig->ivas_format = MONO_FORMAT; + hEncoderConfig->element_mode_init = EVS_MONO; + + IF (!is_EVS_bitrate(hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate); + } + + IF (EQ_16(hEncoderConfig->stereo_dmx_evs, 1)) + { + hEncoderConfig->nchan_inp = 2; + } + } + + /*-----------------------------------------------------------------* + * Input sampling frequency + *-----------------------------------------------------------------*/ + + IF (NE_32(inputFs, 8000) && NE_32(inputFs, 16000) && NE_32(inputFs, 32000) && NE_32(inputFs, 48000)) + { + return IVAS_ERR_INVALID_SAMPLING_RATE; + } + + hEncoderConfig->input_Fs = inputFs; + + /*-----------------------------------------------------------------* + * Channel-aware mode + *-----------------------------------------------------------------*/ + + IF ((error = setChannelAwareConfig_fx(hIvasEnc, caConfig)) != IVAS_ERR_OK) + { + return error; + } + + /*-----------------------------------------------------------------* + * Set codec mode + *-----------------------------------------------------------------*/ + + st_ivas->codec_mode = MODE1; /* Note: in IVAS, set MODE1 */ + IF (EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT)) + { + IF (hEncoderConfig->Opt_AMR_WB) + { + st_ivas->codec_mode = MODE1; + } + ELSE + { + st_ivas->codec_mode = get_codec_mode(hEncoderConfig->ivas_total_brate); + } + } + + IF (hEncoderConfig->ivas_total_brate == IVAS_13k2 && hEncoderConfig->Opt_RF_ON == 1) + { + st_ivas->codec_mode = MODE2; + } + + st_ivas->last_codec_mode = st_ivas->codec_mode; + + /*-----------------------------------------------------------------* + * Sanity checks + *-----------------------------------------------------------------*/ + assert(hEncoderConfig->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined"); + + IF ((NE_16(hEncoderConfig->ivas_format, MONO_FORMAT) || hEncoderConfig->stereo_dmx_evs) && EQ_32(hEncoderConfig->input_Fs, 8000)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz input sampling rate is not supported in IVAS."); + } + + IF (hEncoderConfig->Opt_DTX_ON && NE_16(hEncoderConfig->ivas_format, MONO_FORMAT) && + ((EQ_16(hEncoderConfig->ivas_format, SBA_FORMAT) && GT_32(ivas_get_sba_num_TCs(hEncoderConfig->ivas_total_brate, 1), 2)) || + EQ_16(hEncoderConfig->ivas_format, MC_FORMAT) || EQ_16(hEncoderConfig->ivas_format, MASA_ISM_FORMAT) || EQ_16(hEncoderConfig->ivas_format, SBA_ISM_FORMAT))) + { + return IVAS_ERROR(IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode."); + } + + + IF (hEncoderConfig->Opt_PCA_ON && !(EQ_16(hEncoderConfig->ivas_format, SBA_FORMAT) && EQ_32(hEncoderConfig->ivas_total_brate, PCA_BRATE) && EQ_16(hEncoderConfig->sba_order, SBA_FOA_ORDER))) + { + return IVAS_ERROR(IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only."); + } + + IF ((error = sanitizeBandwidth_fx(hIvasEnc)) != IVAS_ERR_OK) + { + return error; + } + + IF (hEncoderConfig->is_binaural && !((EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT) && hEncoderConfig->stereo_dmx_evs) || EQ_16(hEncoderConfig->ivas_format, STEREO_FORMAT))) + { + return IVAS_ERROR(IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'"); + } + + /*-----------------------------------------------------------------* + * Finalize initialization + *-----------------------------------------------------------------*/ + + IF ((error = ivas_init_encoder_fx(st_ivas)) != IVAS_ERR_OK) + { + return error; + } + + IF (EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT)) + { + hIvasEnc->hCoreCoder = st_ivas->hSCE[0]->hCoreCoder[0]; /* Note: this is needed for switching in EVS mono */ +#ifndef EVS_FLOAT_ENC + hIvasEnc->hCoreCoder_fx = st_ivas->hSCE[0]->hCoreCoder_fx[0]; +#endif + } + ELSE + { + hIvasEnc->hCoreCoder = NULL; + } + + hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON; + hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; + + hIvasEnc->isConfigured = true; + + return error; +} +#endif /*---------------------------------------------------------------------* * IVAS_ENC_GetDelay() * @@ -1828,8 +2223,66 @@ static ivas_error setChannelAwareConfig( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error setChannelAwareConfig_fx( + IVAS_ENC_HANDLE hIvasEnc, + const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig) +{ + Word16 newFecIndicator; + ivas_error error; + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; + + /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */ + IF ((caConfig.channelAwareModeEnabled && NE_32(st_ivas->hEncoderConfig->ivas_total_brate, ACELP_13k20)) || (hEncoderConfig->Opt_RF_ON && EQ_32(hEncoderConfig->input_Fs, 8000))) + { + hEncoderConfig->Opt_RF_ON = 0; + hEncoderConfig->rf_fec_offset = 0; + return IVAS_ERR_OK; + } + + IF (caConfig.channelAwareModeEnabled) + { + hEncoderConfig->Opt_RF_ON = 1; + + /* Convert FEC indicator from API type */ + IF ((error = fecIndicatorApiToInternal(caConfig.fec_indicator, &newFecIndicator)) != IVAS_ERR_OK) + { + return error; + } + + /* Set new values only if they differ from current values */ + IF ((NE_16(newFecIndicator, hEncoderConfig->rf_fec_indicator) || NE_16(caConfig.fec_offset, hEncoderConfig->rf_fec_offset))) + { + hEncoderConfig->rf_fec_indicator = newFecIndicator; + /* Check if new FEC offset has a valid value */ + IF (EQ_16(caConfig.fec_offset, 0) || EQ_16(caConfig.fec_offset, 2) || EQ_16(caConfig.fec_offset, 3) || EQ_16(caConfig.fec_offset, 5) || EQ_16(caConfig.fec_offset, 7)) + { + hEncoderConfig->rf_fec_offset = caConfig.fec_offset; + } + ELSE + { + return IVAS_ERR_INVALID_FEC_OFFSET; + } + hIvasEnc->switchingActive = true; + } + + /* Save a copy of FEC offset value - needed during encoding */ + hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset; + } + ELSE + { + hEncoderConfig->Opt_RF_ON = 0; + } + + return IVAS_ERR_OK; +} +#endif /*---------------------------------------------------------------------* * doCommonConfigureChecks() * @@ -1839,12 +2292,12 @@ static ivas_error setChannelAwareConfig( static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ) { - if ( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) + IF ( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - if ( hIvasEnc->isConfigured ) + IF ( hIvasEnc->isConfigured ) { return IVAS_ERR_RECONFIGURE_NOT_SUPPORTED; } @@ -1971,8 +2424,96 @@ static ivas_error sanitizeBandwidth( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error sanitizeBandwidth_fx( + const IVAS_ENC_HANDLE hIvasEnc) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + Word16 max_bwidth_tmp; + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + max_bwidth_tmp = hIvasEnc->newBandwidthApi; + + /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ + IF (EQ_32(hEncoderConfig->input_Fs, 8000) && GT_16(max_bwidth_tmp, NB)) + { + max_bwidth_tmp = NB; + } + ELSE IF (EQ_32(hEncoderConfig->input_Fs, 16000) && GT_16(max_bwidth_tmp, WB)) + { + max_bwidth_tmp = WB; + } + ELSE IF (EQ_32(hEncoderConfig->input_Fs, 32000) && GT_16(max_bwidth_tmp, SWB)) + { + max_bwidth_tmp = SWB; + } + + /* NB coding not supported in IVAS. Switching to WB. */ + IF (EQ_16(max_bwidth_tmp, NB) && NE_16(hEncoderConfig->ivas_format, UNDEFINED_FORMAT) && NE_16(hEncoderConfig->ivas_format, MONO_FORMAT)) + { + IF (GE_32(hEncoderConfig->input_Fs, 16000)) + { + max_bwidth_tmp = WB; + } + ELSE + { + return IVAS_ERR_INVALID_BITRATE; + } + } + + IF (EQ_16(hEncoderConfig->ivas_format, MONO_FORMAT)) + { +#if 0 // IVAS_fmToDo: temporary disabled to keep EVS bit-exactness -> to be verified + if (max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40) + { + if (hEncoderConfig->ivas_total_brate < ACELP_9k60) + { + max_bwidth_tmp = WB; + } + else + { + max_bwidth_tmp = SWB; + } + } + + if (max_bwidth_tmp == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60) + { + max_bwidth_tmp = WB; + } + + /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ + if ((max_bwidth_tmp == NB || hEncoderConfig->input_Fs == 8000) && hEncoderConfig->ivas_total_brate > ACELP_24k40) + { + if (hEncoderConfig->input_Fs >= 16000) + { + max_bwidth_tmp = WB; + } + else + { + return IVAS_ERR_INVALID_BITRATE; + } + } +#endif + } + ELSE + { + IF (EQ_16(max_bwidth_tmp, FB) && ((NE_16(hEncoderConfig->ivas_format, ISM_FORMAT) && LT_32(hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO)) || + (EQ_16(hEncoderConfig->ivas_format, ISM_FORMAT) && LT_32(div_l(hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism), MIN_BRATE_FB_ISM)))) + { + max_bwidth_tmp = SWB; + } + } + + IF (NE_16(hEncoderConfig->max_bwidth, max_bwidth_tmp)) + { + hEncoderConfig->max_bwidth = max_bwidth_tmp; + hIvasEnc->switchingActive = true; + } + + return IVAS_ERR_OK; +} +#endif /*---------------------------------------------------------------------* * sanitizeBitrateISM() * @@ -2024,8 +2565,53 @@ static ivas_error sanitizeBitrateISM( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error sanitizeBitrateISM_fx( + const ENCODER_CONFIG_HANDLE hEncoderConfig, + const bool extMetadataApi) +{ + IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_128k) && EQ_16(hEncoderConfig->nchan_inp, 1)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_256k) && EQ_16(hEncoderConfig->nchan_inp, 2)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_384k) && EQ_16(hEncoderConfig->nchan_inp, 3)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_16k4) && EQ_16(hEncoderConfig->nchan_inp, 2)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_24k4) && EQ_16(hEncoderConfig->nchan_inp, 3)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (GT_32(hEncoderConfig->ivas_total_brate, IVAS_24k4) && EQ_16(hEncoderConfig->nchan_inp, 4)) + { + return IVAS_ERROR(IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate); + } + + IF (extMetadataApi) + { + hEncoderConfig->ism_extended_metadata_flag = GE_32(hEncoderConfig->ivas_total_brate, ISM_EXTENDED_METADATA_BRATE); + } + ELSE + { + hEncoderConfig->ism_extended_metadata_flag = 0; + } - + return IVAS_ERR_OK; +} +#endif /*---------------------------------------------------------------------* * setBandwidth() * @@ -2064,7 +2650,40 @@ static ivas_error setBandwidth( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error setBandwidth_fx( + IVAS_ENC_HANDLE hIvasEnc, + const IVAS_ENC_BANDWIDTH maxBandwidth) +{ + ivas_error error; + Word16 newBandwidth; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + /* Convert bandwidth from API type */ + IF ((error = bandwidthApiToInternal(maxBandwidth, &newBandwidth)) != IVAS_ERR_OK) + { + return error; + } + + hIvasEnc->newBandwidthApi = newBandwidth; + + /* NB coding not supported in IVAS. Switching to WB. */ + IF (newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT) + { + newBandwidth = WB; + } + + IF (hEncoderConfig->max_bwidth != newBandwidth) + { + hEncoderConfig->max_bwidth = newBandwidth; + hIvasEnc->switchingActive = true; + } + return IVAS_ERR_OK; +} +#endif /*---------------------------------------------------------------------* * resetIsmMetadataProvidedFlags() @@ -2075,9 +2694,9 @@ static ivas_error setBandwidth( static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ) { - int16_t i; + Word16 i; - for ( i = 0; i < MAX_NUM_OBJECTS; ++i ) + FOR ( i = 0; i < MAX_NUM_OBJECTS; ++i ) { hIvasEnc->ismMetadataProvided[i] = false; } @@ -2094,26 +2713,26 @@ static void resetIsmMetadataProvidedFlags( static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, - int16_t *internalMaxBandwidth ) + Word16 *internalMaxBandwidth ) { - switch ( maxBandwidth ) + SWITCH ( maxBandwidth ) { case IVAS_ENC_BANDWIDTH_NB: *internalMaxBandwidth = NB; - break; + BREAK; case IVAS_ENC_BANDWIDTH_WB: *internalMaxBandwidth = WB; - break; + BREAK; case IVAS_ENC_BANDWIDTH_SWB: *internalMaxBandwidth = SWB; - break; + BREAK; case IVAS_ENC_BANDWIDTH_FB: *internalMaxBandwidth = FB; - break; + BREAK; case IVAS_ENC_BANDWIDTH_UNDEFINED: default: return IVAS_ERR_INVALID_BANDWIDTH; - break; + BREAK; } return IVAS_ERR_OK; @@ -2129,19 +2748,19 @@ static ivas_error bandwidthApiToInternal( static ivas_error fecIndicatorApiToInternal( const IVAS_ENC_FEC_INDICATOR fecIndicator, - int16_t *fecIndicatorInternal ) + Word16 *fecIndicatorInternal ) { - switch ( fecIndicator ) + SWITCH ( fecIndicator ) { case IVAS_ENC_FEC_LO: *fecIndicatorInternal = 0; - break; + BREAK; case IVAS_ENC_FEC_HI: *fecIndicatorInternal = 1; - break; + BREAK; default: return IVAS_ERR_INTERNAL; - break; + BREAK; } return IVAS_ERR_OK; diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index a3a4fee8941d879495281ba331110dea94434d85..82aaf5a3c181068cdd5f13ef137b3b78e3451f38 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -68,7 +68,7 @@ typedef struct _IVAS_ENC_DTX_CONFIG { bool enabled; bool variable_SID_rate; - int16_t SID_interval; + Word16 SID_interval; } IVAS_ENC_DTX_CONFIG; typedef enum _IVAS_ENC_SBA_ORDER @@ -128,6 +128,10 @@ ivas_error IVAS_ENC_Open( IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to an encoder handle to be opened */ ); +ivas_error IVAS_ENC_Open_fx( + IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to an encoder handle to be opened */ +); + /*! r: error code */ ivas_error IVAS_ENC_ConfigureForMono( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ @@ -201,6 +205,17 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( const bool Opt_PCA_ON /* i : PCA option flag */ ); +ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the output bitstream */ + const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ + const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ + const bool Opt_PCA_ON /* i : PCA option flag */ +); /*! r: error code */ ivas_error IVAS_ENC_ConfigureForMasa( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 5eb452d7fadfd169b1c60b7fb9c9f101d3f538e6..9fa5649ace5242378f1e5b0a376ea829256f80dc 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -754,6 +754,11 @@ void InitTransientDetection_fx(Word16 nFrameLength, Word16 nTCXDelay, struct TransientDetection * pTransientDetection); +void InitTransientDetection_ivas_fx(Word16 nFrameLength, + Word16 nTCXDelay, + TRAN_DET_HANDLE pTransientDetection, + const Word16 ext_mem_flag +); /** Runs transient detection. * Runs all transient detectors defined in pTransientDetection @@ -1699,6 +1704,10 @@ void IGFEncSetMode_fx( Word16 vad_init_fx(T_CldfbVadState_fx *vad_state); +Word16 vad_init_ivas_fx( + VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ +); + void init_PLC_enc_fx( PLC_ENC_EVS_HANDLE hPlcExt, Word32 sampleRate @@ -3001,6 +3010,11 @@ Word16 peak_vq_enc_fx( void wb_vad_init_fx( VAD_HANDLE hVAD /* i/o: VAD data handle */ ); + +void wb_vad_init_ivas_fx( + VAD_HANDLE hVAD /* i/o: VAD data handle */ +); + void noise_est_init_fx( NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */ ); @@ -3271,7 +3285,7 @@ ivas_error init_encoder_fx( void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ - const int16_t flag_all /* i : flag 1==update all, 0=partial update*/ + const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ ); void destroy_encoder_fx( diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index e922d581fc70cb0c9b26d2363233b4fff0264699..e2514d5db2fe9d9838605be63a1be542e489d98b 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -253,6 +253,7 @@ typedef struct vad_structure int16_t trigger_SID; float running_avg; float snr_sum_vad; + Word16 snr_sum_vad_fx; Word16 running_avg_fx; /*Q15 */ Word32 L_snr_sum_vad_fx; /*Q4*/ @@ -268,29 +269,43 @@ typedef struct cldfb_vad_structure /* feature */ float sp_center[SP_CENTER_NUM]; /* spectral center*/ float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + float sfm[SFM_NUM]; /* spectral flatness*/ - float f_tonality_rate[TONA_NUM]; /* tonality rate*/ + + float f_tonality_rate[TONA_NUM]; /* tonality rate*/ float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ float frames_power[POWER_NUM]; /* energy of several frames*/ + float pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ + float t_bg_energy; /* time background energy of several frames*/ + Word32 t_bg_energy_fx; /* time background energy of several frames*/ float t_bg_energy_sum; /* number of time background energy*/ + Word32 t_bg_energy_sum_fx; /* number of time background energy*/ int16_t tbg_energy_count; /* sum of time background energy of several frames*/ int16_t bg_update_count; /* time of background update*/ float frame_energy_smooth; /* smoothed energy of several frames*/ + Word32 frame_energy_smooth_fx; /* smoothed energy of several frames*/ /* history parameters */ float smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ float sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ float pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ + float lt_snr_org; /* original long time SNR*/ float lf_snr_smooth; /* smoothed lf_snr*/ float l_silence_snr; /* sum of snr's of non active frames*/ float l_speech_snr; /* sum of snr's of active frames*/ + Word32 lt_snr_org_fx; /* original long time SNR*/ + Word32 lf_snr_smooth_fx; /* smoothed lf_snr*/ + Word16 l_silence_snr_fx; /* sum of snr's of non active frames*/ + Word32 l_speech_snr_fx; /* sum of snr's of active frames*/ int16_t l_silence_snr_count; /* number of non active frames*/ int16_t l_speech_snr_count; /* number of active frames*/ float fg_energy; /* foreground energy sum */ float bg_energy; /* background energy sum */ + Word32 fg_energy_fx; /* foreground energy sum */ + Word32 bg_energy_fx; /* background energy sum */ int16_t fg_energy_count; /* number of the foreground energy frame */ int16_t bg_energy_count; /* number of the background energy frame */ int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ @@ -306,6 +321,25 @@ typedef struct cldfb_vad_structure float lt_noise_sp_center0; /* long time noise sp_center0*/ float lt_noise_sp_center3; /* long time noise sp_center3*/ float lt_bg_highf_eng; /* average of long time high frequency energy*/ + Word16 f_tonality_rate_fx[TONA_NUM]; /* tonality rate*/ + Word32 frame_sb_energy_fx[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + Word32 frames_power_fx[POWER_NUM]; /* energy of several frames*/ + Word16 pre_spec_low_dif_fx[PRE_SPEC_DIF_NUM] ; /* low frequency spectral different*/ + Word32 smooth_spec_amp_fx[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + Word32 sb_bg_energy_fx[BG_ENG_NUM]; /* sub-band background energy*/ + Word32 pre_snr_fx[PRE_SNR_NUM]; /* previous time SNR*/ + Word16 sfm_fx[SFM_NUM]; /* spectral flatness*/ + Word16 sp_center_fx[SP_CENTER_NUM]; /* spectral center*/ + Word16 ltd_stable_rate_fx[STABLE_NUM]; /* time-domain stable rate*/ + Word16 tonality_rate3_fx; /* tonality rate*/ + Word16 music_background_rate_fx; /* music background rate*/ + Word16 lt_noise_sp_center_diff_sum_fx; /* different sum of long time noise sp_center*/ + Word32 lt_noise_sp_center_diff_counter_fx; /* number of the member lt_noise_sp_center_diff_sum*/ + Word16 lt_noise_sp_center0_fx; /* long time noise sp_center0*/ + Word16 lt_noise_sp_center3_fx; /* long time noise sp_center3*/ + Word16 lt_bg_highf_eng_fx; /* average of long time high frequency energy*/ + int16_t update_num_with_snr_fx; /* the number of the background update with SNR*/ + int16_t update_num_with_snr; /* the number of the background update with SNR*/ int16_t update_count; int16_t warm_hang_num; /* the number of hangover for warm up*/ @@ -1600,7 +1634,8 @@ typedef struct tcx_enc_structure Word16 tcx_target_bits_fac; int16_t tns_ms_flag[2]; - + Word32 *spectrum_fx[2]; /* MDCT output for a short block */ + Word32 spectrum_long_fx[N_MAX]; /* MDCT output for a long block. Points to spectrum */ } TCX_ENC_DATA, *TCX_ENC_HANDLE; typedef struct TransientDetection @@ -1625,23 +1660,24 @@ typedef struct enc_core_structure * Common parameters *----------------------------------------------------------------------------------*/ - int16_t idchan; /* channel ID (audio channel number) */ + Word16 idchan; /* channel ID (audio channel number) */ Word16 id_element; /* element ID */ int16_t element_mode; /* element mode */ Word16 last_element_mode; /* element mode */ int32_t element_brate; /* element bitrate */ Word16 extl_orig; /* extension layer */ Word32 extl_brate_orig; /* extension layer bitrate */ - int16_t codec_mode; /* Mode1 or Mode2 */ - int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ - int16_t last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ + Word16 codec_mode; /* Mode1 or Mode2 */ + Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ + Word16 last_codec_mode_cng; /* previous inactive frame Mode 1 or 2 */ /* MDCT switching */ - int16_t mdct_sw_enable; /* MDCT switching enable flag */ - int16_t mdct_sw; /* MDCT switching indicator */ + Word16 mdct_sw_enable; /* MDCT switching enable flag */ + Word16 mdct_sw; /* MDCT switching indicator */ BSTR_ENC_HANDLE hBstr; /* encoder bitstream handle */ Word16 last_enerBuffer_exp; + int16_t bitstreamformat; /* Bitstream format flag (G.192/MIME) */ Word16 next_bit_pos_fx; /* position of the next bit to be written in the bitstream */ @@ -1676,7 +1712,7 @@ typedef struct enc_core_structure int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ Word16 nTimeSlots; /* for CLDFB */ - int16_t ini_frame; /* initialization frames counter */ + Word16 ini_frame; /* initialization frames counter */ //Word32 input_Fs_fx; /* input signal sampling frequency in Hz */ //Word32 total_brate_fx; /* total bitrate in kbps of the codec */ @@ -1828,22 +1864,24 @@ typedef struct enc_core_structure Word16 last_vad_spa_fx; - int16_t last_L_frame; /* ACELP@16kHz - last L_frame value */ + Word16 last_L_frame; /* ACELP@16kHz - last L_frame value */ float mem_preemph16k; /* ACELP@16kHz - preemphasis filter memory @16kHz */ float mem_deemp_preQ; /* ACELP@16kHz - prequantizer deemhasis memory */ float mem_preemp_preQ; /* ACELP@16kHz - prequantizer preemhasis memory */ Word16 mem_preemph16k_fx; /* ACELP@16kHz - preemphasis filter memory @16kHz */ Word16 mem_deemp_preQ_fx; /* ACELP@16kHz - prequantizer deemhasis memory */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ - int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ float old_pitch_buf[2 * NB_SUBFR16k]; /* Bass post-filter - buffer of old subframe pitch values */ Word16 old_pitch_buf_fx[2 * NB_SUBFR16k]; /*Q6 Bass post-filter - buffer of old subframe pitch values */ float pst_mem_deemp_err; /* Bass post-filter - filter memory of noise LP filter */ + Word16 pst_mem_deemp_err_fx; /* Bass post-filter - filter memory of noise LP filter */ float pst_lp_ener; /* Bass post-filter - long-term energy */ + Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy */ /* stable short pitch detection */ float voicing0_sm; @@ -2051,19 +2089,19 @@ typedef struct enc_core_structure * Mode2 *----------------------------------------------------------------------------------*/ - int16_t frame_size_index; /* 0-FRAME_SIZE_NB-1: index determining the frame size */ - int16_t bits_frame_nominal; /* avg bits per frame on active frame */ - int16_t last_bits_frame_nominal; /* avg bits per frame on active frame */ - int16_t bits_frame; /* bits per frame overall */ - int16_t bits_frame_core; /* bits per frame for the core */ - int16_t bits_frame_channel; - int16_t side_bits_frame_channel; - int16_t narrowBand; - int16_t restrictedMode; - int16_t nb_subfr; - int16_t tcxonly; - int16_t fscale; - int32_t sr_core; + Word16 frame_size_index; /* 0-FRAME_SIZE_NB-1: index determining the frame size */ + Word16 bits_frame_nominal; /* avg bits per frame on active frame */ + Word16 last_bits_frame_nominal; /* avg bits per frame on active frame */ + Word16 bits_frame; /* bits per frame overall */ + Word16 bits_frame_core; /* bits per frame for the core */ + Word16 bits_frame_channel; + Word16 side_bits_frame_channel; + Word16 narrowBand; + Word16 restrictedMode; + Word16 nb_subfr; + Word16 tcxonly; + Word16 fscale; + Word32 sr_core; /*ACELP config*/ ACELP_config acelp_cfg; /*configuration set for each frame*/ @@ -2121,6 +2159,7 @@ typedef struct enc_core_structure float prevEnergyHF; float currEnergyHF; float currEnergyLookAhead; + Word32 currEnergyLookAhead_fx; //Q31 Word32 prevEnergyHF_fx; Word32 currEnergyHF_fx; Word16 currEnergyHF_e_fx; /* exponent of currEnergyHF and prevEnergyHF */ @@ -2227,12 +2266,17 @@ typedef struct enc_core_structure float mem_preemph16k_DFT; float inp_16k_mem_stereo_sw[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; + Word32 mem_preemph_DFT_fx; + Word32 inp_12k8_mem_stereo_sw_fx[STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT]; + Word32 mem_preemph16k_DFT_fx; + Word32 inp_16k_mem_stereo_sw_fx[STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k]; + /* MCT Channel mode indication: LFE, ignore channel? */ MCT_CHAN_MODE mct_chan_mode; - int16_t is_ism_format; /* Indication whether the codec operates in ISM format */ + Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ - int16_t dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ + Word16 dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ /*----------------------------------------------------------------------------------* * Fixed point only variables *----------------------------------------------------------------------------------*/ diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 68a05f32bf3b5cbc98a75288238b849891049801..321dfbd08f30079d1259c81b5375d65dafbd01d7 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -162,6 +162,31 @@ void InitTransientDetection_fx(Word16 nFrameLength, add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS+1); } +void InitTransientDetection_ivas_fx(Word16 nFrameLength, + Word16 nTCXDelay, + TRAN_DET_HANDLE pTransientDetection, + const Word16 ext_mem_flag + ) +{ + /* Init the delay buffer. */ + InitDelayBuffer(nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ + InitSubblockEnergies(nFrameLength, nTCXDelay, &pTransientDetection->delayBuffer, &pTransientDetection->subblockEnergies); + /* Init the TCX Short/Long transient detector. */ + InitTCXTransientDetector(nTCXDelay, &pTransientDetection->subblockEnergies, &pTransientDetection->transientDetector); + /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ + IF(ext_mem_flag) + { + pTransientDetection->transientDetector.pSubblockEnergies->nDelay = + add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, add((NSUBBLOCKS + 1), (NSUBBLOCKS_SHIFT + 1))); + } + ELSE + { + pTransientDetection->transientDetector.pSubblockEnergies->nDelay = + add(pTransientDetection->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1); + } +} + /** * \brief Calculate average of temporal energy change. * \return average temporal energy change with exponent = 8 diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 1021f79c97bd8cff8ee02f057d1855c68cf86b08..c486f715046c9c0b0ce61fcce2525d368c57640d 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -134,6 +134,74 @@ void wb_vad_init_fx( return; } +void wb_vad_init_ivas_fx( + VAD_HANDLE hVAD /* i/o: VAD data handle */ +) +{ + hVAD->hangover_cnt = 0; + move16(); /* Hangover counter initialized to 0 */ + hVAD->nb_active_frames = ACTIVE_FRAMES_FX; + move16(); /* The counter of SPEECH frames necessary to trigger HO */ + /* is set to max (-> start with hangover) */ + + hVAD->vad_flag_reg_H = L_deposit_l(0); + hVAD->vad_flag_reg_L = L_deposit_l(0); + hVAD->vad_prim_reg = L_deposit_l(0); + hVAD->vad_flag_cnt_50 = 0; + move16(); + hVAD->vad_prim_cnt_16 = 0; + move16(); + + hVAD->hangover_cnt_dtx = HANGOVER_LONG_FX; + move16(); /* hangover for DTX */ + hVAD->hangover_cnt_music = HANGOVER_LONG_MUSIC_FX; + move16(); /* hangover for MUSIC DTX */ + + hVAD->hangover_cnt_he = 0; + move16(); /* Hangover counter initialized to 0 */ + hVAD->nb_active_frames_he = ACTIVE_FRAMES_FX; + move16(); /* The counter of SPEECH frames necessary to trigger HO */ + hVAD->bcg_flux_fx = 1120; + move16(); /*70 in Q4 */ + hVAD->soft_hangover = 0; + move16(); + hVAD->voiced_burst = 0; + move16(); + hVAD->bcg_flux_init = 50; + move16(); + hVAD->nb_active_frames_he1 = ACTIVE_FRAMES_FX; + move16(); + hVAD->hangover_cnt_he1 = 0; + move16(); + + hVAD->prim_act_quick_fx = 0; + move16(); + hVAD->prim_act_slow_fx = 0; + move16(); + hVAD->prim_act_fx = 0; + move16(); + hVAD->prim_act_quick_he_fx = 0; + move16(); + hVAD->prim_act_slow_he_fx = 0; + move16(); + hVAD->prim_act_he_fx = 0; + move16(); + hVAD->consec_inactive = 0; + move16(); + hVAD->spectral_tilt_reset = 1; + move16(); + hVAD->running_avg_fx = 0; + move16(); + hVAD->ra_deltasum_fx = 0; + move16(); + hVAD->trigger_SID = 0; + move16(); + hVAD->snr_sum_vad = 0; + move16(); + hVAD->hangover_terminate_flag = 0; + move16(); + return; +} /*-----------------------------------------------------------------* * sign_thr_snr_acc_fx() diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index 14bf4de21df72debea513f67839f6292f743f360..d01df08970661f65ab2ebfca016799ac9544b315 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -176,7 +176,110 @@ Word16 vad_init_fx( return 0; } +Word16 vad_init_ivas_fx( + VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ +) +{ + Word16 i = 0; + + IF(hVAD_CLDFB == NULL) + { + return -1; + } + + hVAD_CLDFB->frameloop = 0; + hVAD_CLDFB->lt_snr_org_fx = 33554432; /*Q26 */ + hVAD_CLDFB->lf_snr_smooth_fx = 167772155/* 5.0 Q25 */; + hVAD_CLDFB->l_silence_snr_fx = 32768/* 0.5 Q16 */; + hVAD_CLDFB->l_speech_snr_fx = 327675/* 5.0 Q16 */; + hVAD_CLDFB->l_silence_snr_count = 1; + hVAD_CLDFB->l_speech_snr_count = 1; + hVAD_CLDFB->fg_energy_fx = 1073741824; + hVAD_CLDFB->bg_energy_fx = 1073741824; + hVAD_CLDFB->fg_energy_count = 16; + hVAD_CLDFB->bg_energy_count = 16; + hVAD_CLDFB->tonality_rate3_fx = 15073/* 0.46 Q15 */; + hVAD_CLDFB->music_background_rate_fx = 15073/* 0.46 Q15 */; + hVAD_CLDFB->lt_noise_sp_center_diff_sum_fx = 409/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center_diff_counter_fx = L_deposit_l(4); + hVAD_CLDFB->lt_noise_sp_center0_fx = 1841/* 0.4 Q10 */; + hVAD_CLDFB->lt_noise_sp_center3_fx = 2046/* 0.4 Q10 */; + hVAD_CLDFB->lt_bg_highf_eng_fx = 131070/* 2.0 Q16 */; + hVAD_CLDFB->t_bg_energy_fx = 1374389535; + hVAD_CLDFB->t_bg_energy_sum_fx = 1374389535; + hVAD_CLDFB->tbg_energy_count = 1; + hVAD_CLDFB->bg_update_count = 0; + hVAD_CLDFB->frame_energy_smooth_fx = 1073741824; + hVAD_CLDFB->fg_energy_est_start = 0; + hVAD_CLDFB->speech_flag = 0; + hVAD_CLDFB->continuous_noise_num = 0; + hVAD_CLDFB->continuous_speech_num = 0; + hVAD_CLDFB->continuous_speech_num2 = 0; + hVAD_CLDFB->update_num_with_snr = 0; /* the number of the background update with SNR*/ + hVAD_CLDFB->update_count = 0; + hVAD_CLDFB->warm_hang_num = 0; + + FOR(i = 0; i < PRE_SNR_NUM; i++) + { + hVAD_CLDFB->pre_snr_fx[i] = L_deposit_l(0); + } + + FOR(i = 0; i < POWER_NUM; i++) + { + hVAD_CLDFB->frames_power_fx[i] = L_deposit_l(0); + } + + FOR(i = 0; i < SPEC_AMP_NUM; i++) + { + hVAD_CLDFB->smooth_spec_amp_fx[i] = L_deposit_l(0); + } + + hVAD_CLDFB->sfm_fx[0] = 28835/* 0.88 Q15 */; + move16(); + hVAD_CLDFB->sfm_fx[1] = 30146/* 0.92 Q15 */; + move16(); + hVAD_CLDFB->sfm_fx[2] = 30146/* 0.92 Q15 */; + move16(); + + FOR(i = 0; i < SP_CENTER_NUM; i++) + { + hVAD_CLDFB->sp_center_fx[i] = 1228/* 1.2 Q10 */; + move16(); + } + + FOR(i = 0; i < STABLE_NUM; i++) + { + hVAD_CLDFB->ltd_stable_rate_fx[i] = 2294/* 0.07 Q15 */; + move16(); + } + + FOR(i = 0; i < BG_ENG_NUM; i++) + { + hVAD_CLDFB->sb_bg_energy_fx[i] =1374389535; + move32(); + } + FOR(i = 0; i < BG_ENG_NUM; i++) + { + hVAD_CLDFB->frame_sb_energy_fx[i] = L_deposit_l(0); + } + + hVAD_CLDFB->f_tonality_rate_fx[0] = 7864/* 0.48 Q14 */; + move16(); + hVAD_CLDFB->f_tonality_rate_fx[1] = 7864/* 0.48 Q14 */; + move16(); + hVAD_CLDFB->f_tonality_rate_fx[2] = 7864/* 0.48 Q14 */; + move16(); + + + FOR(i = 0; i < PRE_SPEC_DIF_NUM; i++) + { + hVAD_CLDFB->pre_spec_low_dif_fx[i] = 4095; + move16(); + } + + return 0; +} void UpdateState( VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word16 vad_flag, /* i : VAD flag */