Loading Workspace_msvc/lib_enc.vcxproj +0 −1 Original line number Diff line number Diff line Loading @@ -242,7 +242,6 @@ <ClCompile Include="..\lib_enc\ivas_stereo_dft_td_itd_fx.c" /> <ClCompile Include="..\lib_enc\ivas_stereo_dmx_evs_fx.c" /> <ClCompile Include="..\lib_enc\cod4t64_fast_fx.c" /> <ClCompile Include="..\lib_enc\igf_scf_enc.c" /> <ClCompile Include="..\lib_enc\ivas_mcmasa_enc_fx.c" /> <ClCompile Include="..\lib_enc\ivas_core_enc_fx.c" /> <ClCompile Include="..\lib_enc\ivas_cpe_enc_fx.c" /> Loading Workspace_msvc/lib_enc.vcxproj.filters +0 −3 Original line number Diff line number Diff line Loading @@ -253,9 +253,6 @@ <ClCompile Include="..\lib_enc\igf_enc_fx.c"> <Filter>encoder_all_c</Filter> </ClCompile> <ClCompile Include="..\lib_enc\igf_scf_enc.c"> <Filter>encoder_all_c</Filter> </ClCompile> <ClCompile Include="..\lib_enc\igf_scf_enc_fx.c"> <Filter>encoder_all_c</Filter> </ClCompile> Loading lib_com/prot_fx.h +2 −1 Original line number Diff line number Diff line Loading @@ -9983,6 +9983,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFSCFEncoderEncode_ivas_fx( 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 */ Loading @@ -9991,7 +9992,7 @@ Word16 IGFSCFEncoderEncode_ivas_fx( 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 */ ); #endif Word16 ari_encode_14bits_ext_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ Loading lib_enc/igf_enc_fx.c +8 −0 Original line number Diff line number Diff line Loading @@ -310,7 +310,11 @@ static void IGF_WriteEnvelope( IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, EVS_MONO, isIndepFlag ); #else *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); #endif move16(); if ( NULL == hBstr ) Loading Loading @@ -3228,7 +3232,11 @@ static Word16 IGF_WriteEnvelope_ivas( IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, IVAS_SCE, isIndepFlag ); #else *pBitOffset = IGFSCFEncoderEncode_ivas_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); #endif move16(); if ( NULL == hBstr ) Loading lib_enc/igf_scf_enc.cdeleted 100644 → 0 +0 −330 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include <stdint.h> #include "options.h" #include "prot_fx.h" #include "stat_enc.h" #include "stat_com.h" #include "cnst.h" #include "wmc_auto.h" #include "prot_fx_enc.h" /*---------------------------------------------------------------------* * quant_ctx() * * *---------------------------------------------------------------------*/ static Word16 quant_ctx( const Word16 ctx ) { /* ctx ... -5 -4 -3 -2 -1 0 1 2 3 4 5 ... Q(ctx)... -3 -3 -3 -2 -1 0 1 2 3 3 3 ... */ IF( LE_16( abs_s( ctx ), 3 ) ) { return ctx; } ELSE IF( GT_16( ctx, 3 ) ) { return 3; } ELSE /* ctx < -3 */ { return -3; } } /*---------------------------------------------------------------------* * arith_encode_bits() * * *---------------------------------------------------------------------*/ 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, 32767, /* disable the bit count limitation */ &hPrivateData->acState, bit ); move16(); } return; } /*---------------------------------------------------------------------* * arith_encode_residual() * * *---------------------------------------------------------------------*/ 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, x, cumulativeFrequencyTable ); move16(); 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, 0, cumulativeFrequencyTable ); move16(); } 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, IGF_SYMBOLS_IN_TABLE - 1, cumulativeFrequencyTable ); move16(); } /* 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 ); } } return; } /*---------------------------------------------------------------------* * encode_sfe_vector() * * *---------------------------------------------------------------------*/ 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, shr( x[f], 2 ), (const UWord16 *) hPrivateData->cf_se00 ); move16(); 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 */ move16(); arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); } ELSE { /* f >= 2 */ pred = x[f - 1]; /* pred = b */ move16(); 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; } /*---------------------------------------------------------------------* * IGFSCFEncoderEncode_ivas_fx() * * main IGF encoder function *---------------------------------------------------------------------*/ Word16 IGFSCFEncoderEncode_ivas_fx( 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_ivas_fx( 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; } Loading
Workspace_msvc/lib_enc.vcxproj +0 −1 Original line number Diff line number Diff line Loading @@ -242,7 +242,6 @@ <ClCompile Include="..\lib_enc\ivas_stereo_dft_td_itd_fx.c" /> <ClCompile Include="..\lib_enc\ivas_stereo_dmx_evs_fx.c" /> <ClCompile Include="..\lib_enc\cod4t64_fast_fx.c" /> <ClCompile Include="..\lib_enc\igf_scf_enc.c" /> <ClCompile Include="..\lib_enc\ivas_mcmasa_enc_fx.c" /> <ClCompile Include="..\lib_enc\ivas_core_enc_fx.c" /> <ClCompile Include="..\lib_enc\ivas_cpe_enc_fx.c" /> Loading
Workspace_msvc/lib_enc.vcxproj.filters +0 −3 Original line number Diff line number Diff line Loading @@ -253,9 +253,6 @@ <ClCompile Include="..\lib_enc\igf_enc_fx.c"> <Filter>encoder_all_c</Filter> </ClCompile> <ClCompile Include="..\lib_enc\igf_scf_enc.c"> <Filter>encoder_all_c</Filter> </ClCompile> <ClCompile Include="..\lib_enc\igf_scf_enc_fx.c"> <Filter>encoder_all_c</Filter> </ClCompile> Loading
lib_com/prot_fx.h +2 −1 Original line number Diff line number Diff line Loading @@ -9983,6 +9983,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFSCFEncoderEncode_ivas_fx( 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 */ Loading @@ -9991,7 +9992,7 @@ Word16 IGFSCFEncoderEncode_ivas_fx( 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 */ ); #endif Word16 ari_encode_14bits_ext_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ Loading
lib_enc/igf_enc_fx.c +8 −0 Original line number Diff line number Diff line Loading @@ -310,7 +310,11 @@ static void IGF_WriteEnvelope( IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, EVS_MONO, isIndepFlag ); #else *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); #endif move16(); if ( NULL == hBstr ) Loading Loading @@ -3228,7 +3232,11 @@ static Word16 IGF_WriteEnvelope_ivas( IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, IVAS_SCE, isIndepFlag ); #else *pBitOffset = IGFSCFEncoderEncode_ivas_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); #endif move16(); if ( NULL == hBstr ) Loading
lib_enc/igf_scf_enc.cdeleted 100644 → 0 +0 −330 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #include <stdint.h> #include "options.h" #include "prot_fx.h" #include "stat_enc.h" #include "stat_com.h" #include "cnst.h" #include "wmc_auto.h" #include "prot_fx_enc.h" /*---------------------------------------------------------------------* * quant_ctx() * * *---------------------------------------------------------------------*/ static Word16 quant_ctx( const Word16 ctx ) { /* ctx ... -5 -4 -3 -2 -1 0 1 2 3 4 5 ... Q(ctx)... -3 -3 -3 -2 -1 0 1 2 3 3 3 ... */ IF( LE_16( abs_s( ctx ), 3 ) ) { return ctx; } ELSE IF( GT_16( ctx, 3 ) ) { return 3; } ELSE /* ctx < -3 */ { return -3; } } /*---------------------------------------------------------------------* * arith_encode_bits() * * *---------------------------------------------------------------------*/ 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, 32767, /* disable the bit count limitation */ &hPrivateData->acState, bit ); move16(); } return; } /*---------------------------------------------------------------------* * arith_encode_residual() * * *---------------------------------------------------------------------*/ 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, x, cumulativeFrequencyTable ); move16(); 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, 0, cumulativeFrequencyTable ); move16(); } 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, IGF_SYMBOLS_IN_TABLE - 1, cumulativeFrequencyTable ); move16(); } /* 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 ); } } return; } /*---------------------------------------------------------------------* * encode_sfe_vector() * * *---------------------------------------------------------------------*/ 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_ivas_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState, shr( x[f], 2 ), (const UWord16 *) hPrivateData->cf_se00 ); move16(); 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 */ move16(); arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); } ELSE { /* f >= 2 */ pred = x[f - 1]; /* pred = b */ move16(); 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; } /*---------------------------------------------------------------------* * IGFSCFEncoderEncode_ivas_fx() * * main IGF encoder function *---------------------------------------------------------------------*/ Word16 IGFSCFEncoderEncode_ivas_fx( 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_ivas_fx( 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; }