From 2aa61fc28c1737e50b4a751479ce789175e2e101 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Sep 2024 22:32:07 +0530 Subject: [PATCH 1/2] ISM encoder path and IGF related functions converted to fixed point --- lib_com/ivas_ism_com.c | 5 +- lib_com/ivas_prot.h | 2 + lib_com/prot.h | 6 + lib_com/prot_fx.h | 36 ++ lib_dec/fd_cng_dec.c | 4 +- lib_dec/ivas_core_dec.c | 4 +- lib_enc/ACcontextMapping_enc.c | 3 + lib_enc/ari_enc.c | 176 ++++++++ lib_enc/ari_enc_fx.c | 2 +- lib_enc/arith_coder_enc.c | 3 + lib_enc/igf_enc.c | 313 ++++++++++++++ lib_enc/igf_scf_enc.c | 234 +++++++++++ lib_enc/igf_scf_enc_fx.c | 1 + lib_enc/ivas_ism_enc.c | 703 ++++++++++++++++++++++++-------- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/prot_fx_enc.h | 11 + lib_enc/sig_clas_fx.c | 140 +++++++ lib_enc/tcx_utils_enc.c | 4 +- 18 files changed, 1464 insertions(+), 185 deletions(-) diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index c1980986f..82a5ba588 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -1260,7 +1260,7 @@ void ivas_ism_metadata_close( * * Store last metadata values *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void update_last_metadata( const int16_t nchan_ism, /* i : number of objects */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ @@ -1284,8 +1284,7 @@ void update_last_metadata( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void update_last_metadata_fx( const Word16 nchan_ism, /* i : number of objects */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5340eaeb3..7990ecedf 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6691,12 +6691,14 @@ void ivas_ari_done_encoding_14bits( BSTR_ENC_HANDLE hBstr, Tastat *s ); +#ifndef IVAS_FLOAT_FIXED void ivas_ari_encode_14bits_ext( BSTR_ENC_HANDLE hBstr, Tastat *s, int32_t symbol, const uint16_t *cum_freq ); +#endif // !IVAS_FLOAT_FIXED void ivas_wrap_arround( int16_t *pArr, diff --git a/lib_com/prot.h b/lib_com/prot.h index 8a112061d..3417fa83e 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7715,6 +7715,7 @@ int32_t mul_sbc_14bits_ivas( void ari_start_encoding_14bits( Tastat *s ); +#ifndef IVAS_FLOAT_FIXED int16_t ari_encode_14bits_ext( int16_t *ptr, int16_t bp, @@ -7726,6 +7727,7 @@ int16_t ari_done_encoding_14bits( int16_t *ptr, int16_t bp, Tastat *s ); +#endif // !IVAS_FLOAT_FIXED void ari_start_decoding_14bits_ivas( Decoder_State *st, @@ -7794,12 +7796,14 @@ int16_t ari_encode_14bits_range( uint16_t cum_freq_low, uint16_t cum_freq_high ); +#ifndef IVAS_FLOAT_FIXED int16_t ari_encode_14bits_sign( int16_t *ptr, int16_t bp, int32_t bits, Tastat *s, int32_t sign ); +#endif // !IVAS_FLOAT_FIXED int16_t ari_done_cbr_encoding_14bits( int16_t *ptr, @@ -10163,6 +10167,7 @@ void IGFSCFEncoderReset( IGFSCFENC_INSTANCE_HANDLE hPublicData /* i : handle to public data or NULL in case there was no instance created */ ); +#ifndef IVAS_FLOAT_FIXED int16_t IGFSCFEncoderEncode( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -10171,6 +10176,7 @@ int16_t IGFSCFEncoderEncode( const int16_t igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const int16_t indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); +#endif void IGFSCFEncoderSaveContextState( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i : handle to public data or NULL in case there was no instance created */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d1c79d2f9..f47017b59 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10230,6 +10230,7 @@ void ProcessStereoIGF_fx( const int16_t sp_aud_decision0, /* i : sp_aud_decision0 */ const int32_t element_brate /* i : element bitrate */ ); +/*igf_enc.c*/ void IGFEncApplyStereo_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ Word16 ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ @@ -10244,6 +10245,41 @@ void IGFEncApplyStereo_fx( const Word32 element_brate /* i : element bitrate */ ); +void IGFSaveSpectrumForITF_ivas_fx( + IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word32 *pITFSpectrum /* i : MDCT spectrum */ +); +Word16 IGFEncWriteBitstream_ivas_fx( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : ptr to bitOffset counter */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ +); +/*igf_scf_enc.c*/ +Word16 IGFSCFEncoderEncode( + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ +); +/*ari_enc.c*/ +Word16 ari_encode_14bits_ext( + Word16 *ptr, + Word16 bp, + Tastat *s, + Word32 symbol, + const UWord16 *cum_freq ); +Word16 ari_encode_14bits_sign( + Word16 *ptr, + Word16 bp, + Word32 bits, + Tastat *s, + Word16 sign ); +Word16 ari_done_encoding_14bits( Word16 *ptr, Word16 bp, Tastat *s ); #endif // IVAS_FLOAT_FIXED #endif diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 8fb13e823..10c25db4d 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -2674,7 +2674,7 @@ void generate_masking_noise_lb_dirac_fx( n_samples_out = i_mult( shr( hFdCngCom->frameSize, 4 ), nCldfbTs ); n_samples_start = 0; move16(); - Word16 exp_out = Q15; + Word16 exp_out = Q11; move16(); /*LB CLDFB - CNA from STFT*/ IF( cna_flag ) @@ -2769,7 +2769,7 @@ void generate_masking_noise_lb_dirac_fx( /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); } - hFdCngCom->fftBuffer_exp = 31 - 15; + hFdCngCom->fftBuffer_exp = 31 - 11; move16(); n_samples_out = sub( n_samples_out, hFdCngCom->frameSize ); n_samples_start = add( n_samples_start, hFdCngCom->frameSize ); diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index c67519b02..38e590273 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -1207,7 +1207,7 @@ ivas_error ivas_core_dec_fx( q = 2; move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( ( Q11 ) ) ); #ifdef MSAN_FIX Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); #else @@ -1224,7 +1224,7 @@ ivas_error ivas_core_dec_fx( test(); IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 ) ); } #ifndef FIX_826_PRECISION_LOST_AND_COMPL diff --git a/lib_enc/ACcontextMapping_enc.c b/lib_enc/ACcontextMapping_enc.c index 0f37e51de..c33b5f3d5 100644 --- a/lib_enc/ACcontextMapping_enc.c +++ b/lib_enc/ACcontextMapping_enc.c @@ -44,6 +44,9 @@ #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c index 8481d6c94..d8ba85f98 100644 --- a/lib_enc/ari_enc.c +++ b/lib_enc/ari_enc.c @@ -43,6 +43,9 @@ #include "stat_com.h" #include "basop_util.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx_enc.h" +#endif // IVAS_FLOAT_FIXED /*--------------------------------------------------------------- @@ -104,6 +107,20 @@ void ari_start_encoding_14bits_ivas_fx( * Finish ArCo encoding *-------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +Word16 ari_done_encoding_14bits( Word16 *ptr, Word16 bp, Tastat *s ) +{ + Word16 bit; + + bit = 0; + move16(); + if ( GE_32( s->low, ari_q1new ) ) + { + bit = s_xor( bit, 1 ); + } + return ari_put_bit_plus_follow( ptr, bp, add( extract_l( s->bits_to_follow ), 1 ), bit ); +} +#else int16_t ari_done_encoding_14bits( int16_t *ptr, int16_t bp, @@ -139,6 +156,7 @@ int16_t ari_done_encoding_14bits( return bp; } +#endif // IVAS_FLOAT_FIXED /*--------------------------------------------------------------- @@ -147,6 +165,84 @@ int16_t ari_done_encoding_14bits( * encode function for extended proba tables: less branches needed for coding * *-------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +Word16 ari_encode_14bits_ext( + Word16 *ptr, + Word16 bp, + Tastat *s, + Word32 symbol, + UWord16 const *cum_freq ) +{ + Word32 low; + Word32 high; + Word32 range; + Word16 bits_to_follow; + Word16 i; + UWord16 temp; + Word32 L_temp1, L_temp2; + + high = L_add( s->high, 0 ); + low = L_add( s->low, 0 ); + range = L_add( L_sub( high, low ), 1 ); + + L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ ); + Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp ); + IF ( symbol != 0 ) /* when symbol is 0, range remains unchanged */ + { + Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp ); + } + high = L_sub( L_add( low, range ), 1 ); + low = L_add( low, L_temp2 ); + + assert( s->bits_to_follow <= MAX_16 ); + bits_to_follow = extract_l( s->bits_to_follow ); + + FOR( i = 0; i < 0x7FFF; i++ ) + { + IF( LT_32( high, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); + bits_to_follow = 0; + move16(); + } + ELSE IF( GE_32( low, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); + bits_to_follow = 0; + move16(); + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + } + ELSE + { + test(); + IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) ) + { + /* Output an opposite bit */ + /* later if in middle half. */ + bits_to_follow = add( bits_to_follow, 1 ); + low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ + high = L_sub( high, ari_q1new ); + } + ELSE + { + BREAK; /* Otherwise exit loop. */ + } + } + low = L_add( low, low ); + high = L_add( L_add( high, high ), 1 ); /* Scale up code range. */ + } + + s->low = low; + move32(); + s->high = high; + move32(); + s->bits_to_follow = bits_to_follow; + move32(); + + return bp; +} +#else int16_t ari_encode_14bits_ext( int16_t *ptr, @@ -217,6 +313,7 @@ int16_t ari_encode_14bits_ext( return bp; } +#endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------------ @@ -306,6 +403,84 @@ int16_t ari_encode_14bits_range( * * Encode a sign with equal probabilities. *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, Tastat *s, Word32 high, Word32 low ) +{ + Word16 bits_to_follow, tmp; + + bits_to_follow = extract_l( s->bits_to_follow ); + move16(); + + /* while there are more than 16 bits left */ + tmp = sub( 16, bits ); + WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) + { + IF( LE_32( high, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); + bits_to_follow = 0; + move16(); + } + ELSE IF( GE_32( low, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); + bits_to_follow = 0; + move16(); + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + } + ELSE + { + test(); + IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) + { + /* Output an opposite bit */ + /* later if in middle half. */ + bits_to_follow = add( bits_to_follow, 1 ); + low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ + high = L_sub( high, ari_q1new ); + } + ELSE + { + BREAK; /* Otherwise exit loop. */ + } + } + + low = L_add( low, low ); + high = L_add( high, high ); /* Scale up code range. */ + } + + s->low = low; + move32(); + s->high = L_sub( high, 1 ); + move32(); + s->bits_to_follow = bits_to_follow; + move16(); + + return bp; +} +Word16 ari_encode_14bits_sign( Word16 *ptr, Word16 bp, Word32 bits, Tastat *s, Word16 sign ) +{ + Word32 low, high, range; + Word32 L_tmp; + + high = L_add( s->high, 1 ); + low = L_add( s->low, 0 ); + range = L_sub( high, low ); + + L_tmp = L_shr( range, 1 ); + if ( sign != 0 ) + { + high = L_add( low, L_tmp ); + } + if ( sign == 0 ) + { + low = L_add( low, L_tmp ); + } + + return ari_encode_14bits_high_low( ptr, bp, extract_l( bits ), s, high, low ); +} +#else int16_t ari_encode_14bits_sign( int16_t *ptr, @@ -381,6 +556,7 @@ int16_t ari_encode_14bits_sign( return bp; } +#endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------------ * Function: ari_done_cbr_encoding_14bits() diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index 54c21c9d1..872b6a1f3 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -55,7 +55,7 @@ void ari_start_encoding_14bits_fx( TastatEnc *s ) * Ari encoder 14 bits routines * Returns: new bit-stream position *-------------------------------------------------------------*/ -static Word16 ari_put_bit_plus_follow( +Word16 ari_put_bit_plus_follow( Word16 ptr[], /* o: bit-stream */ Word16 bp, /* i: bit-stream position */ Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' */ diff --git a/lib_enc/arith_coder_enc.c b/lib_enc/arith_coder_enc.c index 3b5c8dea9..a2517f99f 100644 --- a/lib_enc/arith_coder_enc.c +++ b/lib_enc/arith_coder_enc.c @@ -44,6 +44,9 @@ #include "basop_util.h" #include "basop_proto_func.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index ccab94255..519a6c79b 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -1639,6 +1639,80 @@ static void IGF_CalculateStereoEnvelope( * * writes IGF SCF values *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/*! r: number of bits writen */ +static Word16 IGF_WriteEnvelope( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : ptr to bitOffset counter */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag, /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + Word16 *igfAllZero /* i : returns 1 if all IGF scfs are zero, else 0 */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 sfb; + Word16 totBitCount; + Word16 startBitCount; + + startBitCount = *pBitOffset; + totBitCount = 0; + *igfAllZero = 1; + move16(); + move16(); + move16(); + hPrivateData = &hIGFEnc->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + + FOR( sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++ ) + { + IF( hPrivateData->igfScfQuantized[sfb] != 0 ) + { + *igfAllZero = 0; + move16(); + BREAK; + } + } + + IF( *igfAllZero != 0 ) + { + IGF_write_bit( hBstr, pBitOffset, 1 ); + + IF( NULL == hBstr ) + { + IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + + IGFSCFEncoderReset_fx( &hPrivateData->hIGFSCFArithEnc ); + + IF( NULL == hBstr ) + { + IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + } + ELSE + { + IGF_write_bit( hBstr, pBitOffset, 0 ); + + IF( NULL == hBstr ) + { + IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + + *pBitOffset = IGFSCFEncoderEncode( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); + move16(); + + IF( NULL == hBstr ) + { + IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + } + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#else // IVAS_FLOAT_FIXED /*! r: number of bits writen */ static int16_t IGF_WriteEnvelope( @@ -1707,6 +1781,7 @@ static int16_t IGF_WriteEnvelope( return totBitCount; } +#endif /*-------------------------------------------------------------------* @@ -2644,6 +2719,42 @@ static void IGF_Whitening( *-------------------------------------------------------------------*/ /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +static Word16 IGF_WriteWhiteningTile( /**< out: Q0 | number of bits written */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ +) +{ + Word16 totBitCount; + Word16 startBitCount; + + totBitCount = 0; + startBitCount = *pBitOffset; + move16(); + move16(); + + IF( EQ_32( whiteningLevel, IGF_WHITENING_MID ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + ELSE + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + IF( EQ_32( whiteningLevel, IGF_WHITENING_OFF ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + ELSE + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + } + } + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#else static int16_t IGF_WriteWhiteningTile( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ int16_t *pBitOffset, /* i : ptr to bitOffset counter */ @@ -2676,6 +2787,7 @@ static int16_t IGF_WriteWhiteningTile( return totBitCount; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -2684,6 +2796,119 @@ static int16_t IGF_WriteWhiteningTile( * writes the whitening levels *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 IGF_WriteWhiteningLevels( /**< out: Q0 | total number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 p; + Word16 nTiles; + Word16 isSame; + Word32 tmp32; + Word16 totBitCount; + Word16 startBitCount; + + totBitCount = 0; + move16(); + isSame = 1; + move16(); + startBitCount = *pBitOffset; + move16(); + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + nTiles = hGrid->nTiles; + move16(); + + IF( isIndepFlag ) + { + isSame = 0; + move16(); + } + ELSE + { + p = 0; + move16(); + tmp32 = 0; + move32(); + + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) + { + test(); + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); + if ( tmp32 != 0 ) + { + isSame = 0; + move16(); + } + p++; + } + } + IF( isSame ) + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + } + ELSE + { + IF( !isIndepFlag ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + IGF_WriteWhiteningTile( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); + p = 1; + move16(); + tmp32 = 0; + move32(); + IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + isSame = 1; + move16(); + } + ELSE + { + if ( LT_16( p, nTiles ) ) + { + isSame = 1; + move16(); + } + + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) + { + test(); + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); + if ( tmp32 != 0 ) + { + isSame = 0; + move16(); + } + p++; + } + } + test(); + IF( !isSame ) + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + FOR( p = 1; p < nTiles; p++ ) + { + IGF_WriteWhiteningTile( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); + } + } + ELSE IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + } + + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#else /*! r: total number of bits written */ static int16_t IGF_WriteWhiteningLevels( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF encoder */ @@ -2773,6 +2998,7 @@ static int16_t IGF_WriteWhiteningLevels( return totBitCount; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -2781,7 +3007,31 @@ static int16_t IGF_WriteWhiteningLevels( * write flattening trigger *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED /*! r: number of bits written */ +static Word16 IGF_WriteFlatteningTrigger( /**< out: | number of bits written */ + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ +) +{ + Word16 flatteningTrigger; + + Word16 totBitCount; + Word16 startBitCount; + totBitCount = 0; + startBitCount = *pBitOffset; + flatteningTrigger = hInstance->flatteningTrigger; + move16(); + move16(); + move16(); + + IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#else static int16_t IGF_WriteFlatteningTrigger( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -2802,6 +3052,7 @@ static int16_t IGF_WriteFlatteningTrigger( return totBitCount; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -2834,6 +3085,54 @@ static void IGF_UpdateInfo_ivas( *-------------------------------------------------------------------*/ /*! r: number of bits written per frame */ +#ifdef IVAS_FLOAT_FIXED +Word16 IGFEncWriteBitstream_ivas_fx( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : ptr to bitOffset counter */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ +) +{ + Word16 igfAllZero; + Word16 startBitCount; + + startBitCount = *pBitOffset; + move16(); + hIGFEnc->infoTotalBitsPerFrameWritten = 0; + move16(); + + if ( isIndepFlag ) + { + hIGFEnc->infoTotalBitsWritten = 0; + move16(); + } + + IGF_WriteEnvelope( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + &igfAllZero ); /* o: *igfAllZero */ + + IGF_WriteWhiteningLevels( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + + IGF_WriteFlatteningTrigger( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset ); /* i: ptr to bitOffset counter */ + + hIGFEnc->infoTotalBitsPerFrameWritten = sub( *pBitOffset, startBitCount ); + hIGFEnc->infoTotalBitsWritten = add( hIGFEnc->infoTotalBitsWritten, hIGFEnc->infoTotalBitsPerFrameWritten ); + move16(); + move16(); + + return hIGFEnc->infoTotalBitsPerFrameWritten; +} +#endif // IVAS_FLOAT_FIXED int16_t IGFEncWriteBitstream( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -3321,6 +3620,20 @@ void IGFEncApplyStereo( * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void IGFSaveSpectrumForITF_ivas_fx( + IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word32 *pITFSpectrum /* i : MDCT spectrum */ +) +{ + IGF_UpdateInfo( hIGFEnc, igfGridIdx ); + + Copy32( pITFSpectrum + IGF_START_MN, hIGFEnc->spec_be_igf, sub( hIGFEnc->infoStopLine, IGF_START_MN ) ); + + return; +} +#endif void IGFSaveSpectrumForITF( IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ const int16_t igfGridIdx, /* i : IGF grid index */ diff --git a/lib_enc/igf_scf_enc.c b/lib_enc/igf_scf_enc.c index 0df03c398..00c17e191 100644 --- a/lib_enc/igf_scf_enc.c +++ b/lib_enc/igf_scf_enc.c @@ -41,6 +41,10 @@ #include "stat_com.h" #include "cnst.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "prot_fx_enc.h" +#endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -114,6 +118,29 @@ static int16_t quant_ctx( * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void arith_encode_bits( + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ + Word16 x, /* i: value to encode */ + Word16 nBits /* i: number of bits to encode */ +) +{ + Word16 i; + Word16 bit; + + + FOR( i = nBits - 1; i >= 0; --i ) /* nBits > 0 */ + { + bit = s_and( shr( x, i ), 1 ); + hPrivateData->ptrBitIndex = ari_encode_14bits_sign( ptr, + hPrivateData->ptrBitIndex, + 32767, /* disable the bit count limitation */ + &hPrivateData->acState, + bit ); + } +} +#else static void arith_encode_bits( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ int16_t *ptr, /* i : pointer to expanded bit buffer, one bit in each short*/ @@ -132,6 +159,7 @@ static void arith_encode_bits( return; } +#endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -140,6 +168,84 @@ static void arith_encode_bits( * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void arith_encode_residual( + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ + Word16 x, /* i: residual value to encode */ + const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ + Word16 tableOffset /* i: offset used to align the table */ +) +{ + Word16 extra; + Word16 extra_tmp; + Word16 extra_safety; + + + x = add( x, tableOffset ); + + test(); + IF( ( GE_16( x, IGF_MIN_ENC_SEPARATE ) ) && ( LE_16( x, IGF_MAX_ENC_SEPARATE ) ) ) + { + x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ + /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + x, + cumulativeFrequencyTable ); + + return; + } + + IF( LT_16( x, IGF_MIN_ENC_SEPARATE ) ) + { + /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ + extra = sub( IGF_MIN_ENC_SEPARATE - 1, x ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + 0, + cumulativeFrequencyTable ); + } + ELSE /* x > IGF_MAX_ENC_SEPARATE */ + { + /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ + extra = sub( x, IGF_MAX_ENC_SEPARATE + 1 ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + IGF_SYMBOLS_IN_TABLE - 1, + cumulativeFrequencyTable ); + } + + /* encode one of the tails of the distribution */ + extra_tmp = sub( extra, 15 ); + IF( extra_tmp < 0 ) + { + /* encode extra with 4 bits if extra < 15 */ + arith_encode_bits( hPrivateData, ptr, extra, 4 ); + } + ELSE /* extra >= 15 */ + { + /* send escape code 15 to indicate extra >= 15 */ + arith_encode_bits( hPrivateData, ptr, 15, 4 ); + + extra_safety = sub( extra_tmp, 63 ); + IF( extra_safety < 0 ) + { + /* encode additional extra with 6 bits */ + arith_encode_bits( hPrivateData, ptr, extra_tmp, 6 ); + } + ELSE + { /* extra_tmp >= 63 */ + arith_encode_bits( hPrivateData, ptr, 63, 6 ); + /* encode safety extra with 7 bits */ + arith_encode_bits( hPrivateData, ptr, extra_safety, 7 ); + } + } +} +#else static void arith_encode_residual( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ int16_t *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ @@ -201,6 +307,7 @@ static void arith_encode_residual( return; } +#endif /*---------------------------------------------------------------------* @@ -208,7 +315,81 @@ static void arith_encode_residual( * * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void encode_sfe_vector( + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Word16 *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ + const Word16 t, /* i : frame counter reset to 0 at each independent frame */ + Word16 *prev_x, /* i : previous vector */ + Word16 *x, /* i : current vector to encode */ + const Word16 length /* i : number of elements to encode */ +) +{ + /* + f + ^ + | d a x + | c b + | e --> t + */ + Word16 f; + Word16 pred; + Word16 ctx; + Word16 ctx_f; + Word16 ctx_t; + + FOR( f = 0; f < length; f++ ) + { + IF( t == 0 ) + { + IF( f == 0 ) + { + /* (t == 0) && (f == 0) */ + /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ + hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + shr( x[f], 2 ), + (const UWord16 *) hPrivateData->cf_se00 ); + arith_encode_bits( hPrivateData, ptr, x[f] & 3, 2 ); /* LSBs as 2 bit raw */ + } + ELSE IF( EQ_16( f, 1 ) ) + { + pred = x[f - 1]; /* pred = b */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); + } + ELSE + { + /* f >= 2 */ + pred = x[f - 1]; /* pred = b */ + ctx = quant_ctx( sub( x[f - 1], x[f - 2] ) ); /* Q(b - e) */ + arith_encode_residual( hPrivateData, ptr, sub( x[f], pred ), &hPrivateData->cf_se02[( IGF_SYMBOLS_IN_TABLE + 1 ) * ( IGF_CTX_OFFSET + ctx )], hPrivateData->cf_off_se02[IGF_CTX_OFFSET + ctx] ); + } + move16(); + } + ELSE + { + /* t == 1 */ + IF( f == 0 ) + { + pred = prev_x[f]; /* pred = a */ + move16(); + arith_encode_residual( hPrivateData, ptr, sub( x[f], pred ), hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); + } + ELSE + { + /* (t == 1) && (f >= 1) */ + pred = add( prev_x[f], sub( x[f - 1], prev_x[f - 1] ) ); /* pred = a + b - c */ + ctx_f = quant_ctx( sub( prev_x[f], prev_x[f - 1] ) ); /* Q(a - c) */ + ctx_t = quant_ctx( sub( x[f - 1], prev_x[f - 1] ) ); /* Q(b - c) */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, &hPrivateData->cf_se11[( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT * ( IGF_CTX_OFFSET + ctx_t ) + ( IGF_SYMBOLS_IN_TABLE + 1 ) * ( IGF_CTX_OFFSET + ctx_f )], hPrivateData->cf_off_se11[IGF_CTX_COUNT * ( IGF_CTX_OFFSET + ctx_t ) + ( IGF_CTX_OFFSET + ctx_f )] ); + } + } + } + return; +} +#else static void encode_sfe_vector( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ int16_t *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ @@ -272,6 +453,7 @@ static void encode_sfe_vector( return; } +#endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -297,6 +479,57 @@ void IGFSCFEncoderReset( * * main IGF encoder function *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +Word16 IGFSCFEncoderEncode( + IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ + Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ +) +{ + Word16 ptr[IGF_BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each short */ + Word16 i; + + /* insert data: */ + hPublicData->ptrBitIndex = 0; + move16(); + hPublicData->bitCount = bitCount; + move16(); + ari_start_encoding_14bits_ivas_fx( &hPublicData->acState ); /* start AC encoding */ + + /* check if coder needs a reset and do it if necessary */ + IF( indepFlag != 0 ) + { + IGFSCFEncoderReset_fx( hPublicData ); + } + + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); + + hPublicData->ptrBitIndex = ari_done_encoding_14bits( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); /* finish AC encoding */ + hPublicData->bitCount = add( hPublicData->bitCount, hPublicData->ptrBitIndex ); + move16(); + move16(); + + /* advancing history: */ + Copy( sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx] ); + hPublicData->t = add( hPublicData->t, 1 ); + move16(); + + /* copy the bits from the temporary bit buffer, if doRealEncoding is enabled */ + IF( hBstr ) + { + FOR( i = 0; i < hPublicData->ptrBitIndex; ++i ) + { + push_next_indice( hBstr, ptr[i], 1 ); + } + } + + /* return next bit offset in the stream */ + return hPublicData->bitCount; +} +#else // IVAS_FLOAT_FIXED int16_t IGFSCFEncoderEncode( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ @@ -342,6 +575,7 @@ int16_t IGFSCFEncoderEncode( /* return next bit offset in the stream */ return hPublicData->bitCount; } +#endif /*---------------------------------------------------------------------* diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index 58b835803..28d228e63 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -98,6 +98,7 @@ static void arith_encode_bits( 32767, /* disable the bit count limitation */ &hPrivateData->acState_fx, bit ); + move16(); } } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 7e51c82bf..ee9635054 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -40,6 +40,7 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #include "prot_fx.h" +#include "prot_fx_enc.h" #endif @@ -48,7 +49,7 @@ * * ISM CoreCoders encoding routine *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_ism_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *data[], /* i : input signal [channels][samples] */ @@ -168,17 +169,11 @@ ivas_error ivas_ism_enc( /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], - &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], - realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], - fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); -#else error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); -#endif + if ( error != IVAS_ERR_OK ) { return error; @@ -201,38 +196,6 @@ ivas_error ivas_ism_enc( if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) { /* compute the dominant sce_id using long term energy */ -#ifdef IVAS_FLOAT_FIXED -#if 1 /************************flt_to_fix****************************/ - for ( int j = 0; j < st_ivas->nchan_transport; j++ ) - { - floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ - } - f2me_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); - for ( int ch = 0; ch < nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->last_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->last_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_elevation, Q22 ); - } - for ( int ch = 0; ch < st_ivas->nchan_transport; ch++ ) - { - st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); /*Q8*/ - } - floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); -#endif /****************************ends here*********************************/ - ivas_ism_get_sce_id_dtx_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); - dtx_flag = ivas_ism_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag ); - IF( sid_flag ) - { - /* estimate coherence between objects */ - ivas_ism_coh_estim_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); - } -#if 1 /************************fix_to_flt****************************/ - me2f_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); - fixedToFloat_arr( st_ivas->hISMDTX->coh_fx, st_ivas->hISMDTX->coh, Q15, st_ivas->nchan_transport ); -#endif /****************************ends here*********************************/ -#else ivas_ism_get_sce_id_dtx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); /* analysis and decision about DTX */ @@ -243,7 +206,6 @@ ivas_error ivas_ism_enc( /* estimate coherence between objects */ ivas_ism_coh_estim_dtx_enc( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); } -#endif // IVAS_FLOAT_FIXED } /*------------------------------------------------------------------* @@ -259,86 +221,15 @@ ivas_error ivas_ism_enc( if ( dtx_flag ) { -#ifdef IVAS_FLOAT_FIXED - /*================flt-to-fix===================================*/ - IF( sid_flag ) - { - IF( GT_16( st_ivas->nchan_transport, 1 ) ) - { - /* write sce id */ - /* quantize and write coherence */ - floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); - } - } - /*================flt-to-fix===================================*/ -#endif ivas_ism_metadata_sid_enc( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata ); } else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { -#ifdef IVAS_FLOAT_FIXED - /*===============================flt-to-fix=============================================*/ - IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ) - { - IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); - } - IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); - st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); - } - } - } - } - } - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); - st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); - st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); - } - } - /*===============================flt-to-fix=============================================*/ - IF( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, L_negate( ONE_IN_Q8 ), 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) - { - return error; - } - - /*===============================flt-2-fix======================================*/ - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); - } - } - /*===============================fix-2-flt======================================*/ -#else if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } -#endif } else /* ISM_MODE_DISC */ { @@ -356,74 +247,12 @@ ivas_error ivas_ism_enc( } ism_total_brate_ref = ism_total_brate; -#ifdef IVAS_FLOAT_FIXED - IF( st_ivas->hMasa != NULL ) - { - st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = floatToFixed( st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, Q8 ); - } - - /*===============================flt-to-fix=============================================*/ - IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ) - { - IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) - { - st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); - } - IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); - st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); - } - } - } - } - } - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); - st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); - st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); - st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); - st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); - } - } - /*===============================flt-to-fix=============================================*/ - IF( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) - { - return error; - } - /*===============================flt-2-fix======================================*/ - IF( st_ivas->hIsmMetaData != NULL ) - { - FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) - { - st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); - st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); - } - } - /*===============================fix-2-flt======================================*/ -#else if ( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } -#endif if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { @@ -547,7 +376,533 @@ ivas_error ivas_ism_enc( return error; } +#else +ivas_error ivas_ism_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + float *data[], /* i : input signal [channels][samples] */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 *nb_bits_metadata, /* i : number of metadata bits */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +) +{ + SCE_ENC_HANDLE hSCE; + Encoder_State *st; + Word16 sce_id; + float old_inp_12k8[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 */ + float old_inp_16k[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 16kHz */ + Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ + float ener[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin */ + float relE[MAX_NUM_OBJECTS][1]; /* frame relative energy */ + Word16 relE_fx[MAX_NUM_OBJECTS][1]; /* frame relative energy, Q8 */ + float A[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* A(z) unquantized for subframes */ + float Aw[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )]; /* weighted A(z) unquantized for subframes */ + float epsP[MAX_NUM_OBJECTS][1][M + 1]; /* LP prediction errors */ + float lsp_new[MAX_NUM_OBJECTS][1][M]; /* LSPs at the end of the frame */ + float lsp_mid[MAX_NUM_OBJECTS][1][M]; /* ISPs in the middle of the frame */ + Word16 vad_hover_flag[MAX_NUM_OBJECTS][1]; /* VAD hangover flag */ + Word16 attack_flag[MAX_NUM_OBJECTS][1]; /* attack flag (GSC or TC) */ + float realBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* real buffer */ + float imagBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* imag buffer */ + float old_wsp[MAX_NUM_OBJECTS][1][L_WSP]; /* old weighted input signal */ + float pitch_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch values */ + float voicing_fr[MAX_NUM_OBJECTS][1][NB_SUBFR]; /* fractional pitch gains */ + Word16 loc_harm[MAX_NUM_OBJECTS][1]; /* harmonicity flag */ + float cor_map_sum[MAX_NUM_OBJECTS][1]; /* speech/music clasif. parameter */ + Word16 vad_flag_dtx[MAX_NUM_OBJECTS][1]; /* HE-SAD flag with additional DTX HO */ + float enerBuffer[MAX_NUM_OBJECTS][1][CLDFB_NO_CHANNELS_MAX]; /* energy buffer */ + float currFlatness[1]; /* flatness parameter */ + float fft_buff[MAX_NUM_OBJECTS][1][2 * L_FFT]; /* FFT buffer */ + float fr_bands[1][2 * NB_BANDS]; /* energy in frequency bands */ + float Etot_LR[1]; /* total energy; correlation shift */ + float lf_E[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ + Word16 localVAD_HE_SAD[1]; /* local HE VAD */ + Word16 nchan_ism, dtx_flag, sid_flag, flag_noisy_speech; + Word16 md_diff_flag[MAX_NUM_OBJECTS]; + Encoder_State *prev_st = NULL; + Word32 ism_total_brate_ref, ism_total_brate; + Word16 i, nchan_transport_ism; + ivas_error error; + + push_wmops( "ivas_ism_enc" ); + + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + error = IVAS_ERR_OK; + move32(); + + dtx_flag = 0; + sid_flag = 0; + flag_noisy_speech = 0; + move16(); + move16(); + move16(); + + nchan_ism = st_ivas->hEncoderConfig->nchan_ism; + move16(); + set16_fx( md_diff_flag, 1, nchan_ism ); + + nchan_transport_ism = st_ivas->nchan_transport; + move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + nchan_transport_ism = 1; + nchan_ism = 1; + move16(); + move16(); + } + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; + move16(); + } + + /*------------------------------------------------------------------* + * Preprocesing + *-----------------------------------------------------------------*/ + + FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) + { + hSCE = st_ivas->hSCE[sce_id]; + st = hSCE->hCoreCoder[0]; + + /*------------------------------------------------------------------* + * Initialization - general + *-----------------------------------------------------------------*/ + + mvr2r( data[sce_id], st->input, input_frame ); + + st->element_mode = IVAS_SCE; + move16(); + + /*------------------------------------------------------------------* + * SCE initialization - core coder + *-----------------------------------------------------------------*/ + + st->idchan = 0; + st->core = -1; + st->core_brate = -1; /* updated in dtx() */ + st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ + st->bwidth = st->last_bwidth; /* updated in BWD */ + st->rate_switching_reset = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + + /*---------------------------------------------------------------* + * Time Domain Transient Detector + *---------------------------------------------------------------*/ + + RunTransientDetection( st->input, input_frame, st->hTranDet ); + currFlatness[0] = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 0 ); + + /*----------------------------------------------------------------* + * Configuration of core encoder + *----------------------------------------------------------------*/ + + /* Force to MODE1 in IVAS */ + st->codec_mode = MODE1; + move16(); + + st->bits_frame_nominal = sub( extract_l( Mpy_32_32( hSCE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), ISM_NB_BITS_METADATA_NOMINAL ); + move16(); + /*----------------------------------------------------------------* + * Front Pre-processing + *----------------------------------------------------------------*/ + error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], + &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], + realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], + fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); + + IF( NE_32( error, IVAS_ERR_OK ) ) + { + return error; + } + + IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + vad_flag[sce_id] = vad_flag_dtx[sce_id][0]; + move16(); + } + ELSE + { + vad_flag[sce_id] = st->vad_flag; + move16(); + } + } + + /*------------------------------------------------------------------* + * DTX analysis + *-----------------------------------------------------------------*/ + + IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + /* compute the dominant sce_id using long term energy */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS /************************flt_to_fix****************************/ + for ( int j = 0; j < st_ivas->nchan_transport; j++ ) + { + floatToFixed_arrL( st_ivas->hSCE[j]->hCoreCoder[0]->input, st_ivas->hSCE[j]->hCoreCoder[0]->input32_fx, Q11, input_frame ); /*Q0*/ + } + f2me_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); + for ( int ch = 0; ch < nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_elevation, Q22 ); + } + for ( int ch = 0; ch < st_ivas->nchan_transport; ch++ ) + { + st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); /*Q8*/ + } + floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); +#endif /****************************ends here*********************************/ + ivas_ism_get_sce_id_dtx_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); + + dtx_flag = ivas_ism_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, vad_flag, st_ivas->hIsmMetaData, md_diff_flag, &sid_flag ); + + IF( sid_flag ) + { + /* estimate coherence between objects */ + ivas_ism_coh_estim_dtx_enc_fx( st_ivas->hISMDTX, st_ivas->hSCE, st_ivas->nchan_transport, input_frame ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS /************************fix_to_flt****************************/ + me2f_buf( &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_fx[0][0], st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc_e, &st_ivas->hISMDTX->long_term_energy_stereo_dmx_enc[0][0], st_ivas->nchan_transport * PARAM_ISM_HYS_BUF_SIZE ); + fixedToFloat_arr( st_ivas->hISMDTX->coh_fx, st_ivas->hISMDTX->coh, Q15, st_ivas->nchan_transport ); +#endif /****************************ends here*********************************/ + } + + /*------------------------------------------------------------------* + * Analysis of objects, configuration and decision about bitrates per channel + * Metadata quantization and encoding + *-----------------------------------------------------------------*/ + + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) ) + { + ivas_param_ism_compute_noisy_speech_flag( st_ivas ); + flag_noisy_speech = st_ivas->hParamIsm->flag_noisy_speech; + move16(); + } + + IF( dtx_flag ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*================flt-to-fix===================================*/ + if ( sid_flag ) + { + if ( GT_16( st_ivas->nchan_transport, 1 ) ) + { + /* write sce id */ + /* quantize and write coherence */ + floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); + } + } + /*================flt-to-fix===================================*/ +#endif + ivas_ism_metadata_sid_enc( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata ); + } + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ){ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ){ + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ){ + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ){ + IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ){ + IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ){ + st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); +} +IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) +{ + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); +} +} +} +} +} +IF( st_ivas->hIsmMetaData != NULL ) +{ + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); + st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + } +} +#endif + +IF( NE_32( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, L_negate( ONE_IN_Q8 ), 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), IVAS_ERR_OK ) ) +{ + return error; +} + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +IF( st_ivas->hIsmMetaData != NULL ) +{ + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); + } +} +#endif +} +ELSE /* ISM_MODE_DISC */ +{ + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + ism_total_brate = 0; + move16(); + FOR( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); + } + } + ELSE + { + ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + } + + ism_total_brate_ref = ism_total_brate; + move32(); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st_ivas->hMasa != NULL ) + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = floatToFixed( st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, Q8 ); + } + + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ) + { + IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); + } + IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); + } + } + } + } + } + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); + st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + } + } +#endif + + IF( NE_32( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ), + IVAS_ERR_OK ) ) + { + return error; + } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); + } + } +#endif + + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + st_ivas->hCPE[0]->brate_surplus = L_sub( ism_total_brate_ref, ism_total_brate ); + move32(); + } +} + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +IF( st_ivas->hIsmMetaData != NULL ) +{ + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + } +} +#endif +update_last_metadata_fx( nchan_ism, st_ivas->hIsmMetaData, md_diff_flag ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +IF( st_ivas->hIsmMetaData != NULL ) +{ + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->last_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_elevation_fx, Q22 ); + } +} +#endif + +/*----------------------------------------------------------------* + * Write IVAS format signaling in SID frames + *----------------------------------------------------------------*/ + +st = st_ivas->hSCE[0]->hCoreCoder[0]; + +IF( sid_flag ) +{ + ivas_write_format_sid( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr ); +} + +/*only metadata encoding is needed for this case*/ +IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) +{ + assert( st_ivas->ism_mode != ISM_MODE_NONE ); + return error; +} + +/*------------------------------------------------------------------* + * CoreCoders encoding + *-----------------------------------------------------------------*/ + +FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) +{ + hSCE = st_ivas->hSCE[sce_id]; + st = hSCE->hCoreCoder[0]; + + /* update pointer to the buffer of indices of the next channel */ + IF( sce_id > 0 ) + { + st->hBstr->ind_list = prev_st->hBstr->ind_list + prev_st->hBstr->nb_ind_tot; + } + + if ( st->low_rate_mode ) + { + st->bwidth = WB; + move16(); + } + + /*----------------------------------------------------------------* + * Core codec configuration + *----------------------------------------------------------------*/ + + /* IGF reconfiguration */ + test(); + IF( NE_32( hSCE->last_element_brate, hSCE->element_brate ) || NE_32( st->last_bwidth, st->bwidth ) ) + { + Word16 igf; + igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->rf_mode ); + IF( NE_32( ( error = IGF_Reconfig( &st->hIGFEnc, igf, 0, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->max_bwidth, st->element_mode, st->rf_mode ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* set ACELP@12k8 / ACELP@16k flag for flexible ACELP core */ + test(); + IF( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) + { + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); + move16(); + } + ELSE IF( st->low_rate_mode ) + { + st->flag_ACELP16k = 0; + move16(); + } + ELSE + { + st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + move16(); + } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + relE_fx[sce_id][0] = float_to_fix16( relE[sce_id][0], Q8 ); +#endif + /* modify the coder_type depending on the total_brate per channel */ + coder_type_modif_ivas_fx( st, relE_fx[sce_id][0] ); + + /*----------------------------------------------------------------* + * Encoder + *----------------------------------------------------------------*/ + test(); + test(); + IF( !dtx_flag || ( dtx_flag && EQ_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) ) + { + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*----------------------------------------------------------------* + * Common updates + *----------------------------------------------------------------*/ + + /* update input samples buffer */ + mvr2r( st->input, st->old_input_signal, input_frame ); + + hSCE->last_element_brate = hSCE->element_brate; + move32(); + + /* Store previous attack detection flag */ + st->hTranDet->transientDetector.prev_bIsAttackPresent = st->hTranDet->transientDetector.bIsAttackPresent; + move16(); + + prev_st = st; +} +IF( dtx_flag ) +{ + FOR( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) + { + IF( NE_16( sce_id, st_ivas->hISMDTX->sce_id_dtx ) ) + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_core; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_core_brate = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->core_brate; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->last_L_frame = st_ivas->hSCE[st_ivas->hISMDTX->sce_id_dtx]->hCoreCoder[0]->last_L_frame; + move16(); + move32(); + move16(); + } + } +} + +pop_wmops(); + +return error; +} +#endif /*------------------------------------------------------------------------- * ivas_ism_enc_config() diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 3bf1bb5c8..5c0165618 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -736,7 +736,7 @@ ivas_error ivas_ism_metadata_enc( hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); } - update_last_metadata( nchan_ism, hIsmMeta, md_diff_flag ); + update_last_metadata_fx( nchan_ism, hIsmMeta, md_diff_flag ); pop_wmops(); return error; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index fec37122b..b1779369e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -922,6 +922,11 @@ void coder_type_modif_fx( const Word16 relE /* i : frame relative E to the long term average */ ); +void coder_type_modif_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 relE /* i : frame relative E to the long term average */ +); + void speech_music_clas_init_fx( SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ); @@ -1273,6 +1278,12 @@ Word16 ari_encode_14bits_ext_fx( Word32 symbol, UWord16 const *cum_freq ); +Word16 ari_put_bit_plus_follow( + Word16 ptr[], /* o: bit-stream */ + Word16 bp, /* i: bit-stream position */ + Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' */ + Word16 bit /* i: bit to send */ +); Word16 ari_done_encoding_14bits_fx( Word16 *ptr, Word16 bp, diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 27f021465..36d1c5052 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -477,3 +477,143 @@ void coder_type_modif_fx( return; } +#ifdef IVAS_FLOAT_FIXED +void coder_type_modif_ivas_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 relE /* i : frame relative E to the long term average */ +) +{ + Word16 unmod_coder_type, vbr_generic_ho; + + SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; + + + IF( st->Opt_SC_VBR ) + { + vbr_generic_ho = hSC_VBR->vbr_generic_ho; + move16(); + } + ELSE + { + vbr_generic_ho = -1; + move16(); + } + + IF( EQ_16( st->codec_mode, MODE1 ) ) + { + /*---------------------------------------------------------------------* + * Coder type modification + * + * Prevent UC coder type in certain conditions + * Prevent VC coder type in certain conditions + * Select TC coder type in appropriate frames + *---------------------------------------------------------------------*/ + + /* At higher rates, use GC coding instead of UC coding to improve quality */ + test(); + test(); + test(); + test(); + test(); + if ( ( EQ_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || + ( GT_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) + { + st->coder_type = GENERIC; + move16(); + } + + /* Prevent UC coding on mixed content at 9.6 kb/s */ + test(); + test(); + if ( GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) && st->audio_frame_cnt != 0 ) + { + st->coder_type = GENERIC; + move16(); + } + + unmod_coder_type = st->coder_type; + move16(); + + /* Enforce GC coder type on inactive signal (this can be later overwritten to INACTIVE) */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( st->localVAD == 0 && ( ( + EQ_16( st->coder_type, UNVOICED ) && ( ( st->Opt_SC_VBR == 0 ) || ( ( EQ_16( st->Opt_SC_VBR, 1 ) ) && vbr_generic_ho == 0 && GT_16( st->last_coder_type, UNVOICED ) ) ) ) || + EQ_16( st->coder_type, TRANSITION ) || EQ_16( st->coder_type, VOICED ) ) + + ) + { + st->coder_type = GENERIC; + move16(); + } + + IF( EQ_16( st->Opt_SC_VBR, 1 ) ) + { + test(); + if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) ) + { + hSC_VBR->vbr_generic_ho = 1; + move16(); + } + + if ( GT_16( st->coder_type, UNVOICED ) ) + { + hSC_VBR->vbr_generic_ho = 0; + move16(); + } + + hSC_VBR->last_7k2_coder_type = st->coder_type; + move16(); + test(); + if ( st->localVAD == 0 && EQ_16( st->coder_type, UNVOICED ) ) + { + hSC_VBR->last_7k2_coder_type = GENERIC; + move16(); + } + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + /* At higher rates and with 16kHz core, allow only GC and TC coder type */ + test(); + test(); + if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) ) + { + /* onset/transition frame is always coded using GC mode */ + st->coder_type = GENERIC; + move16(); + } + } + ELSE /*IVAS*/ + { + /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */ + test(); + test(); + test(); + if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) || + ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) + { + st->coder_type = GENERIC; + move16(); + } + } + + /* Patch for certain low-level signals for which the gain quantizer sometimes goes out of its dynamic range */ + test(); + test(); + test(); + if ( EQ_16( st->coder_type, VOICED ) && EQ_16( st->input_bwidth, NB ) && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) ) + { + st->coder_type = GENERIC; + move16(); + } + } + + return; +} +#endif diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index 2be9596a5..8c21f3f58 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -1730,7 +1730,7 @@ void ProcessStereoIGF_fx( if ( sts[ch]->core == TCX_20_CORE ) { - IGFEncWriteBitstream( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); + IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); } else { @@ -1740,7 +1740,7 @@ void ProcessStereoIGF_fx( { hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; } - IGFEncWriteBitstream( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); + IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); bsBits = hBstr->nb_ind_tot - pBsStart; IGFEncConcatenateBitstream( hIGFEnc[ch], bsBits, hBstr ); -- GitLab From 380c22b30184235743d3bb2a69ca7d85225c53a5 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 5 Sep 2024 22:35:58 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/prot_fx.h | 4 ++-- lib_enc/ari_enc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index f47017b59..faa6760bb 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10247,8 +10247,8 @@ void IGFEncApplyStereo_fx( void IGFSaveSpectrumForITF_ivas_fx( IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ - const Word16 igfGridIdx, /* i : IGF grid index */ - const Word32 *pITFSpectrum /* i : MDCT spectrum */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word32 *pITFSpectrum /* i : MDCT spectrum */ ); Word16 IGFEncWriteBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c index d8ba85f98..8646c79b9 100644 --- a/lib_enc/ari_enc.c +++ b/lib_enc/ari_enc.c @@ -187,7 +187,7 @@ Word16 ari_encode_14bits_ext( L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ ); Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp ); - IF ( symbol != 0 ) /* when symbol is 0, range remains unchanged */ + IF( symbol != 0 ) /* when symbol is 0, range remains unchanged */ { Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp ); } -- GitLab