diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index e9b3c7b18a21520460255507464831eabab944e1..9829e097b5239427b3a700afd142848d410b92b6 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -228,6 +228,7 @@ + diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index 7729568e598800a33acd9375bb24dad79cbf1140..7a4bb01d8671db1a180f7e38641c03525e0b8369 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -626,6 +626,48 @@ + + common_evs_c + + + common_evs_c + + + common_evs_c + + + common_evs_c + + + common_evs_c + + + common_evs_c + + + common_evs_c + + + common_all_c + + + common_all_c + + + common_all_c + + + common_all_c + + + common_all_c + + + common_all_c + + + common_ivas_c + diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 3e8bb5e72d3a8c88756d6e11432f66b2446dad0b..850e9c07039c635f335be8059df66edb26fa72f1 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -274,6 +274,7 @@ + diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index d3b4cb43127d339bc16fd8ea23aac7acc2917f54..47995bb10b1f762212a0de19de97c94e0538bc3d 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -526,6 +526,9 @@ decoder_all_c + + decoder_ivas_c + decoder_all_c diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 06ec09ee509837b42e896da27deb5ff4d924ed7b..ccd8ceda3bee78480e007d9621cca95f411fad25 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -525,7 +525,7 @@ enum *----------------------------------------------------------------------------------*/ #define FRAMES_PER_SEC 50 - +#define INV_FRAME_PER_SEC_Q15 656 #define FRAME_SIZE_NS 20000000L #define ACELP_LOOK_NS 8750000L diff --git a/lib_com/ivas_agc_com_fx.c b/lib_com/ivas_agc_com_fx.c new file mode 100644 index 0000000000000000000000000000000000000000..79e689ae90ac92293d98269b0338b261fd80b459 --- /dev/null +++ b/lib_com/ivas_agc_com_fx.c @@ -0,0 +1,135 @@ +/****************************************************************************************************** + + (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "options.h" +#include "cnst.h" +#include "ivas_cnst.h" +#include "ivas_prot.h" +#include "ivas_prot_fx.h" +#include +#include "wmc_auto.h" +#include "prot.h" +#include "rom_com.h" + +/*------------------------------------------------------------------------------------------* + * Local constants + *------------------------------------------------------------------------------------------*/ + +#define SQRKMAX ( 1.5f ) +#define NBITS_DIFFG ( 2 ) +#define DBSTEP ( -6.f ) /* desired dB step value in dB*/ +#define ABS_EMIN_MAX ( 3 ) +#define MAXATTEXP ( 1 ) /* the desired maximum attenuation exponent range per frame*/ + +#define LOG2_NUMCOEFF_SQRKMAX ( 3 ) /* ceilf(logf(ceilf(SQRKMAX * numCoeffs)) * INV_LOG_2) in Q0 */ +#define LOG2_4 ( 2 ) /* ceilf(logf(totExp) * INV_LOG_2)in Q0 */ +#define A_FX ( 8172 ) /* 0.5f * ( 1.f - powf( 10.f, DBSTEP / 20.f ) ) in Q15 */ + +/*-----------------------------------------------------------------------------------------* + * Function ivas_agc_initWindowFunc() + * + * Get a window function + *-----------------------------------------------------------------------------------------*/ + +void ivas_agc_initWindowFunc_fx( + Word16 *pWinFunc, + const Word16 length ) +{ + Word16 i; + Word16 a; + const Word16 *cos_val; + + a = A_FX; /* for DBSTEP -6.f */ + + SWITCH( length ) + { + case 128: + cos_val = cos_pi_by_127; + BREAK; + case 256: + cos_val = cos_pi_by_255; + BREAK; + case 384: + cos_val = cos_pi_by_383; + BREAK; + default: + cos_val = cos_pi_by_383; + BREAK; + } + + for ( i = 0; i < length; i++ ) + { + pWinFunc[i] = add( MAX_16, (Word16) Mpy_32_16_1( L_sub( (Word32) cos_val[i], (Word32) MAX_16 ), a ) ); + } + + return; +} + +/*-----------------------------------------------------------------------------------------* + * Function ivas_agc_calcGainParams_fx() + * + * Calculate gain parameters + *-----------------------------------------------------------------------------------------*/ + +void ivas_agc_calcGainParams_fx( + UWord16 *absEmin, + UWord16 *betaE, + UWord16 *maxAttExp, + const Word16 numCoeffs ) +{ + Word16 totExp; + Word16 Bm; + Word16 nbits; + + nbits = NBITS_DIFFG; + assert( EQ_16( numCoeffs, IVAS_SPAR_MAX_DMX_CHS ) ); + *absEmin = s_max( ABS_EMIN_MAX, LOG2_NUMCOEFF_SQRKMAX ); + + totExp = add( add( *absEmin, AGC_EMAX ), 1 ); + /**betaE = (UWord16)ceilf(logf(totExp) * INV_LOG_2);*/ + *betaE = (UWord16) LOG2_4; + + /*Bm = (UWord16)ceilf(logf((AGC_EMAX + 1 + 1)) * INV_LOG_2);*/ + Bm = 1; + + IF( GT_16( nbits, 0 ) ) + { + Bm = s_min( AGC_BITS_PER_CH - 1, NBITS_DIFFG ); + } + + /**maxAttExp = ((UWord16) powf( 2, Bm ) ) - 2;*/ + *maxAttExp = sub( shl( 2, 1 ), 2 ); + *maxAttExp = s_min( MAXATTEXP, *maxAttExp ); + + return; +} diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 2c1098a16aeb80eb268692b031682814f6597985..737bb947043e39795b79097935567d0a72e7a1ee 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -92,6 +92,42 @@ void ivas_tda_fx( const Word16 length /* i : length of time alised signal buffer */ ); +// ivas_agc_dec_fx.c +ivas_error ivas_spar_agc_dec_open_fx( + ivas_agc_dec_state_t **hAgcDec, /* i/o: SPAR AGC decoder handle */ + const Word32 output_Fs /* i : output sampling rate */ +); + +void ivas_spar_agc_dec_close_fx( + ivas_agc_dec_state_t **hAgcDec /* i/o: SPAR AGC decoder handle */ +); + +void ivas_agc_dec_process_fx( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + Word32 *pcm_in[], /* i : input audio channels */ + Word32 *pcm_out[], /* o : output audio channels */ + const Word16 n_channels, /* i : number of channels */ + const Word16 output_frame /* i : output frame length */ +); + +void ivas_agc_read_bits_fx( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + const Word16 n_channels, /* i : number of channels */ + const Word16 AGC_flag /* i : AGC on/off flag */ +); + +// ivas_agc_com_fx.c +void ivas_agc_initWindowFunc_fx( + Word16 *pWinFunc, + const Word16 length ); + +void ivas_agc_calcGainParams_fx( + UWord16 *absEmin, + UWord16 *betaE, + UWord16 *maxAttExp, + const Word16 numCoeffs ); + #ifdef IVAS_FLOAT_FIXED void ivas_transient_det_process_fx( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 9f06f25f090b466de7b4940db173d478e26ecaea..60c309854f9c2fc091a8c2e153f52ec0d0be18cf 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -328,6 +328,9 @@ typedef struct ivas_agc_chan_data_t typedef struct ivas_agc_com_state_t { float *winFunc; +#ifdef IVAS_FLOAT_FIXED + Word16 *winFunc_fx; +#endif // IVAS_FLOAT_FIXED int16_t in_delay; /* TODO: JBM check if this needs to be adjusted in the dec */ uint16_t absEmin; uint16_t betaE; diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 343cf3cd4362ab7ad3aba6ce84844db7a9e62809..7bce292b25001529ec993595c33416ef0f6a647a 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -5564,12 +5564,15 @@ void TonalMDCTConceal_Apply( ); //avq_dec_fx.c + void AVQ_demuxdec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq_out[] /* i/o: AVQ nq index */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i : number of subvectors */ + Word16 nq[], /* i/o: AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ ); void AVQ_dec_lpc( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a532b1c1d837bea2126eeb0ccf808b13f8166c58..9e867840b78c35957c09323b98a91206bead9bf2 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -37888,6 +37888,172 @@ const Word16 fftSineTab640_fx[ 321 ] = { const Word32 bwMode2fs[4] = { 8000, 16000, 32000, 48000 }; +const Word16 cos_pi_by_127[128] = /* Q15 */ +{ + 32767 ,32756 ,32726 ,32676 ,32606 ,32516 , + 32406 ,32276 ,32127 ,31958 ,31769 , + 31561 ,31333 ,31087 ,30821 ,30537 , + 30233 ,29912 ,29572 ,29213 ,28837 , + 28444 ,28033 ,27605 ,27160 ,26698 , + 26220 ,25726 ,25216 ,24691 ,24150 , + 23595 ,23026 ,22442 ,21844 ,21234 , + 20610 ,19974 ,19325 ,18665 ,17993 , + 17310 ,16616 ,15913 ,15199 ,14477 , + 13745 ,13005 ,12258 ,11502 ,10740 , + 9971 ,9196 ,8415 ,7629 ,6839 , + 6044 ,5245 ,4444 ,3639 ,2833 , + 2025 ,1215 ,405 ,-405 ,-1215 , + -2025 ,-2833 ,-3639 ,-4444 ,-5245 , + -6044 ,-6839 ,-7629 ,-8415 ,-9196 , + -9971 ,-10740 ,-11502 ,-12258 ,-13005 , + -13745 ,-14477 ,-15199 ,-15913 ,-16616 , + -17310 ,-17993 ,-18665 ,-19325 ,-19974 , + -20610 ,-21234 ,-21844 ,-22442 ,-23026 , + -23595 ,-24150 ,-24691 ,-25216 ,-25726 , + -26220 ,-26698 ,-27160 ,-27605 ,-28033 , + -28444 ,-28837 ,-29213 ,-29572 ,-29912 , + -30233 ,-30537 ,-30821 ,-31087 ,-31333 , + -31561 ,-31769 ,-31958 ,-32127 ,-32276 , + -32406 ,-32516 ,-32606 ,-32676 ,-32726 , + -32756 ,-32767 +}; + +const Word16 cos_pi_by_255[256] = /* Q15 */ +{ + 32767 ,32764 ,32757 ,32744 ,32727 ,32704 , + 32677 ,32645 ,32607 ,32565 ,32518 , + 32466 ,32409 ,32347 ,32280 ,32209 , + 32132 ,32050 ,31964 ,31873 ,31777 , + 31676 ,31570 ,31460 ,31345 ,31225 , + 31100 ,30970 ,30836 ,30697 ,30554 , + 30406 ,30253 ,30096 ,29934 ,29767 , + 29596 ,29421 ,29241 ,29056 ,28868 , + 28674 ,28477 ,28275 ,28069 ,27859 , + 27644 ,27425 ,27202 ,26975 ,26744 , + 26509 ,26269 ,26026 ,25779 ,25528 , + 25273 ,25014 ,24751 ,24485 ,24215 , + 23941 ,23663 ,23382 ,23098 ,22810 , + 22518 ,22223 ,21925 ,21623 ,21318 , + 21010 ,20699 ,20384 ,20067 ,19746 , + 19422 ,19096 ,18766 ,18434 ,18099 , + 17761 ,17420 ,17077 ,16731 ,16383 , + 16032 ,15679 ,15323 ,14965 ,14605 , + 14243 ,13878 ,13511 ,13142 ,12772 , + 12399 ,12024 ,11648 ,11270 ,10890 , + 10508 ,10125 ,9740 ,9354 ,8967 , + 8578 ,8187 ,7796 ,7403 ,7009 , + 6615 ,6219 ,5822 ,5424 ,5026 , + 4626 ,4226 ,3826 ,3425 ,3023 , + 2621 ,2218 ,1815 ,1412 ,1009 , + 605 ,201 ,-201 ,-605 ,-1009 , + -1412 ,-1815 ,-2218 ,-2621 ,-3023 , + -3425 ,-3826 ,-4226 ,-4626 ,-5026 , + -5424 ,-5822 ,-6219 ,-6615 ,-7009 , + -7403 ,-7796 ,-8187 ,-8578 ,-8967 , + -9354 ,-9740 ,-10125 ,-10508 ,-10890 , + -11270 ,-11648 ,-12024 ,-12399 ,-12772 , + -13142 ,-13511 ,-13878 ,-14243 ,-14605 , + -14965 ,-15323 ,-15679 ,-16032 ,-16383 , + -16731 ,-17077 ,-17420 ,-17761 ,-18099 , + -18434 ,-18766 ,-19096 ,-19422 ,-19746 , + -20067 ,-20384 ,-20699 ,-21010 ,-21318 , + -21623 ,-21925 ,-22223 ,-22518 ,-22810 , + -23098 ,-23382 ,-23663 ,-23941 ,-24215 , + -24485 ,-24751 ,-25014 ,-25273 ,-25528 , + -25779 ,-26026 ,-26269 ,-26509 ,-26744 , + -26975 ,-27202 ,-27425 ,-27644 ,-27859 , + -28069 ,-28275 ,-28477 ,-28674 ,-28868 , + -29056 ,-29241 ,-29421 ,-29596 ,-29767 , + -29934 ,-30096 ,-30253 ,-30406 ,-30554 , + -30697 ,-30836 ,-30970 ,-31100 ,-31225 , + -31345 ,-31460 ,-31570 ,-31676 ,-31777 , + -31873 ,-31964 ,-32050 ,-32132 ,-32209 , + -32280 ,-32347 ,-32409 ,-32466 ,-32518 , + -32565 ,-32607 ,-32645 ,-32677 ,-32704 , + -32727 ,-32744 ,-32757 ,-32764 ,-32767 +}; + +const Word16 cos_pi_by_383[384] = /* Q15 */ +{ + 32767 ,32765 ,32762 ,32757 ,32749 ,32739 , + 32727 ,32713 ,32696 ,32677 ,32656 , + 32633 ,32608 ,32580 ,32551 ,32519 , + 32485 ,32448 ,32410 ,32369 ,32327 , + 32282 ,32234 ,32185 ,32134 ,32080 , + 32024 ,31966 ,31906 ,31844 ,31779 , + 31713 ,31644 ,31573 ,31500 ,31425 , + 31348 ,31269 ,31188 ,31104 ,31019 , + 30931 ,30841 ,30749 ,30655 ,30560 , + 30462 ,30361 ,30259 ,30155 ,30049 , + 29941 ,29831 ,29719 ,29604 ,29488 , + 29370 ,29250 ,29128 ,29004 ,28878 , + 28750 ,28620 ,28488 ,28354 ,28218 , + 28081 ,27941 ,27800 ,27657 ,27512 , + 27365 ,27216 ,27066 ,26913 ,26759 , + 26603 ,26445 ,26286 ,26124 ,25961 , + 25796 ,25630 ,25461 ,25291 ,25120 , + 24946 ,24771 ,24594 ,24416 ,24236 , + 24054 ,23871 ,23686 ,23499 ,23311 , + 23122 ,22930 ,22738 ,22543 ,22348 , + 22150 ,21952 ,21751 ,21550 ,21346 , + 21142 ,20936 ,20728 ,20519 ,20309 , + 20097 ,19885 ,19670 ,19455 ,19238 , + 19019 ,18800 ,18579 ,18357 ,18134 , + 17910 ,17684 ,17457 ,17229 ,17000 , + 16769 ,16538 ,16305 ,16072 ,15837 , + 15601 ,15364 ,15126 ,14887 ,14647 , + 14407 ,14165 ,13922 ,13678 ,13433 , + 13188 ,12941 ,12694 ,12446 ,12197 , + 11947 ,11696 ,11445 ,11192 ,10939 , + 10686 ,10431 ,10176 ,9920 ,9664 , + 9407 ,9149 ,8891 ,8632 ,8372 , + 8112 ,7851 ,7590 ,7328 ,7066 , + 6803 ,6540 ,6277 ,6013 ,5748 , + 5483 ,5218 ,4953 ,4687 ,4421 , + 4154 ,3888 ,3621 ,3353 ,3086 , + 2818 ,2550 ,2282 ,2014 ,1746 , + 1477 ,1209 ,940 ,671 ,403 , + 134 ,-134 ,-403 ,-671 ,-940 , + -1209 ,-1477 ,-1746 ,-2014 ,-2282 , + -2550 ,-2818 ,-3086 ,-3353 ,-3621 , + -3888 ,-4154 ,-4421 ,-4687 ,-4953 , + -5218 ,-5483 ,-5748 ,-6013 ,-6277 , + -6540 ,-6803 ,-7066 ,-7328 ,-7590 , + -7851 ,-8112 ,-8372 ,-8632 ,-8891 , + -9149 ,-9407 ,-9664 ,-9920 ,-10176 , + -10431 ,-10686 ,-10939 ,-11192 ,-11445 , + -11696 ,-11947 ,-12197 ,-12446 ,-12694 , + -12941 ,-13188 ,-13433 ,-13678 ,-13922 , + -14165 ,-14407 ,-14647 ,-14887 ,-15126 , + -15364 ,-15601 ,-15837 ,-16072 ,-16305 , + -16538 ,-16769 ,-17000 ,-17229 ,-17457 , + -17684 ,-17910 ,-18134 ,-18357 ,-18579 , + -18800 ,-19019 ,-19238 ,-19455 ,-19670 , + -19885 ,-20097 ,-20309 ,-20519 ,-20728 , + -20936 ,-21142 ,-21346 ,-21550 ,-21751 , + -21952 ,-22150 ,-22348 ,-22543 ,-22738 , + -22930 ,-23122 ,-23311 ,-23499 ,-23686 , + -23871 ,-24054 ,-24236 ,-24416 ,-24594 , + -24771 ,-24946 ,-25120 ,-25291 ,-25461 , + -25630 ,-25796 ,-25961 ,-26124 ,-26286 , + -26445 ,-26603 ,-26759 ,-26913 ,-27066 , + -27216 ,-27365 ,-27512 ,-27657 ,-27800 , + -27941 ,-28081 ,-28218 ,-28354 ,-28488 , + -28620 ,-28750 ,-28878 ,-29004 ,-29128 , + -29250 ,-29370 ,-29488 ,-29604 ,-29719 , + -29831 ,-29941 ,-30049 ,-30155 ,-30259 , + -30361 ,-30462 ,-30560 ,-30655 ,-30749 , + -30841 ,-30931 ,-31019 ,-31104 ,-31188 , + -31269 ,-31348 ,-31425 ,-31500 ,-31573 , + -31644 ,-31713 ,-31779 ,-31844 ,-31906 , + -31966 ,-32024 ,-32080 ,-32134 ,-32185 , + -32234 ,-32282 ,-32327 ,-32369 ,-32410 , + -32448 ,-32485 ,-32519 ,-32551 ,-32580 , + -32608 ,-32633 ,-32656 ,-32677 ,-32696 , + -32713 ,-32727 ,-32739 ,-32749 ,-32757 , + -32762 ,-32765 ,-32767 +}; + const Word16 swb_lsp_prev_interp_init[10] = { 32767, 31164, 26510, 19261, 10126, 0, -10126, -19261, -26510, -31164 }; /* st->swb_lsp_prev_interp[i] = (float)cos( (float)i * PI / (float)10.0f )*/ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index a2c36637056f855619c5bd6908c5d78368385cf5..b38fa2fe34315b981312e094b712b061b9c1b5c8 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1973,6 +1973,11 @@ extern const Word16 pwf_fx[17]; extern const Word32 inverse_table[]; extern const Word16 cos_diff_table[512]; extern const Word32 bwMode2fs[4]; + +extern const Word16 cos_pi_by_127[128]; +extern const Word16 cos_pi_by_255[256]; +extern const Word16 cos_pi_by_383[384]; + extern const Word16 swb_lsp_prev_interp_init[]; extern const Word16 L_frame_inv[8]; extern const Word16 InvIntTable[65]; diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index 7ab3e51c83395c546f1e061f95a9cd4fe83ae72c..ab73ea4b037bcc63c765ab149dc690d50c620c82 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -7,46 +7,46 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Static table prototypes */ +#include "prot.h" /* Function prototypes */ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ +/*-------------------------------------------------------------------* + * Local prototypes + *-------------------------------------------------------------------*/ + +static void read_cv_fx( Decoder_State *st, UWord16 *I, Word16 *kv, Word16 nq, Word16 *nbits ); + /*-----------------------------------------------------------------* - * Function AVQ_Demuxdec_Bstr * - * ~~~~~~~~~~~~~~~~~~ * - * Read indexes from one bitstream and decode subvectors. * + * AVQ_demuxdec() + * + * Demultiplex and decode subvectors using + * split algebraic vector dequantizer based on RE8 latice. *-----------------------------------------------------------------*/ void AVQ_demuxdec_fx( - Decoder_State *st_fx,/* i/o: decoder state structure */ - Word16 xriq[], /* o: decoded subvectors [0..8*Nsv-1] */ - Word16 *nb_bits, /* i/o: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors */ - Word16 nq[] /* i/o: AVQ nq index */ -#ifdef IVAS_CODE_AVQ - ,Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ - Word16 trgtSvPos /* i : target SV for AVQ bit savings */ -#endif + Decoder_State *st, /* i/o: decoder state structure */ + Word16 xriq[], /* o : decoded subvectors [0..8*Nsv-1]*/ + Word16 *nb_bits, /* i/o: number of allocated bits */ + const Word16 Nsv, /* i : number of subvectors */ + Word16 nq[], /* i/o: AVQ nq index */ + Word16 avq_bit_sFlag, /* i : flag for AVQ bit saving solution */ + Word16 trgtSvPos /* i : target SV for AVQ bit savings */ ) { - Word16 i,j, bits, order_v; + Word16 i, j, bits, tmp; UWord16 I[NSV_MAX]; - Word16 *kv, code[8]; - Word16 tmp16; -#ifdef IVAS_CODE_AVQ + Word16 code[8]; + Word16 *kv; Word16 nq_est, unused_bits_idx; Word16 bitsMod; Word16 underflow; Word16 unusedbitsFlag; Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits; -#endif - set16_fx( (Word16*)I, 0, NSV_MAX ); - set16_fx( code, 0, 8 ); - - kv = xriq; /* reuse vector to save memory */ + kv = xriq; /* reuse vector to save memory */ bits = *nb_bits; move16(); -#ifdef IVAS_CODE_AVQ bitsMod = 0; move16(); underflow = 0; @@ -67,59 +67,75 @@ void AVQ_demuxdec_fx( move16(); j = i; move16(); - if (EQ_16(avq_bit_sFlag, 2)) + IF( EQ_16( avq_bit_sFlag, 2 ) ) { - j = add(i, 1); + j = add( i, 1 ); } - WHILE (LT_16(i, sub(Nsv, 1))) + WHILE( LT_16( i, sub( Nsv, 1 ) ) ) { move16(); svOrder[i] = j; i++; j++; } -#endif - FOR( i=0; iBER_detect = 1; + st->BER_detect = 1; move16(); - set16_fx( xriq, 0, shl(Nsv,3) ); + set16_fx( xriq, 0, shl( Nsv, 3 ) ); set16_fx( nq, 0, Nsv ); *nb_bits = 0; move16(); @@ -127,74 +143,133 @@ PMT("AVQ bit saving code needs to be written ") return; } - bits = sub(bits,nq[i]); - bits = sub(bits,1); /* count the stop bit */ + bits = sub( bits, nq[k] ); + bits = sub( bits, 1 ); /* count the stop bit */ - if( nq[i] > 0 ) + IF( GT_16( nq[k], 0 ) ) { - nq[i] = add(nq[i],1); - move16(); + nq[k] = add( nq[k], 1 ); } /* read codebook indices (rank I and event. Voronoi index kv) */ - IF( nq[i] != 0 ) /* for Q0 nothing to read */ + read_cv_fx( st, &I[k], &kv[k * 8], nq[k], &bits ); + } + } /* for */ + + /* Bit Saving Solution */ + IF( GT_16( avq_bit_sFlag, 0 ) && GT_16( bits, 8 ) ) + { + i = svOrder[Nsv - 1]; + nq[i] = 0; + bitsMod = bits % 5; + IF( NE_16( i, sub( Nsv, 1 ) ) ) + { + nullVec = 0; + FOR( j = i; j < Nsv - 1; j++ ) { - IF( LT_16(nq[i], 5)) /* Q2, Q3, Q4 */ + IF( EQ_16( nq[svOrder[j]], 0 ) ) { - tmp16 = shl(nq[i], 2); - order_v = 0; - move16(); + nullVec = add( nullVec, 1 ); } - ELSE /* for Q3/Q4 + Voronoi extensions r=1,2 */ + } + nq_est = bits / 5; + IF( ( GT_16( bitsMod, 0 ) || ( EQ_16( nullVec, 4 ) && EQ_16( nq_est, 5 ) ) ) && NE_16( bitsMod, 4 ) && GE_16( add( bits, nullVec ), ( add( add( shl( nq_est, 2 ), nq_est ), 4 ) ) ) && EQ_16( nq[svOrder[Nsv - 2]], 0 ) ) /* dummy bits */ + { + dummy_bits = sub( 5, bitsMod ); + bits = add( bits, dummy_bits ); /* add dummy bits */ + bitsMod = 0; + } + ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[Nsv - 2]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ + { + underflow = 0; + IF( NE_16( ( add( bitsMod, nullVec ) % 5 ), 0 ) ) { - j = 1; - move16(); - if( s_and(nq[i], 1) == 0 ) - { - j = add(j,1); - } - order_v = sub(shr(nq[i], 1), j); /* Voronoi order determination */ - tmp16 = shl(add(j, 2), 2); + underflow = 1; } + dummy_bits = add( nullVec, underflow ); + bits = add( bits, dummy_bits ); /* add dummy bits */ + bitsMod = 0; + } + } + underflow = 1; + IF( NE_16( bitsMod, 4 ) ) + { + underflow = 0; + bits = sub( bits, bitsMod ); + } + bits = add( bits, underflow ); - I[i] = get_next_indice(st_fx, tmp16 ); - move16(); - bits = sub(bits, tmp16); + /* read the unary code for unused bit*/ + unused_bits_idx = -1; + DO + { + ( unused_bits_idx )++; + IF( EQ_16( add( add( shl( unused_bits_idx, 2 ), unused_bits_idx ), 4 ), sub( bits, 1 ) ) ) + { + BREAK; + } + } + WHILE( get_next_indice_1( st ) ); - IF( order_v > 0 ) - { - tmp16 = shl(i, 3); - FOR( j=0; j<8; j++ ) - { - kv[tmp16+j] = (Word16)get_next_indice(st_fx, order_v ); - move16(); - } - bits = sub(bits, shl(order_v, 3)); - } + unusedbitsFlag = 0; + + IF( EQ_16( dummy_bits, 0 ) ) + { + IF( EQ_16( unused_bits_idx, 0 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) + { + unusedbitsFlag = 1; + } + ELSE IF( EQ_16( unused_bits_idx, 1 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) + { + unusedbitsFlag = -1; } } + + /*Compute AVQ code book number from unused Bits */ + tmp = (Word16) ( sub( bits, add( add( shl( add( unusedbitsFlag, unused_bits_idx ), 2 ), unusedbitsFlag ), unused_bits_idx ) ) ); + nq_est = tmp / 5; + nq_est = EQ_16( ( tmp % 5 ), 0 ) ? nq_est : add( nq_est, 1 ); + + IF( EQ_16( nq_est, 1 ) ) + { + nq_est = 0; + } + bits = sub( bits, underflow ); + + bits = sub( bits, unused_bits_idx ); + + IF( NE_16( nq_est, 0 ) ) + { + bits = sub( bits, 1 ); + } + + nq[i] = nq_est; + /* read codebook indices (rank I and event. Voronoi index kv) */ + read_cv_fx( st, &I[i], &kv[i * 8], nq[i], &bits ); + + bits = sub( bits, dummy_bits ); + + IF( NE_16( bitsMod, 4 ) ) + { + bits = add( bits, bitsMod ); + } } /* decode all subvectors */ - FOR( i=0; i #include "options.h" /* Compilation switches */ +#include #include "cnst.h" /* Common constants */ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ +#define IVAS_CODE +#define IVAS_CODE_AVQ /*-----------------------------------------------------------------* * transf_cdbk_dec() * Transform domain contribution decoding @@ -36,6 +39,7 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE Word16 avq_bit_sFlag; Word16 trgtSvPos; + Word16 Nsv = 8; avq_bit_sFlag = 0; move16(); @@ -156,18 +160,18 @@ void transf_cdbk_dec_fx( /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ IF (GT_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->coder_type_fx, INACTIVE) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && !harm_flag_acelp && code_preQ[0] != 0) { - PMT("Fixed point taking accound of the scaling needs to be done here ") - IF (fabs((float)(st->last_code_preq)) > 16.0f * (float)fabs(code_preQ[0])) + //PMT("Fixed point taking accound of the scaling needs to be done here ") + IF (GT_16(abs_s(st_fx->last_code_preq), shl(abs_s(code_preQ[0]),4))) { - st->mem_preemp_preQ /= 16; + st_fx->mem_preemp_preQ /= 16; } - ELSE IF (fabs((float)(st->last_code_preq)) > 8.0f * (float)fabs(code_preQ[0])) + ELSE IF (GT_16(abs_s((st_fx->last_code_preq)), shl(abs_s(code_preQ[0]),3))) { - st->mem_preemp_preQ /= 8; + st_fx->mem_preemp_preQ /= 8; } } - st->last_code_preq = (int16_t)code_preQ[L_SUBFR - 1]; + st_fx->last_code_preq = (Word16)code_preQ[L_SUBFR - 1]; #endif /*--------------------------------------------------------------* * Preemphasise diff --git a/lib_dec/ivas_agc_dec_fx.c b/lib_dec/ivas_agc_dec_fx.c new file mode 100644 index 0000000000000000000000000000000000000000..10dbe15891a988701dd157d48f747ca1761eb92e --- /dev/null +++ b/lib_dec/ivas_agc_dec_fx.c @@ -0,0 +1,348 @@ +/****************************************************************************************************** + + (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "options.h" +#include "prot.h" +#include "prot_fx2.h" +#include "ivas_prot.h" +#include "ivas_prot_fx.h" +#include +#include +#include "wmc_auto.h" + + +/*-----------------------------------------------------------------------------------------* + * Function ivas_agc_dec_init_fx() + * + * AGC decoder initialization call + * + *-----------------------------------------------------------------------------------------*/ + +static void ivas_agc_dec_init_fx( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + const Word16 output_frame, + const Word16 delay ) +{ + Word16 i; + ivas_agc_dec_chan_state_t *ptrG = hAgcDec->gain_state; + ivas_agc_chan_data_t *ptr = hAgcDec->gain_data; + + hAgcDec->agc_com.in_delay = delay; + hAgcDec->agc_com.num_coeff = IVAS_SPAR_MAX_DMX_CHS; + ivas_agc_calcGainParams_fx( &hAgcDec->agc_com.absEmin, &hAgcDec->agc_com.betaE, &hAgcDec->agc_com.maxAttExp, hAgcDec->agc_com.num_coeff ); + + ivas_agc_initWindowFunc_fx( hAgcDec->agc_com.winFunc_fx, output_frame - hAgcDec->agc_com.in_delay ); + + FOR( i = 0; i < IVAS_SPAR_MAX_DMX_CHS; i++ ) + { + /* gain_state */ + ptrG->lastGain_fx = MAX_16; + ptrG->gainExpVal = 0; + ptrG++; + + /* gain_data */ + ptr->absGainExp = hAgcDec->agc_com.absEmin; + ptr->absGainExpCurr = hAgcDec->agc_com.absEmin; + ptr++; + } + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_spar_agc_dec_open_fx() + * + * Allocate and initialize SPAR AGC decoder handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_spar_agc_dec_open_fx( + ivas_agc_dec_state_t **hAgcDec, /* i/o: SPAR AGC decoder handle */ + const Word32 output_Fs /* i : output sampling rate */ +) +{ + ivas_agc_dec_state_t *hAgc; + Word16 output_frame, delay; + + IF( ( hAgc = (ivas_agc_dec_state_t *) malloc( sizeof( ivas_agc_dec_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" ); + } + + output_frame = (Word16) Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ); + delay = NS2SA_fx2( output_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); + + IF( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( output_frame - delay ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" ); + } + + IF( ( hAgc->gain_state = (ivas_agc_dec_chan_state_t *) malloc( sizeof( ivas_agc_dec_chan_state_t ) * FOA_CHANNELS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" ); + } + + IF( ( hAgc->gain_data = (ivas_agc_chan_data_t *) malloc( sizeof( ivas_agc_chan_data_t ) * FOA_CHANNELS ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AGC decoder" ); + } + + ivas_agc_dec_init_fx( hAgc, output_frame, delay ); + + *hAgcDec = hAgc; + + return IVAS_ERR_OK; +} + + +/*------------------------------------------------------------------------- + * ivas_spar_agc_dec_close_fx() + * + * Deallocate SPAR AGC decoder handle + *------------------------------------------------------------------------*/ + +void ivas_spar_agc_dec_close_fx( + ivas_agc_dec_state_t **hAgcDec /* i/o: SPAR AGC decoder handle */ +) +{ + ivas_agc_dec_state_t *hAgc; + + IF( hAgcDec == NULL || *hAgcDec == NULL ) + { + return; + } + + hAgc = *hAgcDec; + + free( hAgc->agc_com.winFunc_fx ); + hAgc->agc_com.winFunc = NULL; + + free( hAgc->gain_state ); + hAgc->gain_state = NULL; + + free( hAgc->gain_data ); + hAgc->gain_data = NULL; + + free( *hAgcDec ); + *hAgcDec = NULL; + + return; +} + + +/*-----------------------------------------------------------------------------------------* + * Function ivas_agc_dec_process_fx() + * + * AGC decoder + *-----------------------------------------------------------------------------------------*/ + +void ivas_agc_dec_process_fx( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + Word32 *pcm_in[], /* i : input audio channels */ + Word32 *pcm_out[], /* o : output audio channels */ + const Word16 n_channels, /* i : number of channels */ + const Word16 output_frame /* i : output frame length */ +) +{ + Word16 i, j, idx; + Word16 tmp, tmp_2; + UWord16 offset; + Word16 gainLast, gain; + ivas_agc_dec_state_t *pState = hAgcDec; + + offset = output_frame - pState->agc_com.in_delay; + + FOR( i = 0; i < n_channels; i++ ) + { + pState->gain_state[i].gainExpVal = sub( pState->gain_data[i].absGainExp, pState->gain_data[i].absGainExpCurr ); + + IF( GT_16( pState->gain_state[i].gainExpVal, ( pState->agc_com.maxAttExp + 1 ) ) || LT_16( pState->gain_state[i].gainExpVal, -1 ) ) + { + /* Such conditions indicate packet loss, better reset and do nothing*/ + pState->gain_data[i].absGainExp = pState->agc_com.absEmin; + pState->gain_state[i].gainExpVal = 0; + } + + // pState->gain_state[i].lastGain = powf( pState->agc_com.winFunc[offset - 1], ( -1.f * (float) ( pState->gain_data[i].absGainExp - pState->agc_com.absEmin ) ) ); + // gainLast = 1.f / pState->gain_state[i].lastGain; + + tmp = negate( sub( pState->gain_data[i].absGainExp, pState->agc_com.absEmin ) ); + IF( LT_16( tmp, 0 ) ) + { + tmp_2 = MAX_16; + FOR( idx = 0; idx < negate( tmp ); idx++ ) + { + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + } + tmp_2 = div_l( ONE_IN_Q30, tmp_2 ); + } + ELSE + { + tmp_2 = MAX_16; + FOR( idx = 0; idx < ( tmp ); idx++ ) + { + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + } + } + pState->gain_state[i].lastGain_fx = tmp_2; + gainLast = div_l( ONE_IN_Q30, pState->gain_state[i].lastGain_fx ); // Q14 + + IF( NE_16( pState->gain_state[i].gainExpVal, 0 ) ) + { + FOR( idx = 0; idx < output_frame; idx++ ) + { + IF( GE_16( idx, pState->agc_com.in_delay ) ) + { + // gain = powf( pState->agc_com.winFunc[idx - pState->agc_com.in_delay], (float) ( -1 * pState->gain_state[i].gainExpVal ) ) * gainLast; + + tmp = negate( pState->gain_state[i].gainExpVal ); + IF( LT_16( tmp, 0 ) ) + { + tmp_2 = MAX_16; + FOR( j = 0; j < negate( tmp ); j++ ) + { + tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); + } + if ( LT_16( tmp_2, 0 ) ) + { + tmp_2 = div_l( ONE_IN_Q30, negate( tmp_2 ) ); // Q14 + tmp_2 = negate( tmp_2 ); + } + else + { + tmp_2 = div_l( ONE_IN_Q30, tmp_2 ); // Q14 + } + } + ELSE + { + tmp_2 = MAX_16; + FOR( j = 0; j < ( tmp ); j++ ) + { + tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); + } + tmp_2 = shr( tmp_2, 1 ); // Q14 + } + gain = mult( tmp_2, gainLast ); + } + ELSE + { + gain = shr( gainLast, 1 ); // Q13 + } + + pcm_out[i][idx] = Mpy_32_16_1( pcm_in[i][idx], gain ); + } + + // pState->gain_state[i].lastGain *= powf( pState->agc_com.winFunc[offset - 1], (float) pState->gain_state[i].gainExpVal ); + tmp = pState->gain_state[i].gainExpVal; + IF( LT_16( tmp, 0 ) ) + { + tmp_2 = MAX_16; + FOR( idx = 0; idx < negate( tmp ); idx++ ) + { + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + } + tmp_2 = div_l( ONE_IN_Q30, tmp_2 ); + } + ELSE + { + tmp_2 = MAX_16; + FOR( idx = 0; idx < ( tmp ); idx++ ) + { + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + } + tmp_2 = shr( tmp_2, 1 ); // Q14 + } + pState->gain_state[i].lastGain_fx = mult( pState->gain_state[i].lastGain_fx, tmp_2 ); + } + ELSE + { + gain = shr( gainLast, 1 ); // Q13 + FOR( idx = 0; idx < output_frame; idx++ ) + { + pcm_out[i][idx] = Mpy_32_16_1( pcm_in[i][idx], gain ); + } + } + pState->gain_data[i].absGainExp = pState->gain_data[i].absGainExpCurr; + } + + return; +} + + +/*-----------------------------------------------------------------------------------------* + * ivas_agc_read_bits_fx() + * + * decode AGC parameters + *-----------------------------------------------------------------------------------------*/ + +void ivas_agc_read_bits_fx( + ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + const Word16 n_channels, /* i : number of channels */ + const Word16 AGC_flag /* i : AGC on/off flag */ +) +{ + Word16 i; + Word16 per_ch_bit[FOA_CHANNELS]; + ivas_agc_dec_state_t *pState = hAgcDec; + + set16_fx( per_ch_bit, 0, FOA_CHANNELS ); + + /* read AGC parameters */ + IF( EQ_16( AGC_flag, 1 ) ) + { + per_ch_bit[0] = 1; + + assert( EQ_16( AGC_BITS_PER_CH, ( pState->agc_com.betaE + 1 ) ) ); + FOR( i = 0; i < n_channels; i++ ) + { + IF( EQ_16( per_ch_bit[i], 1 ) ) + { /* TODO: to replace get_next_indice with get_next_indice_fx when fixed point Decoder state struct used for fixed point implementation */ + pState->gain_data[i].absGainExpCurr = get_next_indice( st0, (Word16) pState->agc_com.betaE ); + } + ELSE + { + pState->gain_data[i].absGainExpCurr = (Word32) pState->agc_com.absEmin; + } + } + } + ELSE + { + FOR( i = 0; i < n_channels; i++ ) + { + pState->gain_data[i].absGainExpCurr = (Word32) pState->agc_com.absEmin; + } + } + + return; +} diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index e7d3709463dfc2236a5fcc43312ee1745c538933..9f9ae61fc480d5b6ec719683974b657930bd6d5e 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -41,6 +41,12 @@ #include "ivas_rom_com.h" #include #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED +#ifdef DUMPS_ENABLED +#include "debug.h" +#endif // DUMPS_ENABLED /*-----------------------------------------------------------------------* @@ -260,7 +266,41 @@ ivas_error ivas_jbm_dec_tc( if ( st_ivas->ivas_format == SBA_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, p_output, p_output, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); +#ifdef DUMPS_ENABLED + dbgwrite_txt( &p_output[0][0], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED +#else + Word32 *output_fx[12]; + FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + output_fx[i] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); + FOR( Word16 j = 0; j < output_frame; j++ ) + { + output_fx[i][j] = (Word32) ( p_output[i][j] * ONE_IN_Q14 ); + } + } + + ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( output_fx ), ( output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); + + FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + FOR( Word16 j = 0; j < output_frame; j++ ) + { + p_output[i][j] = (float) output_fx[i][j] / ONE_IN_Q12; + } + } + +#ifdef DUMPS_ENABLED + dbgwrite_txt( &p_output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED + + FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + free( output_fx[i] ); + } +#endif // !IVAS_FLOAT_FIXED if ( st_ivas->hSpar->hPCA != NULL ) { @@ -445,7 +485,41 @@ ivas_error ivas_jbm_dec_tc( if ( st_ivas->sba_dirac_stereo_flag ) { +#ifndef IVAS_FLOAT_FIXED ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, &p_output[sba_ch_idx], &p_output[sba_ch_idx], st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); +#ifdef DUMPS_ENABLED + dbgwrite_txt( &p_output[sba_ch_idx], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED +#else + Word32 *output_fx[20]; + FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + output_fx[i] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); + FOR( Word16 j = 0; j < output_frame; j++ ) + { + output_fx[i][j] = (Word32) ( p_output[i + sba_ch_idx][j] * ONE_IN_Q14 ); + } + } + + ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( output_fx ), ( output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); + + FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + FOR( Word16 j = 0; j < output_frame; j++ ) + { + p_output[i + sba_ch_idx][j] = (float) output_fx[i][j] / ONE_IN_Q12; + } + } + +#ifdef DUMPS_ENABLED + dbgwrite_txt( &p_output[sba_ch_idx][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED + + FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + { + free( output_fx[i] ); + } +#endif // !IVAS_FLOAT_FIXED if ( st_ivas->hSpar->hPCA != NULL ) { diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 692e1a4cf7bd7cb132d3b603bb3a31d1cb4e897c..1b6747d04a0d3c4901c0c116a998c029fb3ddcf1 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -39,7 +39,12 @@ #include "ivas_cnst.h" #include #include "wmc_auto.h" - +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED +#ifdef DUMPS_ENABLED +#include "debug.h" +#endif // DUMPS_ENABLED @@ -489,7 +494,41 @@ void ivas_sba_mix_matrix_determiner( /* AGC */ nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; nchan_out = nchan_transport; +#ifndef IVAS_FLOAT_FIXED ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); +#ifdef DUMPS_ENABLED + dbgwrite_txt( &output[0][0], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED +#else + Word32 *output_fx[20]; + FOR( Word16 c = 0; c < nchan_transport; c++ ) + { + output_fx[c] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); + FOR( Word16 j = 0; j < output_frame; j++ ) + { + output_fx[c][j] = (Word32) ( output[c][j] * ONE_IN_Q14 ); + } + } + + ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); + + FOR( Word16 c = 0; c < nchan_transport; c++ ) + { + FOR( Word16 j = 0; j < output_frame; j++ ) + { + output[c][j] = (float) output_fx[c][j] / ONE_IN_Q12; + } + } + +#ifdef DUMPS_ENABLED + dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED + + FOR( Word16 c = 0; c < nchan_transport; c++ ) + { + free( output_fx[c] ); + } +#endif // !IVAS_FLOAT_FIXED /* Convert numeric range back */ for ( ch = 0; ch < nchan_out; ch++ ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index cd79d2ca02387599e8bdf4a1157f727c2947dde4..03f5e905e7ab914d53c1b84a31cbb04b75d09465 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -43,7 +43,12 @@ #include #include #include "wmc_auto.h" - +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED +#ifdef DUMPS_ENABLED +#include "debug.h" +#endif // DUMPS_ENABLED /*-------------------------------------------------------------------* * Local function prototypes @@ -142,7 +147,11 @@ ivas_error ivas_spar_dec_open( } /* AGC handle */ +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_spar_agc_dec_open_fx( &hSpar->hAgcDec, output_Fs ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_agc_dec_open( &hSpar->hAgcDec, output_Fs ) ) != IVAS_ERR_OK ) +#endif // IVAS_FLOAT_FIXED { return error; } @@ -295,7 +304,11 @@ void ivas_spar_dec_close( ivas_FB_mixer_close( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); /* AGC */ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_agc_dec_close_fx( &( *hSpar )->hAgcDec ); +#else ivas_spar_agc_dec_close( &( *hSpar )->hAgcDec ); +#endif // IVAS_FLOAT_FIXED /* PCA */ if ( ( *hSpar )->hPCA != NULL ) @@ -831,7 +844,12 @@ static ivas_error ivas_spar_dec_MD( hSpar->AGC_flag = get_next_indice( st0, 1 ); } +#ifndef IVAS_FLOAT_FIXED ivas_agc_read_bits( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag ); +#else + ivas_agc_read_bits_fx( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag ); +#endif // IVAS_FLOAT_FIXED + } /*---------------------------------------------------------------------* @@ -1190,7 +1208,42 @@ void ivas_spar_dec_agc_pca( * AGC *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); +#ifdef DUMPS_ENABLED + dbgwrite_txt( &output[0][0], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED +#else + Word32 *output_fx[20]; + FOR( Word16 i = 0; i < nchan_transport; i++ ) + { + output_fx[i] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); + FOR( Word16 j = 0; j < output_frame; j++ ) + { + output_fx[i][j] = (Word32) ( output[i][j] * ONE_IN_Q14 ); + } + } + + ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); + + FOR( Word16 i = 0; i < nchan_transport; i++ ) + { + FOR( Word16 j = 0; j < output_frame; j++ ) + { + output[i][j] = (float) output_fx[i][j] / ONE_IN_Q12; + } + } + +#ifdef DUMPS_ENABLED + dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); +#endif // DUMPS_ENABLED + + FOR( Word16 i = 0; i < nchan_transport; i++ ) + { + free( output_fx[i] ); + } + +#endif // !IVAS_FLOAT_FIXED if ( hSpar->hPCA != NULL ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index aede64b6d072fc4f748873471ecc449255abb622..e2c395eab0b8c5c11cc7e42f4ec4a859745089b0 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -618,6 +618,9 @@ typedef struct ivas_spar_md_dec_state_t typedef struct ivas_agc_dec_chan_state_t { float lastGain; +#ifdef IVAS_FLOAT_FIXED + Word16 lastGain_fx; +#endif // IVAS_FLOAT_FIXED int16_t gainExpVal; } ivas_agc_dec_chan_state_t; diff --git a/lib_dec/swb_bwe_dec_hr.c b/lib_dec/swb_bwe_dec_hr.c index 74f62c6c442c6f70c1a86c62252a10e7368b6690..95c87d3ad3d1d06a485a54b53814b182aa51dd96 100644 --- a/lib_dec/swb_bwe_dec_hr.c +++ b/lib_dec/swb_bwe_dec_hr.c @@ -40,6 +40,9 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * swb_bwe_dec_hr() @@ -270,7 +273,11 @@ void swb_bwe_dec_hr( *---------------------------------------------------------------------*/ Nsv = ( NUM_TRANS_END_FREQ_COEF - NUM_TRANS_START_FREQ_COEF ) / WIDTH_BAND; +#ifdef IVAS_FLOAT_FIXED + AVQ_demuxdec_fx( st, x_norm, &nBits, Nsv, nq, 0, Nsv - 1 ); +#else AVQ_demuxdec( st, x_norm, &nBits, Nsv, nq, 0, Nsv - 1 ); +#endif // IVAS_FLOAT_FIXED for ( i = 0; i < Nsv * WIDTH_BAND; i++ ) { t_audio[k * output_frame / NUM_TIME_SWITCHING_BLOCKS + NUM_TRANS_START_FREQ_COEF + i] = (float) ( x_norm[i] ); @@ -441,7 +448,11 @@ void swb_bwe_dec_hr( *---------------------------------------------------------------------*/ Nsv = i / WIDTH_BAND; +#ifdef IVAS_FLOAT_FIXED + AVQ_demuxdec_fx( st, x_norm, &nBits, Nsv, nq, 0, Nsv - 1 ); +#else AVQ_demuxdec( st, x_norm, &nBits, Nsv, nq, 0, Nsv - 1 ); +#endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * second stage decoding *---------------------------------------------------------------------*/ @@ -463,7 +474,11 @@ void swb_bwe_dec_hr( } nBits -= NBITS_GLOB_GAIN_BWE_HR; +#ifdef IVAS_FLOAT_FIXED + AVQ_demuxdec_fx( st, x_norm1, &nBits, Nsv2, nq2, 0, Nsv2 - 1 ); +#else AVQ_demuxdec( st, x_norm1, &nBits, Nsv2, nq2, 0, Nsv2 - 1 ); +#endif // IVAS_FLOAT_FIXED } /*---------------------------------------------------------------------* diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 666a1aef75f9c46a168f2d8168d14adf2adbfd4c..eeb3c833be61ac39d2eef616b30f47b4a999b7f6 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -12,7 +12,7 @@ #define Q_GUARD 1 #define Q_32_BITS 14 /* scaling of 't_audio32' */ #define MAKE_PSEUDO_FLT(v,e) ((((Word32)(v))<<16) + (e)) - +#define AVQ_DEMUX /*-----------------------------------------------------------* * Gain_Dequant_HR() *